diff --git a/custom_components/README.md b/custom_components/README.md deleted file mode 100644 index a320e42..0000000 --- a/custom_components/README.md +++ /dev/null @@ -1,4 +0,0 @@ -```yaml -# example configuration: - -``` \ No newline at end of file diff --git a/custom_components/empty_sensor_hub/README.md b/custom_components/empty_sensor_hub/README.md new file mode 100644 index 0000000..e4f8ca0 --- /dev/null +++ b/custom_components/empty_sensor_hub/README.md @@ -0,0 +1,33 @@ +```yaml +# example configuration: + +empty_sensor_hub: + id: empty_sensor_hub_1 + +sensor: + - platform: empty_sensor_hub + name: Sensor for empty sensor hub 1 + empty_sensor_hub_id: empty_sensor_hub_1 + + - platform: empty_sensor_hub + name: Sensor for empty sensor hub 2 + empty_sensor_hub_id: empty_sensor_hub_1 + +text_sensor: + - platform: empty_sensor_hub + name: Text sensor for empty sensor hub 1 + empty_sensor_hub_id: empty_sensor_hub_1 + + - platform: empty_sensor_hub + name: Text sensor for empty sensor hub 2 + empty_sensor_hub_id: empty_sensor_hub_1 + +binary_sensor: + - platform: empty_sensor_hub + name: Binary sensor for empty sensor hub 1 + empty_sensor_hub_id: empty_sensor_hub_1 + + - platform: empty_sensor_hub + name: Binary sensor for empty sensor hub 2 + empty_sensor_hub_id: empty_sensor_hub_1 +``` \ No newline at end of file diff --git a/custom_components/empty_sensor_hub/__init__.py b/custom_components/empty_sensor_hub/__init__.py new file mode 100644 index 0000000..aa6b9a6 --- /dev/null +++ b/custom_components/empty_sensor_hub/__init__.py @@ -0,0 +1,20 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.const import CONF_ID + +AUTO_LOAD = ['sensor','text_sensor', 'binary_sensor'] +MULTI_CONF = True + +CONF_HUB_ID = 'empty_sensor_hub_id' + +empty_sensor_hub_ns = cg.esphome_ns.namespace('empty_sensor_hub') + +EmptySensorHub = empty_sensor_hub_ns.class_('EmptySensorHub', cg.Component) + +CONFIG_SCHEMA = cv.Schema({ + cv.GenerateID(): cv.declare_id(EmptySensorHub), +}).extend(cv.COMPONENT_SCHEMA) + +def to_code(config): + var = cg.new_Pvariable(config[CONF_ID]) + yield cg.register_component(var, config) \ No newline at end of file diff --git a/custom_components/empty_sensor_hub/binary_sensor.py b/custom_components/empty_sensor_hub/binary_sensor.py new file mode 100644 index 0000000..76cea6e --- /dev/null +++ b/custom_components/empty_sensor_hub/binary_sensor.py @@ -0,0 +1,23 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import binary_sensor +from esphome.const import CONF_ID +from . import EmptySensorHub, CONF_HUB_ID + +DEPENDENCIES = ['empty_sensor_hub'] + +binary_sensor_ns = cg.esphome_ns.namespace('binary_sensor') +BinarySensor = binary_sensor_ns.class_('BinarySensor', binary_sensor.BinarySensor, cg.Nameable) + +CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend({ + cv.GenerateID(): cv.declare_id(BinarySensor), + cv.GenerateID(CONF_HUB_ID): cv.use_id(EmptySensorHub) +}).extend(cv.COMPONENT_SCHEMA) + +def to_code(config): + paren = yield cg.get_variable(config[CONF_HUB_ID]) + var = cg.new_Pvariable(config[CONF_ID]) + + yield binary_sensor.register_binary_sensor(var, config) + + cg.add(paren.register_binary_sensor(var)) \ No newline at end of file diff --git a/custom_components/empty_sensor_hub/empty_sensor_hub.cpp b/custom_components/empty_sensor_hub/empty_sensor_hub.cpp new file mode 100644 index 0000000..be02f01 --- /dev/null +++ b/custom_components/empty_sensor_hub/empty_sensor_hub.cpp @@ -0,0 +1,24 @@ +#include "empty_sensor_hub.h" +#include "esphome/core/log.h" + +namespace esphome { +namespace empty_sensor_hub { + +static const char *TAG = "empty_sensor_hub.component"; + +void EmptySensorHub::setup(){ + +} + +void EmptySensorHub::dump_config(){ + for (auto *sensor : this->sensors_) { + LOG_SENSOR(" ", "Sensor", sensor); + } + + for(auto *text_sensor : this->text_sensors_){ + LOG_TEXT_SENSOR(" ", "Text sensor", text_sensor); + } +} + +} //namespace empty_sensor_hub +} //namespace esphome \ No newline at end of file diff --git a/custom_components/empty_sensor_hub/empty_sensor_hub.h b/custom_components/empty_sensor_hub/empty_sensor_hub.h new file mode 100644 index 0000000..35395e9 --- /dev/null +++ b/custom_components/empty_sensor_hub/empty_sensor_hub.h @@ -0,0 +1,26 @@ +#pragma once + +#include "esphome/core/component.h" +#include "esphome/components/sensor/sensor.h" +#include "esphome/components/binary_sensor/binary_sensor.h" +#include "esphome/components/text_sensor/text_sensor.h" + +namespace esphome { +namespace empty_sensor_hub { + +class EmptySensorHub : public Component { + public: + void register_sensor(sensor::Sensor *obj) { this->sensors_.push_back(obj); } + void register_text_sensor(text_sensor::TextSensor *obj) { this->text_sensors_.push_back(obj); } + void register_binary_sensor(binary_sensor::BinarySensor *obj) { this->binary_sensors_.push_back(obj); } + void setup() override; + void dump_config() override; + + protected: + std::vector sensors_; + std::vector text_sensors_; + std::vector binary_sensors_; +}; + +} //namespace empty_sensor_hub +} //namespace esphome \ No newline at end of file diff --git a/custom_components/empty_sensor_hub/sensor.py b/custom_components/empty_sensor_hub/sensor.py new file mode 100644 index 0000000..b8d6ed5 --- /dev/null +++ b/custom_components/empty_sensor_hub/sensor.py @@ -0,0 +1,23 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import sensor +from esphome.const import CONF_ID, UNIT_EMPTY, ICON_EMPTY +from . import EmptySensorHub, CONF_HUB_ID + +DEPENDENCIES = ['empty_sensor_hub'] + +sensor_ns = cg.esphome_ns.namespace('sensor') +Sensor = sensor_ns.class_('Sensor', sensor.Sensor, cg.Nameable) + +CONFIG_SCHEMA = sensor.sensor_schema(UNIT_EMPTY, ICON_EMPTY, 1).extend({ + cv.GenerateID(): cv.declare_id(Sensor), + cv.GenerateID(CONF_HUB_ID): cv.use_id(EmptySensorHub) +}).extend(cv.COMPONENT_SCHEMA) + +def to_code(config): + paren = yield cg.get_variable(config[CONF_HUB_ID]) + var = cg.new_Pvariable(config[CONF_ID]) + + yield sensor.register_sensor(var, config) + + cg.add(paren.register_sensor(var)) \ No newline at end of file diff --git a/custom_components/empty_sensor_hub/text_sensor.py b/custom_components/empty_sensor_hub/text_sensor.py new file mode 100644 index 0000000..18a7c89 --- /dev/null +++ b/custom_components/empty_sensor_hub/text_sensor.py @@ -0,0 +1,23 @@ +import esphome.codegen as cg +import esphome.config_validation as cv +from esphome.components import text_sensor +from esphome.const import CONF_ID +from . import EmptySensorHub, CONF_HUB_ID + +DEPENDENCIES = ['empty_sensor_hub'] + +text_sensor_ns = cg.esphome_ns.namespace('text_sensor') +TextSensor = text_sensor_ns.class_('TextSensor', text_sensor.TextSensor, cg.Nameable) + +CONFIG_SCHEMA = text_sensor.TEXT_SENSOR_SCHEMA.extend({ + cv.GenerateID(): cv.declare_id(TextSensor), + cv.GenerateID(CONF_HUB_ID): cv.use_id(EmptySensorHub) +}).extend(cv.COMPONENT_SCHEMA) + +def to_code(config): + paren = yield cg.get_variable(config[CONF_HUB_ID]) + var = cg.new_Pvariable(config[CONF_ID]) + + yield text_sensor.register_text_sensor(var, config) + + cg.add(paren.register_text_sensor(var)) \ No newline at end of file diff --git a/test_empty_components.yaml b/test_empty_components.yaml index 79f9182..0c2c31d 100644 --- a/test_empty_components.yaml +++ b/test_empty_components.yaml @@ -26,10 +26,18 @@ sensor: sensor3: name: Sensor 3 + - platform: empty_sensor_hub + name: Sensor for empty sensor hub + empty_sensor_hub_id: empty_sensor_hub_1 + binary_sensor: - platform: empty_binary_sensor name: Empty binary sensor + - platform: empty_sensor_hub + name: Binary sensor for empty sensor hub + empty_sensor_hub_id: empty_sensor_hub_1 + output: - platform: empty_binary_output id: empty_binary_output_1 @@ -54,7 +62,11 @@ fan: text_sensor: - platform: empty_text_sensor name: Empty text sensor - + + - platform: empty_sensor_hub + name: Text sensor for empty sensor hub + empty_sensor_hub_id: empty_sensor_hub_1 + cover: platform: empty_cover name: Empty cover @@ -84,4 +96,8 @@ spi: empty_spi_component: id: empty_spi_component_1 - cs_pin: D8 \ No newline at end of file + cs_pin: D8 + +empty_sensor_hub: + id: empty_sensor_hub_1 +