mirror of
https://github.com/oxan/esphome-stream-server.git
synced 2026-02-14 18:29:54 +00:00
Add ESPHome Python integration for usage as external component
This commit is contained in:
31
components/stream_server/__init__.py
Normal file
31
components/stream_server/__init__.py
Normal file
@@ -0,0 +1,31 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import uart
|
||||
from esphome.const import CONF_ID, CONF_PORT
|
||||
|
||||
# ESPHome doesn't know the Stream abstraction yet, so hardcode to use a UART for now.
|
||||
|
||||
DEPENDENCIES = ["uart"]
|
||||
|
||||
MULTI_CONF = True
|
||||
|
||||
StreamServerComponent = cg.global_ns.class_("StreamServerComponent", cg.Component)
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(StreamServerComponent),
|
||||
cv.Optional(CONF_PORT): cv.port,
|
||||
}
|
||||
)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
.extend(uart.UART_DEVICE_SCHEMA)
|
||||
)
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
if CONF_PORT in config:
|
||||
cg.add(var.set_port(config[CONF_PORT]))
|
||||
|
||||
yield cg.register_component(var, config)
|
||||
yield uart.register_uart_device(var, config)
|
||||
@@ -17,6 +17,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/uart/uart.h"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
@@ -31,7 +32,9 @@
|
||||
|
||||
class StreamServerComponent : public esphome::Component {
|
||||
public:
|
||||
StreamServerComponent() = default;
|
||||
explicit StreamServerComponent(Stream *stream) : stream_{stream} {}
|
||||
void set_uart_parent(esphome::uart::UARTComponent *parent) { this->stream_ = parent; }
|
||||
|
||||
void setup() override;
|
||||
void loop() override;
|
||||
Reference in New Issue
Block a user