Compare commits

74 Commits
Author SHA1 Message Date
gnxlxnxx 9870f2ea93 .................... 2024-03-19 15:53:18 +01:00
gnxlxnxx 534d6fd05d ................... 2024-03-19 15:49:31 +01:00
gnxlxnxx 8d02d1dbee .............................. 2024-01-24 22:50:16 +01:00
gnxlxnxx 759b4eb255 ............................ 2024-01-24 22:45:14 +01:00
gnxlxnxx ad4b2f2a5b ........................... 2024-01-24 22:35:31 +01:00
gnxlxnxx 0bd1f33fb9 .......................... 2024-01-24 22:34:05 +01:00
gnxlxnxx 09c6898a2a ......................... 2024-01-24 22:28:24 +01:00
gnxlxnxx 1d826ac4af ........................ 2024-01-24 22:20:05 +01:00
gnxlxnxx e19ac64db1 ....................... 2024-01-24 22:19:22 +01:00
gnxlxnxx a13f98ec7e ...................... 2024-01-24 22:15:51 +01:00
gnxlxnxx 5d15a6f1dc ..................... 2024-01-24 22:11:18 +01:00
gnxlxnxx 48f0cb517e .................... 2024-01-24 21:35:25 +01:00
gnxlxnxx 9738f1bd71 ................... 2024-01-23 22:39:54 +01:00
gnxlxnxx 72908bdf26 ................... 2024-01-05 00:57:55 +01:00
gnxlxnxx 36ae7a47bd .................. 2024-01-04 23:59:53 +01:00
gnxlxnxx cd19a7d7a0 ................. 2024-01-04 22:49:20 +01:00
gnxlxnxx cb358e0e27 ................. 2024-01-04 01:15:04 +01:00
gnxlxnxx 46bd170839 ................ 2024-01-04 00:57:24 +01:00
gnxlxnxx d296b1e61d ............... 2024-01-04 00:56:29 +01:00
gnxlxnxx d076942363 .............. 2024-01-03 22:28:44 +01:00
gnxlxnxx 6c57d06d86 ............. 2024-01-03 22:26:54 +01:00
gnxlxnxx 00903ca832 ............. 2024-01-03 22:09:26 +01:00
gnxlxnxx 4df82f668f ............ 2024-01-03 22:03:31 +01:00
gnxlxnxx 43f27bbbd9 ............ 2024-01-03 21:56:56 +01:00
gnxlxnxx 51db90093e ........... 2024-01-03 21:56:05 +01:00
gnxlxnxx 108f5a6433 .......... 2024-01-03 21:55:15 +01:00
gnxlxnxx e72cb91530 ......... 2024-01-03 21:44:50 +01:00
gnxlxnxx 5fcb15f3a0 ........ 2024-01-03 21:40:53 +01:00
gnxlxnxx 53b23340dc ....... 2024-01-03 21:35:10 +01:00
gnxlxnxx ac3080f1bb ...... 2024-01-03 21:34:18 +01:00
gnxlxnxx 1728c1aae8 ..... 2024-01-03 21:32:47 +01:00
gnxlxnxx fc5a9d85d3 .... 2024-01-03 21:28:07 +01:00
gnxlxnxx 08a99e9ee5 ... 2024-01-03 21:23:27 +01:00
gnxlxnxx cb427b17dc .. 2024-01-03 21:14:42 +01:00
gnxlxnxx 18cab91774 . 2024-01-03 16:33:26 +01:00
gnxlxnxx 7a45e2b8cf . 2024-01-03 16:30:31 +01:00
gnxlxnxx 5effe60dd7 . 2024-01-03 16:03:12 +01:00
gnxlxnxx a35709a233 . 2024-01-03 01:29:48 +01:00
gnxlxnxx 999db6bca9 . 2024-01-03 01:25:15 +01:00
gnxlxnxx ec18740dae . 2024-01-03 01:20:43 +01:00
gnxlxnxx fba4c0d51f . 2024-01-03 01:14:31 +01:00
gnxlxnxx d94dca1832 . 2024-01-03 01:13:35 +01:00
gnxlxnxx 62fa86abf8 . 2024-01-03 01:12:42 +01:00
gnxlxnxx 6a7bc20ad0 . 2024-01-03 01:08:25 +01:00
gnxlxnxx f90c2ec7c3 . 2024-01-03 01:03:43 +01:00
gnxlxnxx 1f733d2887 . 2024-01-03 00:42:17 +01:00
gnxlxnxx 6191889745 . 2024-01-03 00:36:45 +01:00
gnxlxnxx 524927671e BAAAAAR 2024-01-03 00:33:59 +01:00
gnxlxnxx f61a94e32b FOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO 2024-01-03 00:31:07 +01:00
gnxlxnxx 39d5a466eb Add sensor 2023-12-20 16:17:02 +01:00
gnxlxnxx 099510e340 see code 2023-12-20 15:58:58 +01:00
gnxlxnxx ef51d5b253 wtf 2023-12-20 15:58:03 +01:00
gnxlxnxx 3a7276ce1c see code 2023-12-20 15:56:48 +01:00
gnxlxnxx 98d3dda32e change foo 2023-12-20 15:55:33 +01:00
gnxlxnxx 8357412036 Foooooo 2023-12-20 15:48:45 +01:00
gnxlxnxx 277ed4fd01 BAAAR 2023-12-20 15:35:48 +01:00
gnxlxnxx 182ea3e204 Foooooo 2023-12-20 15:24:13 +01:00
gnxlxnxx 8486714605 baz 2023-12-18 22:50:00 +01:00
gnxlxnxx bd3f376e52 baaaaar 2023-12-18 22:46:51 +01:00
gnxlxnxx 048892359e Fooooooo 2023-12-18 22:45:56 +01:00
gnxlxnxx f150e66357 Foooo 2023-12-18 22:42:05 +01:00
gnxlxnxx 0d099f7449 Update 'components/empty_i2c_component/empty_i2c_component.cpp' 2023-12-17 21:30:40 +01:00
gnxlxnxx da631bb6a0 Fixes 2023-12-17 20:42:15 +01:00
gnxlxnxx 90b58c7e4d rename folder 2023-12-17 20:31:18 +01:00
gnxlxnxx 9ee2ee5864 Test i2c foo 2023-12-17 20:21:55 +01:00
HB 31c3e4aba9 Added binary sensors to dump_config in sensor hub 2020-10-01 05:43:57 +02:00
HB 8a9291c8ac empty sensor hub 2020-10-01 05:33:13 +02:00
HB b3f368ad3a use names as much as possible for friendlier config 2020-10-01 00:00:50 +02:00
HB a37a62e31d sensor fix, readme configuration examples 2020-09-30 23:58:10 +02:00
HB b567cbd7a5 yaml formatting 2020-09-30 21:40:33 +02:00
HB 11791476b0 config example in readme test 2020-09-30 21:27:29 +02:00
HB ae336d2b80 config example in readme FIX 2020-09-30 21:26:32 +02:00
HB c5a762956f config example in readme 2020-09-30 21:25:43 +02:00
HB a9eab678d0 enough with the logo already 2020-09-30 18:30:45 +02:00
90 changed files with 751 additions and 88 deletions
+35
View File
@@ -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,100 @@
#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 {
static const char *TAG = "empty_i2c_sensor.sensor";
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
+7
View File
@@ -0,0 +1,7 @@
```yaml
# example configuration:
output:
- platform: empty_binary_output
id: empty_binary_output_1
```
+7
View File
@@ -0,0 +1,7 @@
```yaml
# example configuration:
binary_sensor:
- platform: empty_binary_sensor
name: Empty binary sensor
```
+6
View File
@@ -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
```
+7
View File
@@ -0,0 +1,7 @@
```yaml
# example configuration:
cover:
platform: empty_cover
name: Empty cover
```
+13
View File
@@ -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
```
+7
View File
@@ -0,0 +1,7 @@
```yaml
# example configuration:
output:
- platform: empty_float_output
id: empty_float_output_1
```
+11
View File
@@ -0,0 +1,11 @@
```yaml
# example configuration:
empty_i2c_component:
id: empty_i2c_component_1
address: 0x01 # optional
i2c:
sda: 4
scl: 5
```
@@ -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
+11
View File
@@ -0,0 +1,11 @@
```yaml
# example configuration:
sensor:
- platform: empty_i2c_sensor
name: Empty I2C sensor
i2c:
sda: 4
scl: 5
```
+22
View File
@@ -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)
@@ -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
@@ -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)
+14
View File
@@ -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
```
+7
View File
@@ -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)
+33
View File
@@ -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
```
+20
View File
@@ -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
+23
View File
@@ -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))
+11
View File
@@ -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
```
+12
View File
@@ -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
```
+7
View File
@@ -0,0 +1,7 @@
```yaml
# example configuration:
switch:
- platform: empty_switch
name: Empty switch
```
+7
View File
@@ -0,0 +1,7 @@
```yaml
# example configuration:
text_sensor:
- platform: empty_text_sensor
name: Empty text sensor
```
+11
View File
@@ -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
```
+12
View File
@@ -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
```
+11
View File
@@ -0,0 +1,11 @@
```yaml
# example configuration:
empty_i2c_component:
id: empty_i2c_component_1
address: 0x01 # optional
i2c:
sda: 4
scl: 5
```
+33
View File
@@ -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)
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

+31 -16
View File
@@ -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
-6
View File
@@ -1,6 +0,0 @@
packages:
device: !include device.yaml
sensor:
- platform: example_custom_sensor
id: example_custom_sensor_1