mirror of
https://github.com/esphome/esphome.git
synced 2024-11-25 00:18:11 +01:00
Fixes
This commit is contained in:
parent
a07a835eb0
commit
968ff4b619
11 changed files with 70 additions and 35 deletions
|
@ -9,7 +9,7 @@
|
|||
|
||||
# pylint: disable=unused-import
|
||||
from esphome.cpp_generator import ( # noqa
|
||||
Expression, RawExpression, TemplateArguments,
|
||||
Expression, RawExpression, RawStatement, TemplateArguments,
|
||||
StructInitializer, ArrayInitializer, safe_exp, Statement,
|
||||
progmem_array, statement, variable, Pvariable, new_Pvariable,
|
||||
add, add_global, add_library, add_build_flag, add_define,
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
import esphome.config_validation as cv
|
||||
import esphome.codegen as cg
|
||||
from esphome.components import esp32_ble_tracker
|
||||
from esphome.const import CONF_ID
|
||||
|
||||
DEPENDENCIES = ['esp32_ble_tracker']
|
||||
ble_ibeacon_ns = cg.esphome_ns.namespace('ble_ibeacon')
|
||||
IBeaconListener = ble_ibeacon_ns.class_('IBeaconListener', esp32_ble_tracker.ESPBTDeviceListener)
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema({
|
||||
cv.GenerateID(): cv.declare_id(IBeaconListener),
|
||||
}).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA)
|
||||
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield esp32_ble_tracker.register_ble_device(var, config)
|
|
@ -21,5 +21,4 @@ def to_code(config):
|
|||
var = cg.variable(config[CONF_ID], rhs)
|
||||
for i, conf in enumerate(config[CONF_SENSORS]):
|
||||
sens = cg.Pvariable(conf[CONF_ID], var.get_sensor(i))
|
||||
cg.add(sens.set_name(conf[CONF_NAME]))
|
||||
yield sensor.register_sensor(sens, conf)
|
||||
|
|
|
@ -24,6 +24,5 @@ def to_code(config):
|
|||
rhs = CustomSwitchConstructor(template_)
|
||||
var = cg.variable(config[CONF_ID], rhs)
|
||||
for i, conf in enumerate(config[CONF_SWITCHES]):
|
||||
switch_ = cg.new_Pvariable(conf[CONF_ID], var.get_switch(i))
|
||||
cg.add(switch_.set_name(conf[CONF_NAME]))
|
||||
switch_ = cg.Pvariable(conf[CONF_ID], var.get_switch(i))
|
||||
yield switch.register_switch(switch_, conf)
|
||||
|
|
|
@ -24,6 +24,5 @@ def to_code(config):
|
|||
var = cg.variable(config[CONF_ID], rhs)
|
||||
|
||||
for i, conf in enumerate(config[CONF_TEXT_SENSORS]):
|
||||
text = cg.new_Pvariable(conf[CONF_ID], var.get_text_sensor(i))
|
||||
cg.add(text.set_name(conf[CONF_NAME]))
|
||||
text = cg.Pvariable(conf[CONF_ID], var.get_text_sensor(i))
|
||||
yield text_sensor.register_text_sensor(text, conf)
|
||||
|
|
|
@ -4,7 +4,7 @@ from esphome.const import CONF_ID, CONF_SCAN_INTERVAL, ESP_PLATFORM_ESP32
|
|||
from esphome.core import coroutine
|
||||
|
||||
ESP_PLATFORMS = [ESP_PLATFORM_ESP32]
|
||||
AUTO_LOAD = ['xiaomi_ble', 'ble_ibeacon']
|
||||
AUTO_LOAD = ['xiaomi_ble']
|
||||
|
||||
CONF_ESP32_BLE_ID = 'esp32_ble_id'
|
||||
esp32_ble_tracker_ns = cg.esphome_ns.namespace('esp32_ble_tracker')
|
||||
|
|
|
@ -33,6 +33,7 @@ class ESPBTUUID {
|
|||
|
||||
class ESPBLEiBeacon {
|
||||
public:
|
||||
ESPBLEiBeacon() { memset(&this->beacon_data_, 0, sizeof(this->beacon_data_)); }
|
||||
ESPBLEiBeacon(const uint8_t *data);
|
||||
static optional<ESPBLEiBeacon> from_manufacturer_data(const std::string &data);
|
||||
|
||||
|
@ -98,9 +99,7 @@ class ESPBTDeviceListener {
|
|||
public:
|
||||
virtual void on_scan_end() {}
|
||||
virtual bool parse_device(const ESPBTDevice &device) = 0;
|
||||
void set_parent(ESP32BLETracker *parent) {
|
||||
parent_ = parent;
|
||||
}
|
||||
void set_parent(ESP32BLETracker *parent) { parent_ = parent; }
|
||||
|
||||
protected:
|
||||
ESP32BLETracker *parent_{nullptr};
|
||||
|
|
|
@ -152,7 +152,7 @@ def add_includes(includes):
|
|||
for include in includes:
|
||||
path = CORE.relative_config_path(include)
|
||||
res = os.path.relpath(path, CORE.relative_build_path('src')).replace(os.path.sep, '/')
|
||||
cg.add_global(cg.RawExpression(u'#include "{}"'.format(res)))
|
||||
cg.add_global(cg.RawStatement(u'#include "{}"'.format(res)))
|
||||
|
||||
|
||||
@coroutine_with_priority(100.0)
|
||||
|
|
|
@ -12,5 +12,5 @@ fi
|
|||
|
||||
set -x
|
||||
|
||||
script/clang-tidy.py -c --fix
|
||||
script/clang-tidy.py -c --fix --all-headers
|
||||
script/clang-format.py -c -i
|
||||
|
|
38
tests/custom.h
Normal file
38
tests/custom.h
Normal 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");
|
||||
}
|
||||
};
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue