parent
b3f368ad3a
commit
8a9291c8ac
@ -1,4 +0,0 @@
|
|||||||
```yaml
|
|
||||||
# example configuration:
|
|
||||||
|
|
||||||
```
|
|
||||||
@ -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
|
||||||
|
```
|
||||||
@ -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)
|
||||||
@ -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))
|
||||||
@ -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
|
||||||
@ -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<sensor::Sensor *> sensors_;
|
||||||
|
std::vector<text_sensor::TextSensor *> text_sensors_;
|
||||||
|
std::vector<binary_sensor::BinarySensor *> binary_sensors_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} //namespace empty_sensor_hub
|
||||||
|
} //namespace esphome
|
||||||
@ -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))
|
||||||
@ -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))
|
||||||
Loading…
Reference in new issue