Compare commits
72
Commits
09a49f75d9
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d02d1dbee | ||
|
|
759b4eb255 | ||
|
|
ad4b2f2a5b | ||
|
|
0bd1f33fb9 | ||
|
|
09c6898a2a | ||
|
|
1d826ac4af | ||
|
|
e19ac64db1 | ||
|
|
a13f98ec7e | ||
|
|
5d15a6f1dc | ||
|
|
48f0cb517e | ||
|
|
9738f1bd71 | ||
|
|
72908bdf26 | ||
|
|
36ae7a47bd | ||
|
|
cd19a7d7a0 | ||
|
|
cb358e0e27 | ||
|
|
46bd170839 | ||
|
|
d296b1e61d | ||
|
|
d076942363 | ||
|
|
6c57d06d86 | ||
|
|
00903ca832 | ||
|
|
4df82f668f | ||
|
|
43f27bbbd9 | ||
|
|
51db90093e | ||
|
|
108f5a6433 | ||
|
|
e72cb91530 | ||
|
|
5fcb15f3a0 | ||
|
|
53b23340dc | ||
|
|
ac3080f1bb | ||
|
|
1728c1aae8 | ||
|
|
fc5a9d85d3 | ||
|
|
08a99e9ee5 | ||
|
|
cb427b17dc | ||
|
|
18cab91774 | ||
|
|
7a45e2b8cf | ||
|
|
5effe60dd7 | ||
|
|
a35709a233 | ||
|
|
999db6bca9 | ||
|
|
ec18740dae | ||
|
|
fba4c0d51f | ||
|
|
d94dca1832 | ||
|
|
62fa86abf8 | ||
|
|
6a7bc20ad0 | ||
|
|
f90c2ec7c3 | ||
|
|
1f733d2887 | ||
|
|
6191889745 | ||
|
|
524927671e | ||
|
|
f61a94e32b | ||
|
|
39d5a466eb | ||
|
|
099510e340 | ||
|
|
ef51d5b253 | ||
|
|
3a7276ce1c | ||
|
|
98d3dda32e | ||
|
|
8357412036 | ||
|
|
277ed4fd01 | ||
|
|
182ea3e204 | ||
|
|
8486714605 | ||
|
|
bd3f376e52 | ||
|
|
048892359e | ||
|
|
f150e66357 | ||
|
|
0d099f7449 | ||
|
|
da631bb6a0 | ||
|
|
90b58c7e4d | ||
|
|
9ee2ee5864 | ||
|
|
31c3e4aba9 | ||
|
|
8a9291c8ac | ||
|
|
b3f368ad3a | ||
|
|
a37a62e31d | ||
|
|
b567cbd7a5 | ||
|
|
11791476b0 | ||
|
|
ae336d2b80 | ||
|
|
c5a762956f | ||
|
|
a9eab678d0 |
@@ -0,0 +1,35 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import light, output, i2c
|
||||
from esphome.const import CONF_OUTPUT_ID, CONF_OUTPUT
|
||||
|
||||
CONF_I2C_ADDR = 0x09
|
||||
|
||||
UPPER_OUTPUT = "upper"
|
||||
LOWER_OUTPUT = "lower"
|
||||
|
||||
c_monochromatic_ns = cg.esphome_ns.namespace("c_monochromatic")
|
||||
MonochromaticLightOutput = c_monochromatic_ns.class_(
|
||||
"MonochromaticLightOutput", light.LightOutput, cg.Component
|
||||
)
|
||||
|
||||
CONFIG_SCHEMA = light.BRIGHTNESS_ONLY_LIGHT_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(MonochromaticLightOutput),
|
||||
cv.Required(UPPER_OUTPUT): cv.use_id(output.FloatOutput),
|
||||
cv.Required(LOWER_OUTPUT): cv.use_id(output.FloatOutput),
|
||||
|
||||
}
|
||||
).extend(i2c.i2c_device_schema(CONF_I2C_ADDR)).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
|
||||
await light.register_light(var, config)
|
||||
|
||||
upper = await cg.get_variable(config[UPPER_OUTPUT])
|
||||
lower = await cg.get_variable(config[LOWER_OUTPUT])
|
||||
cg.add(var.set_output(upper, lower))
|
||||
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
@@ -0,0 +1,97 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
#include "esphome/components/light/light_output.h"
|
||||
#include "esphome/components/output/float_output.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace c_monochromatic {
|
||||
|
||||
enum State { Off, Auto, On };
|
||||
|
||||
class MonochromaticLightOutput : public light::LightOutput,
|
||||
public i2c::I2CDevice,
|
||||
public Component {
|
||||
public:
|
||||
void set_output(output::FloatOutput *upper, output::FloatOutput *lower) {
|
||||
upper_ = upper;
|
||||
lower_ = lower;
|
||||
state_ = Off;
|
||||
bright_ = 0.0;
|
||||
}
|
||||
light::LightTraits get_traits() override {
|
||||
auto traits = light::LightTraits();
|
||||
traits.set_supported_color_modes({light::ColorMode::BRIGHTNESS});
|
||||
return traits;
|
||||
}
|
||||
void write_state(light::LightState *state) override {
|
||||
this->light_state_ = state;
|
||||
state->current_values_as_brightness(&(this->bright_));
|
||||
if (this->state_ == On) {
|
||||
this->upper_->set_level(this->bright_);
|
||||
this->lower_->set_level(this->bright_);
|
||||
}
|
||||
}
|
||||
|
||||
void set_state(State s) {
|
||||
this->state_ = s;
|
||||
switch (s) {
|
||||
case (On):
|
||||
/* this -> light_state_->turn_on(); */
|
||||
this->upper_->set_level(this->bright_);
|
||||
this->lower_->set_level(this->bright_);
|
||||
break;
|
||||
case (Off):
|
||||
/* this -> light_state_->turn_off(); */
|
||||
this->upper_->set_level(0.0);
|
||||
this->lower_->set_level(0.0);
|
||||
break;
|
||||
case (Auto):
|
||||
break;
|
||||
}
|
||||
/* this -> write_state(this -> light_state_); */
|
||||
}
|
||||
|
||||
void loop() {
|
||||
uint8_t data = 10;
|
||||
this->read_register(0x0, &data, 0x1);
|
||||
/* ESP_LOGI(TAG, "READ value: %d", data); */
|
||||
if (data != 0) {
|
||||
if (data & 1) {
|
||||
this->set_state(Off);
|
||||
ESP_LOGI("TEST", "Set to Off", data);
|
||||
} else if ( data & 2 ){
|
||||
this->set_state(Auto);
|
||||
ESP_LOGI("TEST", "Set to Auto", data);
|
||||
} else if (data & 4) {
|
||||
this->set_state(On);
|
||||
ESP_LOGI("TEST", "Set to On", data);
|
||||
}
|
||||
}
|
||||
if(this->state_ == Auto) {
|
||||
if(data & 8){
|
||||
// TODO: turn on led
|
||||
/* ESP_LOGI(TAG, "Auto On"); */
|
||||
this->upper_->set_level(this->bright_);
|
||||
this->lower_->set_level(this->bright_);
|
||||
}
|
||||
else{
|
||||
/* ESP_LOGI(TAG, "Auto Off"); */
|
||||
this->upper_->set_level(0.0);
|
||||
this->lower_->set_level(0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
State state_;
|
||||
float bright_;
|
||||
light::LightState *light_state_;
|
||||
output::FloatOutput *upper_;
|
||||
output::FloatOutput *lower_;
|
||||
};
|
||||
|
||||
} // namespace c_monochromatic
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,7 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
output:
|
||||
- platform: empty_binary_output
|
||||
id: empty_binary_output_1
|
||||
```
|
||||
@@ -0,0 +1,7 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
binary_sensor:
|
||||
- platform: empty_binary_sensor
|
||||
name: Empty binary sensor
|
||||
```
|
||||
@@ -0,0 +1,6 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
empty_component:
|
||||
id: empty_component_1
|
||||
```
|
||||
@@ -0,0 +1,12 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
sensor:
|
||||
- platform: empty_compound_sensor
|
||||
sensor1:
|
||||
name: Sensor 1
|
||||
sensor2:
|
||||
name: Sensor 2
|
||||
sensor3:
|
||||
name: Sensor 3
|
||||
```
|
||||
@@ -0,0 +1,7 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
cover:
|
||||
platform: empty_cover
|
||||
name: Empty cover
|
||||
```
|
||||
@@ -0,0 +1,13 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
fan:
|
||||
- platform: empty_fan
|
||||
name: Empty fan
|
||||
output: gpio_d1
|
||||
|
||||
output:
|
||||
- platform: gpio
|
||||
pin: D1
|
||||
id: gpio_d1
|
||||
```
|
||||
@@ -0,0 +1,7 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
output:
|
||||
- platform: empty_float_output
|
||||
id: empty_float_output_1
|
||||
```
|
||||
@@ -0,0 +1,11 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
empty_i2c_component:
|
||||
id: empty_i2c_component_1
|
||||
address: 0x01 # optional
|
||||
|
||||
i2c:
|
||||
sda: 4
|
||||
scl: 5
|
||||
```
|
||||
+5
-3
@@ -1,5 +1,6 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "empty_i2c_component.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace empty_i2c_component {
|
||||
@@ -7,11 +8,12 @@ namespace empty_i2c_component {
|
||||
static const char *TAG = "empty_i2c_component.component";
|
||||
|
||||
void EmptyI2CComponent::setup() {
|
||||
|
||||
}
|
||||
|
||||
void EmptyI2CComponent::loop() {
|
||||
|
||||
uint8_t data = 10;
|
||||
this->read_register(0x0, &data, 0x1);
|
||||
ESP_LOGI(TAG, "READ value: %d", data);
|
||||
}
|
||||
|
||||
void EmptyI2CComponent::dump_config(){
|
||||
@@ -20,4 +22,4 @@ void EmptyI2CComponent::dump_config(){
|
||||
|
||||
|
||||
} // namespace empty_i2c_component
|
||||
} // namespace esphome
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,11 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
sensor:
|
||||
- platform: empty_i2c_sensor
|
||||
name: Empty I2C sensor
|
||||
|
||||
i2c:
|
||||
sda: 4
|
||||
scl: 5
|
||||
```
|
||||
@@ -0,0 +1,22 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import i2c, sensor
|
||||
from esphome.const import CONF_ID, ICON_EMPTY, UNIT_EMPTY
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
CONF_I2C_ADDR = 0x01
|
||||
|
||||
empty_i2c_sensor_ns = cg.esphome_ns.namespace('empty_i2c_sensor')
|
||||
EmptyI2CSensor = empty_i2c_sensor_ns.class_('EmptyI2CSensor', cg.PollingComponent, i2c.I2CDevice)
|
||||
|
||||
CONFIG_SCHEMA = sensor.sensor_schema().extend({
|
||||
cv.GenerateID(): cv.declare_id(EmptyI2CSensor),
|
||||
}).extend(cv.polling_component_schema('60s')).extend(i2c.i2c_device_schema(CONF_I2C_ADDR))
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield sensor.register_sensor(var, config)
|
||||
yield i2c.register_i2c_device(var, config)
|
||||
|
||||
+8
-1
@@ -1,5 +1,8 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "empty_i2c_sensor.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
static const char* const TAG = "i2c sensor";
|
||||
|
||||
namespace esphome {
|
||||
namespace empty_i2c_sensor {
|
||||
@@ -11,6 +14,10 @@ void EmptyI2CSensor::setup(){
|
||||
}
|
||||
|
||||
void EmptyI2CSensor::update(){
|
||||
uint8_t data = 10;
|
||||
this->read_register(0x0, &data, (size_t)0x1);
|
||||
ESP_LOGI(TAG, "sensor output: %d", data);
|
||||
this->publish_state((float)data);
|
||||
|
||||
}
|
||||
|
||||
@@ -19,4 +26,4 @@ void EmptyI2CSensor::dump_config(){
|
||||
}
|
||||
|
||||
} // namespace EmptyI2CSensor
|
||||
} // namespace esphome
|
||||
} // namespace esphome
|
||||
+2
-2
@@ -10,7 +10,7 @@ CONF_I2C_ADDR = 0x01
|
||||
empty_i2c_sensor_ns = cg.esphome_ns.namespace('empty_i2c_sensor')
|
||||
EmptyI2CSensor = empty_i2c_sensor_ns.class_('EmptyI2CSensor', cg.PollingComponent, i2c.I2CDevice)
|
||||
|
||||
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_EMPTY, ICON_EMPTY, 1).extend({
|
||||
CONFIG_SCHEMA = sensor.sensor_schema().extend({
|
||||
cv.GenerateID(): cv.declare_id(EmptyI2CSensor),
|
||||
}).extend(cv.polling_component_schema('60s')).extend(i2c.i2c_device_schema(CONF_I2C_ADDR))
|
||||
|
||||
@@ -19,4 +19,4 @@ def to_code(config):
|
||||
yield cg.register_component(var, config)
|
||||
yield sensor.register_sensor(var, config)
|
||||
yield i2c.register_i2c_device(var, config)
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
light:
|
||||
- platform: empty_light
|
||||
name: Empty light
|
||||
output: pwm_output
|
||||
|
||||
output:
|
||||
- platform: esp8266_pwm
|
||||
pin: D1
|
||||
frequency: 1000 Hz
|
||||
id: pwm_output
|
||||
```
|
||||
@@ -0,0 +1,7 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
sensor:
|
||||
- platform: empty_sensor
|
||||
name: Empty sensor
|
||||
```
|
||||
@@ -1,17 +1,18 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import sensor
|
||||
from esphome.const import CONF_ID
|
||||
from esphome.const import CONF_ID, UNIT_EMPTY, ICON_EMPTY
|
||||
|
||||
empty_sensor_ns = cg.esphome_ns.namespace('empty_sensor')
|
||||
|
||||
EmptySensor = empty_sensor_ns.class_('EmptySensor', cg.PollingComponent)
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema({
|
||||
CONFIG_SCHEMA = sensor.sensor_schema(UNIT_EMPTY, ICON_EMPTY, 1).extend({
|
||||
cv.GenerateID(): cv.declare_id(EmptySensor)
|
||||
}).extend(cv.polling_component_schema('60s'))
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
yield sensor.register_sensor(var, config)
|
||||
|
||||
@@ -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,28 @@
|
||||
#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);
|
||||
}
|
||||
|
||||
for(auto *binary_sensor : this->binary_sensors_){
|
||||
LOG_BINARY_SENSOR(" ", "Binary sensor", binary_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))
|
||||
@@ -0,0 +1,11 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
empty_spi_component:
|
||||
id: empty_spi_component_1
|
||||
cs_pin: D8
|
||||
|
||||
spi:
|
||||
clk_pin: D5
|
||||
miso_pin: D6
|
||||
```
|
||||
@@ -0,0 +1,12 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
sensor:
|
||||
- platform: empty_spi_sensor
|
||||
name: Empty SPI sensor
|
||||
cs_pin: D8
|
||||
|
||||
spi:
|
||||
clk_pin: D5
|
||||
miso_pin: D6
|
||||
```
|
||||
@@ -0,0 +1,7 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
switch:
|
||||
- platform: empty_switch
|
||||
name: Empty switch
|
||||
```
|
||||
@@ -0,0 +1,7 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
text_sensor:
|
||||
- platform: empty_text_sensor
|
||||
name: Empty text sensor
|
||||
```
|
||||
@@ -0,0 +1,11 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
empty_uart_component:
|
||||
id: empty_uart_component_1
|
||||
|
||||
uart:
|
||||
tx_pin: D0
|
||||
rx_pin: D1
|
||||
baud_rate: 9600
|
||||
```
|
||||
@@ -0,0 +1,12 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
sensor:
|
||||
- platform: empty_uart_sensor
|
||||
name: Empty UART sensor
|
||||
|
||||
uart:
|
||||
tx_pin: D0
|
||||
rx_pin: D1
|
||||
baud_rate: 9600
|
||||
```
|
||||
@@ -0,0 +1,11 @@
|
||||
```yaml
|
||||
# example configuration:
|
||||
|
||||
empty_i2c_component:
|
||||
id: empty_i2c_component_1
|
||||
address: 0x01 # optional
|
||||
|
||||
i2c:
|
||||
sda: 4
|
||||
scl: 5
|
||||
```
|
||||
@@ -0,0 +1,33 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import i2c, sensor, monochromatic, output, light
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
DEPENDENCIES = ['i2c']
|
||||
|
||||
CONF_I2C_ADDR = 0x09
|
||||
|
||||
showcase_component_ns = cg.esphome_ns.namespace('showcase_component')
|
||||
ShowcaseComponent = showcase_component_ns.class_('ShowcaseComponent', cg.Component, i2c.I2CDevice, light.LightOutput)
|
||||
|
||||
CONFIG_SCHEMA = light.BRIGHTNESS_ONLY_LIGHT_SCHEMA.extend(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(ShowcaseComponent),
|
||||
|
||||
cv.Required("upper"): cv.use_id(output.FloatOutput),
|
||||
cv.Required("lower"): cv.use_id(output.FloatOutput)
|
||||
# cv.Required("upper"): cv.use_id(monochromatic.MonochromaticLightOutput),
|
||||
# cv.Required("lower"): cv.use_id(monochromatic.MonochromaticLightOutput)
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(CONF_I2C_ADDR))
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
|
||||
upper = await cg.get_variable(config["upper"])
|
||||
cg.add(var.set_upper(upper))
|
||||
lower = await cg.get_variable(config["lower"])
|
||||
cg.add(var.set_lower(lower))
|
||||
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "showcase_component.h"
|
||||
#include <Arduino.h>
|
||||
|
||||
namespace esphome {
|
||||
namespace showcase_component {
|
||||
|
||||
/* static const char *TAG = "showcase_component.component"; */
|
||||
|
||||
void ShowcaseComponent::setup() {
|
||||
}
|
||||
|
||||
void ShowcaseComponent::turn_on(){
|
||||
this->write_state(On);
|
||||
}
|
||||
|
||||
void ShowcaseComponent::turn_off(){
|
||||
this->write_state(Off);
|
||||
}
|
||||
|
||||
void ShowcaseComponent::loop() {
|
||||
uint8_t data = 10;
|
||||
this->read_register(0x0, &data, 0x1);
|
||||
/* ESP_LOGI(TAG, "READ value: %d", data); */
|
||||
if(data != 0){
|
||||
if(data & 1){
|
||||
this->write_state(Off);
|
||||
/* ESP_LOGI(TAG, "Set to Off", data); */
|
||||
} else if ( data & 2 ){
|
||||
this->write_state(Auto);
|
||||
/* ESP_LOGI(TAG, "Set to Auto", data); */
|
||||
} else if ( data & 4 ){
|
||||
this->write_state(On);
|
||||
/* ESP_LOGI(TAG, "Set to On", data); */
|
||||
}
|
||||
}
|
||||
if(this->s_ == Auto) {
|
||||
if(data & 8){
|
||||
// TODO: turn on led
|
||||
/* ESP_LOGI(TAG, "Auto On"); */
|
||||
this->upper_->set_level(this->b_upper_);
|
||||
this->lower_->set_level(this->b_lower_);
|
||||
}
|
||||
else{
|
||||
/* ESP_LOGI(TAG, "Auto Off"); */
|
||||
this->upper_->set_level(0.0);
|
||||
this->lower_->set_level(0.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ShowcaseComponent::dump_config(){
|
||||
ESP_LOGCONFIG(TAG, "showcase component");
|
||||
}
|
||||
|
||||
} // namespace empty_i2c_component
|
||||
} // namespace esphome
|
||||
@@ -0,0 +1,106 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/entity_base.h"
|
||||
#include "esphome/core/log.h"
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/i2c/i2c.h"
|
||||
#include "esphome/components/output/float_output.h"
|
||||
#include "esphome/components/light/light_output.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace showcase_component {
|
||||
|
||||
/* class Output: public light::LightOutput{ */
|
||||
/* public: */
|
||||
/* void set_output(output::FloatOutput *output) { output_ = output; } */
|
||||
/* light::LightTraits get_traits() override { */
|
||||
/* auto traits = light::LightTraits(); */
|
||||
/* traits.set_supported_color_modes({light::ColorMode::BRIGHTNESS}); */
|
||||
/* return traits; */
|
||||
/* } */
|
||||
/* void write_state(light::LightState *state) override { */
|
||||
/* float bright; */
|
||||
/* state->current_values_as_brightness(&bright); */
|
||||
/* this->output_->set_level(bright); */
|
||||
/* } */
|
||||
|
||||
/* protected: */
|
||||
/* output::FloatOutput *output_; */
|
||||
/* }; */
|
||||
|
||||
enum State{ Off, Auto, On };
|
||||
|
||||
static const char *TAG = "showcase_component.component";
|
||||
|
||||
class ShowcaseComponent : public i2c::I2CDevice, public Component, public EntityBase, public light::LightOutput {
|
||||
public:
|
||||
State s_{Off};
|
||||
float b_upper_{1.0};
|
||||
float b_lower_{1.0};
|
||||
|
||||
void turn_on();
|
||||
void turn_off();
|
||||
|
||||
void publish_state(){ this->remote_values_callback_.call(); }
|
||||
|
||||
void add_new_remote_values_callback(std::function<void()> &&send_callback) {
|
||||
this->remote_values_callback_.add(std::move(send_callback));
|
||||
}
|
||||
|
||||
void setup() override;
|
||||
void loop() override;
|
||||
void dump_config() override;
|
||||
|
||||
void set_upper(output::FloatOutput *upper) {this->upper_ = upper;}
|
||||
void set_lower(output::FloatOutput *lower) {this->lower_ = lower;}
|
||||
|
||||
void write_state(State s){
|
||||
ESP_LOGI(TAG, "Write_state");
|
||||
this->s_ = s;
|
||||
switch(s) {
|
||||
case(On):
|
||||
/* ESP_LOGI(TAG, "Set to On"); */
|
||||
this->set_level(this->b_upper_, this->b_lower_);
|
||||
break;
|
||||
case(Off):
|
||||
/* ESP_LOGI(TAG, "Set to Off"); */
|
||||
this->upper_->set_level(0.0);
|
||||
this->lower_->set_level(0.0);
|
||||
break;
|
||||
case(Auto):
|
||||
/* ESP_LOGI(TAG, "Set to Auto"); */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void set_level(float bright){
|
||||
this->set_level(bright, bright);
|
||||
/* this->upper_->write_state(upper); */
|
||||
/* this->lower_->write_state(lower); */
|
||||
}
|
||||
|
||||
void set_level(float upper, float lower){
|
||||
this->set_level_upper(upper);
|
||||
this->set_level_lower(lower);
|
||||
/* this->upper_->write_state(upper); */
|
||||
/* this->lower_->write_state(lower); */
|
||||
}
|
||||
|
||||
void set_level_upper(float bright){
|
||||
this->b_upper_ = bright;
|
||||
this->upper_->set_level(bright);
|
||||
}
|
||||
|
||||
void set_level_lower(float bright){
|
||||
this->b_lower_ = bright;
|
||||
this->lower_->set_level(bright);
|
||||
}
|
||||
protected:
|
||||
CallbackManager<void()> remote_values_callback_{};
|
||||
|
||||
output::FloatOutput *upper_;
|
||||
output::FloatOutput *lower_;
|
||||
};
|
||||
|
||||
} // namespace empty_i2c_component
|
||||
} // namespace esphome
|
||||
@@ -1,24 +0,0 @@
|
||||
#include "esphome/core/log.h"
|
||||
#include "example_custom_sensor.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace example_custom_sensor {
|
||||
|
||||
void ExampleCustomSensor::setup() {
|
||||
// This will be called by App.setup()
|
||||
}
|
||||
|
||||
void ExampleCustomSensor::loop() {
|
||||
// This will be called by App.loop()
|
||||
}
|
||||
|
||||
void ExampleCustomSensor::update(){
|
||||
// This will be called every "update_interval" milliseconds.
|
||||
}
|
||||
|
||||
void ExampleCustomSensor::dump_config(){
|
||||
ESP_LOGCONFIG(TAG, "Empty custom sensor");
|
||||
}
|
||||
|
||||
} //namespace example_custom_sensor
|
||||
} //namespace esphome
|
||||
@@ -1,17 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/components/sensor/sensor.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace example_custom_sensor {
|
||||
|
||||
class ExampleCustomSensor : public sensor::Sensor, public PollingComponent {
|
||||
void setup() override;
|
||||
void dump_config() override;
|
||||
void loop() override;
|
||||
void update() override;
|
||||
};
|
||||
|
||||
} //namespace example_custom_sensor
|
||||
} //namespace esphome
|
||||
@@ -1,17 +0,0 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import sensor
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
example_custom_sensor_ns = cg.esphome_ns.namespace('example_custom_sensor')
|
||||
|
||||
ExampleCustomSensor = example_custom_sensor_ns.class_('ExampleCustomSensor', cg.PollingComponent)
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema({
|
||||
cv.GenerateID(): cv.declare_id(ExampleCustomSensor)
|
||||
}).extend(cv.polling_component_schema('60s'))
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield cg.register_component(var, config)
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.4 KiB |
+31
-16
@@ -6,31 +6,38 @@ packages:
|
||||
|
||||
sensor:
|
||||
- platform: empty_sensor
|
||||
id: empty_sensor_1
|
||||
name: Empty sensor
|
||||
|
||||
- platform: empty_i2c_sensor
|
||||
id: empty_i2c_sensor_1
|
||||
name: Empty I2C sensor
|
||||
|
||||
- platform: empty_spi_sensor
|
||||
id: empty_spi_sensor_1
|
||||
name: Empty SPI sensor
|
||||
cs_pin: D8
|
||||
|
||||
- platform: empty_uart_sensor
|
||||
id: empty_uart_sensor_1
|
||||
name: Empty UART sensor
|
||||
|
||||
- platform: empty_compound_sensor
|
||||
id: empty_compound_sensor_1
|
||||
sensor1:
|
||||
name: "Sensor 1"
|
||||
name: Sensor 1
|
||||
sensor2:
|
||||
name: "Sensor 2"
|
||||
name: Sensor 2
|
||||
sensor3:
|
||||
name: "Sensor 3"
|
||||
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
|
||||
id: empty_binary_sensor_1
|
||||
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
|
||||
@@ -40,25 +47,29 @@ output:
|
||||
|
||||
light:
|
||||
- platform: empty_light
|
||||
id: empty_light_1
|
||||
name: Empty light
|
||||
output: empty_float_output_1
|
||||
|
||||
switch:
|
||||
- platform: empty_switch
|
||||
id: empty_switch_1
|
||||
name: Empty switch
|
||||
|
||||
fan:
|
||||
- platform: empty_fan
|
||||
id: empty_fan_1
|
||||
name: Empty fan
|
||||
output: empty_binary_output_1
|
||||
|
||||
text_sensor:
|
||||
- platform: empty_text_sensor
|
||||
id: empty_text_sensor_1
|
||||
|
||||
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
|
||||
id: empty_cover_1
|
||||
name: Empty cover
|
||||
|
||||
empty_component:
|
||||
id: empty_component_1
|
||||
@@ -85,4 +96,8 @@ spi:
|
||||
|
||||
empty_spi_component:
|
||||
id: empty_spi_component_1
|
||||
cs_pin: D8
|
||||
cs_pin: D8
|
||||
|
||||
empty_sensor_hub:
|
||||
id: empty_sensor_hub_1
|
||||
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
packages:
|
||||
device: !include device.yaml
|
||||
|
||||
sensor:
|
||||
- platform: example_custom_sensor
|
||||
id: example_custom_sensor_1
|
||||
Reference in New Issue
Block a user