1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-02 03:12:20 +01:00
This commit is contained in:
Otto Winter
2019-05-08 11:31:06 +02:00
parent a07a835eb0
commit 968ff4b619
11 changed files with 70 additions and 35 deletions

38
tests/custom.h Normal file
View File

@@ -0,0 +1,38 @@
class CustomSensor : public Component, public Sensor {
public:
void loop() override {
publish_state(42.0);
}
};
class CustomTextSensor : public Component, public TextSensor {
public:
void loop() override {
publish_state("Hello World");
}
};
class CustomBinarySensor : public Component, public BinarySensor {
public:
void loop() override {
publish_state(false);
}
};
class CustomSwitch : public Switch {
protected:
void write_state(bool state) override {
ESP_LOGD("custom_switch", "Setting %s", ONOFF(state));
}
};
class CustomComponent : public PollingComponent {
public:
void setup() override {
ESP_LOGD("custom_component", "Setup");
}
void update() override {
ESP_LOGD("custom_component", "Update");
}
};

View File

@@ -7,6 +7,8 @@ esphome:
- wait_until:
- api.connected
- wifi.connected
includes:
- custom.h
substitutions:
devicename: test3
@@ -65,6 +67,7 @@ ota:
logger:
hardware_uart: UART1
level: DEBUG
esp8266_store_log_strings_in_flash: false
web_server:
@@ -124,7 +127,8 @@ sensor:
gain: 60x
- platform: custom
lambda: |-
auto s = new sensor::Sensor();
auto s = new CustomSensor();
App.register_component(s);
return {s};
sensors:
- id: custom_sensor
@@ -187,9 +191,10 @@ binary_sensor:
name: TTP229 LSF Test
- platform: custom
lambda: |-
auto s = new binary_sensor::BinarySensor();
auto s = new CustomBinarySensor();
App.register_component(s);
return {s};
sensors:
binary_sensors:
- id: custom_binary_sensor
name: Custom Binary Sensor
@@ -225,6 +230,14 @@ text_sensor:
- platform: homeassistant
entity_id: sensor.hello_world2
id: ha_hello_world2
- platform: custom
lambda: |-
auto s = new CustomTextSensor();
App.register_component(s);
return {s};
text_sensors:
- id: custom_text_sensor
name: Custom Text Sensor
script:
- id: my_script
@@ -249,12 +262,18 @@ switch:
interlock: *interlock
- platform: custom
lambda: |-
auto s = new switch::Switch();
auto s = new CustomSwitch();
return {s};
sensors:
switches:
- id: custom_switch
name: Custom Switch
custom_component:
lambda: |-
auto s = new CustomComponent();
s->set_update_interval(15000);
return {s};
stepper:
- platform: uln2003
id: my_stepper