mirror of
https://github.com/esphome/esphome.git
synced 2024-11-26 08:55:22 +01:00
Add option to suppress embedded MCU updates on certain datapoints (#1396)
This commit is contained in:
parent
3afb564a48
commit
0ea41e2f71
3 changed files with 18 additions and 0 deletions
|
@ -6,6 +6,8 @@ from esphome.const import CONF_ID, CONF_TIME_ID
|
||||||
|
|
||||||
DEPENDENCIES = ['uart']
|
DEPENDENCIES = ['uart']
|
||||||
|
|
||||||
|
CONF_IGNORE_MCU_UPDATE_ON_DATAPOINTS = "ignore_mcu_update_on_datapoints"
|
||||||
|
|
||||||
tuya_ns = cg.esphome_ns.namespace('tuya')
|
tuya_ns = cg.esphome_ns.namespace('tuya')
|
||||||
Tuya = tuya_ns.class_('Tuya', cg.Component, uart.UARTDevice)
|
Tuya = tuya_ns.class_('Tuya', cg.Component, uart.UARTDevice)
|
||||||
|
|
||||||
|
@ -13,6 +15,7 @@ CONF_TUYA_ID = 'tuya_id'
|
||||||
CONFIG_SCHEMA = cv.Schema({
|
CONFIG_SCHEMA = cv.Schema({
|
||||||
cv.GenerateID(): cv.declare_id(Tuya),
|
cv.GenerateID(): cv.declare_id(Tuya),
|
||||||
cv.Optional(CONF_TIME_ID): cv.use_id(time.RealTimeClock),
|
cv.Optional(CONF_TIME_ID): cv.use_id(time.RealTimeClock),
|
||||||
|
cv.Optional(CONF_IGNORE_MCU_UPDATE_ON_DATAPOINTS): cv.ensure_list(cv.uint8_t),
|
||||||
}).extend(cv.COMPONENT_SCHEMA).extend(uart.UART_DEVICE_SCHEMA)
|
}).extend(cv.COMPONENT_SCHEMA).extend(uart.UART_DEVICE_SCHEMA)
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,3 +26,6 @@ def to_code(config):
|
||||||
if CONF_TIME_ID in config:
|
if CONF_TIME_ID in config:
|
||||||
time_ = yield cg.get_variable(config[CONF_TIME_ID])
|
time_ = yield cg.get_variable(config[CONF_TIME_ID])
|
||||||
cg.add(var.set_time_id(time_))
|
cg.add(var.set_time_id(time_))
|
||||||
|
if CONF_IGNORE_MCU_UPDATE_ON_DATAPOINTS in config:
|
||||||
|
for dp in config[CONF_IGNORE_MCU_UPDATE_ON_DATAPOINTS]:
|
||||||
|
cg.add(var.add_ignore_mcu_update_on_datapoints(dp))
|
||||||
|
|
|
@ -256,6 +256,14 @@ void Tuya::handle_datapoint_(const uint8_t *buffer, size_t len) {
|
||||||
datapoint.type = (TuyaDatapointType) buffer[1];
|
datapoint.type = (TuyaDatapointType) buffer[1];
|
||||||
datapoint.value_uint = 0;
|
datapoint.value_uint = 0;
|
||||||
|
|
||||||
|
// drop update if datapoint is in ignore_mcu_datapoint_update list
|
||||||
|
for (auto i : this->ignore_mcu_update_on_datapoints_) {
|
||||||
|
if (datapoint.id == i) {
|
||||||
|
ESP_LOGV(TAG, "Datapoint %u found in ignore_mcu_update_on_datapoints list, dropping MCU update", datapoint.id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
size_t data_size = (buffer[2] << 8) + buffer[3];
|
size_t data_size = (buffer[2] << 8) + buffer[3];
|
||||||
const uint8_t *data = buffer + 4;
|
const uint8_t *data = buffer + 4;
|
||||||
size_t data_len = len - 4;
|
size_t data_len = len - 4;
|
||||||
|
|
|
@ -71,6 +71,9 @@ class Tuya : public Component, public uart::UARTDevice {
|
||||||
#ifdef USE_TIME
|
#ifdef USE_TIME
|
||||||
void set_time_id(time::RealTimeClock *time_id) { this->time_id_ = time_id; }
|
void set_time_id(time::RealTimeClock *time_id) { this->time_id_ = time_id; }
|
||||||
#endif
|
#endif
|
||||||
|
void add_ignore_mcu_update_on_datapoints(uint8_t ignore_mcu_update_on_datapoints) {
|
||||||
|
this->ignore_mcu_update_on_datapoints_.push_back(ignore_mcu_update_on_datapoints);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void handle_char_(uint8_t c);
|
void handle_char_(uint8_t c);
|
||||||
|
@ -93,6 +96,7 @@ class Tuya : public Component, public uart::UARTDevice {
|
||||||
std::vector<TuyaDatapointListener> listeners_;
|
std::vector<TuyaDatapointListener> listeners_;
|
||||||
std::vector<TuyaDatapoint> datapoints_;
|
std::vector<TuyaDatapoint> datapoints_;
|
||||||
std::vector<uint8_t> rx_message_;
|
std::vector<uint8_t> rx_message_;
|
||||||
|
std::vector<uint8_t> ignore_mcu_update_on_datapoints_{};
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tuya
|
} // namespace tuya
|
||||||
|
|
Loading…
Reference in a new issue