diff --git a/README.md b/README.md index db13382..e0b20a6 100644 --- a/README.md +++ b/README.md @@ -12,5 +12,9 @@ external_components: components: [ component1, component2 ] ``` -## NOTE: Some components were merged to esphome :tada: -- [keypad](https://github.com/ssieb/custom_components/tree/master/components/keypad) -> [matrix_keypad](https://esphome.io/components/matrix_keypad.html?highlight=keypad) +## NOTE: Some components have been merged to esphome :tada: +- keypad, matrix_keypad -> [matrix_keypad](https://esphome.io/components/matrix_keypad) +- vbus -> [Resol VBus](https://esphome.io/components/vbus) +- wiegand -> [Wiegand Reader](https://esphome.io/components/wiegand) +- kuntze -> [Kuntze pool sensor](https://esphome.io/components/sensor/kuntze) +- growatt -> [Growatt Solar](https://esphome.io/components/sensor/growatt_solar) diff --git a/components/growatt/README.md b/components/growatt/README.md deleted file mode 100644 index 0f970cb..0000000 --- a/components/growatt/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# Growatt inverter modbus interface - -A configured uart component is required. -A configured modbus component is usually optional. It will be automatically created. - -Example: -```yaml -sensor: - - platform: growatt - id: my_growatt - input_power: - id: inv - pv1_voltage: - id: pv1_volt -``` - -All sensors are optional. The available sensors are: -- `input_power` -- `pv1_voltage` -- `pv1_current` -- `pv1_power` -- `pv2_voltage` -- `pv2_current` -- `pv2_power` -- `output_power` -- `grid_frequency` -- `ac_voltage` -- `ac_current` -- `ac_power` -- `today_gen` -- `total_gen` -- `temperature` -- `today_grid` -- `total_grid` - diff --git a/components/growatt/__init__.py b/components/growatt/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/components/growatt/growatt.cpp b/components/growatt/growatt.cpp deleted file mode 100644 index 1025bed..0000000 --- a/components/growatt/growatt.cpp +++ /dev/null @@ -1,165 +0,0 @@ -#include "growatt.h" -#include "esphome/core/log.h" - -namespace esphome { -namespace growatt { - -static const char *TAG = "growatt"; - -static const uint8_t CMD_READ_INPUT_REG = 0x04; -static const uint16_t REGISTER_START[] = {0, 93, 1048}; -static const uint16_t REGISTER_COUNT[] = {57, 1, 4}; - -void Growatt::on_modbus_data(const std::vector &data) { - uint32_t raw_32; - uint16_t raw_16; - - auto get_16bit = [&](int i) -> uint16_t { - return (uint16_t(data[i * 2]) << 8) | uint16_t(data[i * 2 + 1]); - }; - auto get_32bit = [&](int i) -> uint32_t { - return (uint32_t(get_16bit(i)) << 16) | uint32_t(get_16bit(i + 1)); - }; - - this->waiting_ = false; - if (data.size() < REGISTER_COUNT[this->state_ - 1] * 2) { - ESP_LOGW(TAG, "Invalid data packet size (%d) for state %d", data.size(), this->state_); - return; - } - ESP_LOGD(TAG, "Data: %s", hexencode(data).c_str()); - - if (this->state_ == 1) { - this->state_ = 2; - raw_32 = get_32bit(1); - float input_power = raw_32 / 10.0f; - - raw_16 = get_16bit(3); - float pv1_voltage = raw_16 / 10.0f; - raw_16 = get_16bit(4); - float pv1_current = raw_16 / 10.0f; - raw_32 = get_32bit(5); - float pv1_power = raw_32 / 10.0f; - - raw_16 = get_16bit(7); - float pv2_voltage = raw_16 / 10.0f; - raw_16 = get_16bit(8); - float pv2_current = raw_16 / 10.0f; - raw_32 = get_32bit(9); - float pv2_power = raw_32 / 10.0f; - - raw_32 = get_32bit(35); - float output_power = raw_32 / 10.0f; - - raw_16 = get_16bit(37); - float grid_frequency = raw_16 / 100.0f; - - raw_16 = get_16bit(38); - float ac_voltage = raw_16 / 10.0f; - raw_16 = get_16bit(39); - float ac_current = raw_16 / 10.0f; - raw_32 = get_32bit(40); - float ac_power = raw_32 / 10.0f; - - raw_32 = get_32bit(53); - float today_gen = raw_32 / 10.0f; - raw_32 = get_32bit(55); - float total_gen = raw_32 / 10.0f; - - ESP_LOGD(TAG, "DATA: IP=%.1fW V1=%.1fV I1=%.3fA P1=%.1fW V2=%.1fV I2=%.3fA P2=%.1fW OP=%.1fW F=%.1fHz " - "VAC=%.1fV IAC=%.3fA PAC=%.1fW TDGE=%.1fkWh TTGE=%.1fkWh", - input_power, pv1_voltage, pv1_current, pv1_power, pv2_voltage, pv2_current, pv2_power, output_power, grid_frequency, - ac_voltage, ac_current, ac_power, today_gen, total_gen); - if (this->input_power_sensor_ != nullptr) - this->input_power_sensor_->publish_state(input_power); - if (this->pv1_voltage_sensor_ != nullptr) - this->pv1_voltage_sensor_->publish_state(pv1_voltage); - if (this->pv1_current_sensor_ != nullptr) - this->pv1_current_sensor_->publish_state(pv1_current); - if (this->pv1_power_sensor_ != nullptr) - this->pv1_power_sensor_->publish_state(pv1_power); - if (this->pv2_voltage_sensor_ != nullptr) - this->pv2_voltage_sensor_->publish_state(pv2_voltage); - if (this->pv2_current_sensor_ != nullptr) - this->pv2_current_sensor_->publish_state(pv2_current); - if (this->pv2_power_sensor_ != nullptr) - this->pv2_power_sensor_->publish_state(pv2_power); - if (this->output_power_sensor_ != nullptr) - this->output_power_sensor_->publish_state(output_power); - if (this->grid_frequency_sensor_ != nullptr) - this->grid_frequency_sensor_->publish_state(grid_frequency); - if (this->ac_voltage_sensor_ != nullptr) - this->ac_voltage_sensor_->publish_state(ac_voltage); - if (this->ac_current_sensor_ != nullptr) - this->ac_current_sensor_->publish_state(ac_current); - if (this->ac_power_sensor_ != nullptr) - this->ac_power_sensor_->publish_state(ac_power); - if (this->today_gen_sensor_ != nullptr) - this->today_gen_sensor_->publish_state(today_gen); - if (this->total_gen_sensor_ != nullptr) - this->total_gen_sensor_->publish_state(total_gen); - return; - } - if (this->state_ == 2) { - this->state_ = 3; - raw_16 = get_16bit(0); // register 93 - float temperature = raw_16 / 10.0f; - ESP_LOGD(TAG, "DATA: TEMP=%.2f", temperature); - if (this->temperature_sensor_ != nullptr) - this->temperature_sensor_->publish_state(temperature); - return; - } - if (this->state_ == 3) { - this->state_ = 0; - raw_32 = get_32bit(0); // register 1048 - float today_grid = raw_32 / 10.0f; - raw_32 = get_32bit(2); - float total_grid = raw_32 / 10.0f; - ESP_LOGD(TAG, "DATA: TDGE=%.1fkWh TTGE=%.1fkWh", today_grid, total_grid); - if (this->today_grid_sensor_ != nullptr) - this->today_grid_sensor_->publish_state(today_grid); - if (this->total_grid_sensor_ != nullptr) - this->total_grid_sensor_->publish_state(total_grid); - return; - } -} - -void Growatt::loop() { - long now = millis(); - // timeout after 15 seconds - if (this->waiting_ && (now - this->last_send_ > 15000)) { - ESP_LOGW(TAG, "timed out waiting for response"); - this->waiting_ = false; - } - if (this->waiting_ || (this->state_ == 0) || (now - this->last_send_ < 1000)) - return; - this->last_send_ = now; - this->send(CMD_READ_INPUT_REG, REGISTER_START[this->state_ - 1], REGISTER_COUNT[this->state_ - 1]); - this->waiting_ = true; -} - -void Growatt::update() { this->state_ = 1; } - -void Growatt::dump_config() { - ESP_LOGCONFIG(TAG, "Growatt:"); - ESP_LOGCONFIG(TAG, " Address: 0x%02X", this->address_); - LOG_SENSOR("", "Input Power", this->input_power_sensor_); - LOG_SENSOR("", "PV1 Voltage", this->pv1_voltage_sensor_); - LOG_SENSOR("", "PV1 Current", this->pv1_current_sensor_); - LOG_SENSOR("", "PV1 Power", this->pv1_power_sensor_); - LOG_SENSOR("", "PV2 Voltage", this->pv2_voltage_sensor_); - LOG_SENSOR("", "PV2 Current", this->pv2_current_sensor_); - LOG_SENSOR("", "PV2 Power", this->pv2_power_sensor_); - LOG_SENSOR("", "Output Power", this->output_power_sensor_); - LOG_SENSOR("", "Grid Frequency", this->grid_frequency_sensor_); - LOG_SENSOR("", "AC Voltage", this->ac_voltage_sensor_); - LOG_SENSOR("", "AC Current", this->ac_current_sensor_); - LOG_SENSOR("", "AC Power", this->ac_power_sensor_); - LOG_SENSOR("", "Today Generated", this->today_gen_sensor_); - LOG_SENSOR("", "Total Generated", this->total_gen_sensor_); - LOG_SENSOR("", "Temperature", this->temperature_sensor_); - LOG_SENSOR("", "Today to Grid", this->today_grid_sensor_); - LOG_SENSOR("", "Total to Grid", this->total_grid_sensor_); -} - -} // namespace growatt -} // namespace esphome diff --git a/components/growatt/growatt.h b/components/growatt/growatt.h deleted file mode 100644 index 567083b..0000000 --- a/components/growatt/growatt.h +++ /dev/null @@ -1,62 +0,0 @@ -#pragma once - -#include "esphome/core/component.h" -#include "esphome/components/sensor/sensor.h" -#include "esphome/components/modbus/modbus.h" - -namespace esphome { -namespace growatt { - -class Growatt : public PollingComponent, public modbus::ModbusDevice { - public: - void set_input_power_sensor(sensor::Sensor *input_power_sensor) { input_power_sensor_ = input_power_sensor; } - void set_pv1_voltage_sensor(sensor::Sensor *pv1_voltage_sensor) { pv1_voltage_sensor_ = pv1_voltage_sensor; } - void set_pv1_current_sensor(sensor::Sensor *pv1_current_sensor) { pv1_current_sensor_ = pv1_current_sensor; } - void set_pv1_power_sensor(sensor::Sensor *pv1_power_sensor) { pv1_power_sensor_ = pv1_power_sensor; } - void set_pv2_voltage_sensor(sensor::Sensor *pv2_voltage_sensor) { pv2_voltage_sensor_ = pv2_voltage_sensor; } - void set_pv2_current_sensor(sensor::Sensor *pv2_current_sensor) { pv2_current_sensor_ = pv2_current_sensor; } - void set_pv2_power_sensor(sensor::Sensor *pv2_power_sensor) { pv2_power_sensor_ = pv2_power_sensor; } - void set_output_power_sensor(sensor::Sensor *output_power_sensor) { output_power_sensor_ = output_power_sensor; } - void set_grid_frequency_sensor(sensor::Sensor *grid_frequency_sensor) { grid_frequency_sensor_ = grid_frequency_sensor; } - void set_ac_voltage_sensor(sensor::Sensor *ac_voltage_sensor) { ac_voltage_sensor_ = ac_voltage_sensor; } - void set_ac_current_sensor(sensor::Sensor *ac_current_sensor) { ac_current_sensor_ = ac_current_sensor; } - void set_ac_power_sensor(sensor::Sensor *ac_power_sensor) { ac_power_sensor_ = ac_power_sensor; } - void set_today_gen_sensor(sensor::Sensor *today_gen_sensor) { today_gen_sensor_ = today_gen_sensor; } - void set_total_gen_sensor(sensor::Sensor *total_gen_sensor) { total_gen_sensor_ = total_gen_sensor; } - void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; } - void set_today_grid_sensor(sensor::Sensor *today_grid_sensor) { today_grid_sensor_ = today_grid_sensor; } - void set_total_grid_sensor(sensor::Sensor *total_grid_sensor) { total_grid_sensor_ = total_grid_sensor; } - - void loop() override; - void update() override; - - void on_modbus_data(const std::vector &data) override; - - void dump_config() override; - - protected: - int state_{0}; - bool waiting_{false}; - long last_send_{0}; - - sensor::Sensor *input_power_sensor_; - sensor::Sensor *pv1_voltage_sensor_; - sensor::Sensor *pv1_current_sensor_; - sensor::Sensor *pv1_power_sensor_; - sensor::Sensor *pv2_voltage_sensor_; - sensor::Sensor *pv2_current_sensor_; - sensor::Sensor *pv2_power_sensor_; - sensor::Sensor *output_power_sensor_; - sensor::Sensor *grid_frequency_sensor_; - sensor::Sensor *ac_voltage_sensor_; - sensor::Sensor *ac_current_sensor_; - sensor::Sensor *ac_power_sensor_; - sensor::Sensor *today_gen_sensor_; - sensor::Sensor *total_gen_sensor_; - sensor::Sensor *temperature_sensor_; - sensor::Sensor *today_grid_sensor_; - sensor::Sensor *total_grid_sensor_; -}; - -} // namespace growatt -} // namespace esphome diff --git a/components/growatt/sensor.py b/components/growatt/sensor.py deleted file mode 100644 index 4f002da..0000000 --- a/components/growatt/sensor.py +++ /dev/null @@ -1,192 +0,0 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import sensor, modbus -from esphome.const import CONF_ID, UNIT_VOLT, ICON_FLASH, UNIT_AMPERE, UNIT_WATT, \ - ICON_POWER, ICON_CURRENT_AC, UNIT_HERTZ, CONF_TEMPERATURE, ICON_THERMOMETER, UNIT_CELSIUS - -AUTO_LOAD = ['modbus'] - -growatt_ns = cg.esphome_ns.namespace('growatt') -Growatt = growatt_ns.class_('Growatt', cg.PollingComponent, modbus.ModbusDevice) - -CONF_INPUT_POWER = "input_power" -CONF_PV1_VOLTAGE = "pv1_voltage" -CONF_PV1_CURRENT = "pv1_current" -CONF_PV1_POWER = "pv1_power" -CONF_PV2_VOLTAGE = "pv2_voltage" -CONF_PV2_CURRENT = "pv2_current" -CONF_PV2_POWER = "pv2_power" -CONF_OUTPUT_POWER = "output_power" -CONF_GRID_FREQUENCY = "grid_frequency" -CONF_AC_VOLTAGE = "ac_voltage" -CONF_AC_CURRENT = "ac_current" -CONF_AC_POWER = "ac_power" -CONF_TODAY_GEN = "today_gen" -CONF_TOTAL_GEN = "total_gen" -CONF_TODAY_GRID = "today_grid" -CONF_TOTAL_GRID = "total_grid" -UNIT_KILOWATT_HOURS = "kWh" - -CONFIG_SCHEMA = cv.Schema({ - cv.GenerateID(): cv.declare_id(Growatt), - cv.Optional(CONF_INPUT_POWER): sensor.sensor_schema( - unit_of_measurement=UNIT_WATT, - icon=ICON_POWER, - accuracy_decimals=1 - ), - cv.Optional(CONF_PV1_VOLTAGE): sensor.sensor_schema( - unit_of_measurement=UNIT_VOLT, - icon=ICON_FLASH, - accuracy_decimals=1 - ), - cv.Optional(CONF_PV1_CURRENT): sensor.sensor_schema( - unit_of_measurement=UNIT_AMPERE, - icon=ICON_CURRENT_AC, - accuracy_decimals=3 - ), - cv.Optional(CONF_PV1_POWER): sensor.sensor_schema( - unit_of_measurement=UNIT_WATT, - icon=ICON_POWER, - accuracy_decimals=1 - ), - cv.Optional(CONF_PV2_VOLTAGE): sensor.sensor_schema( - unit_of_measurement=UNIT_VOLT, - icon=ICON_FLASH, - accuracy_decimals=1 - ), - cv.Optional(CONF_PV2_CURRENT): sensor.sensor_schema( - unit_of_measurement=UNIT_AMPERE, - icon=ICON_CURRENT_AC, - accuracy_decimals=3 - ), - cv.Optional(CONF_PV2_POWER): sensor.sensor_schema( - unit_of_measurement=UNIT_WATT, - icon=ICON_POWER, - accuracy_decimals=1 - ), - cv.Optional(CONF_OUTPUT_POWER): sensor.sensor_schema( - unit_of_measurement=UNIT_WATT, - icon=ICON_POWER, - accuracy_decimals=1 - ), - cv.Optional(CONF_GRID_FREQUENCY): sensor.sensor_schema( - unit_of_measurement=UNIT_HERTZ, - icon=ICON_CURRENT_AC, - accuracy_decimals=1 - ), - cv.Optional(CONF_AC_VOLTAGE): sensor.sensor_schema( - unit_of_measurement=UNIT_VOLT, - icon=ICON_FLASH, - accuracy_decimals=1 - ), - cv.Optional(CONF_AC_CURRENT): sensor.sensor_schema( - unit_of_measurement=UNIT_AMPERE, - icon=ICON_CURRENT_AC, - accuracy_decimals=3 - ), - cv.Optional(CONF_AC_POWER): sensor.sensor_schema( - unit_of_measurement=UNIT_WATT, - icon=ICON_POWER, - accuracy_decimals=1 - ), - cv.Optional(CONF_TODAY_GEN): sensor.sensor_schema( - unit_of_measurement=UNIT_KILOWATT_HOURS, - icon=ICON_POWER, - accuracy_decimals=1 - ), - cv.Optional(CONF_TOTAL_GEN): sensor.sensor_schema( - unit_of_measurement=UNIT_KILOWATT_HOURS, - icon=ICON_POWER, - accuracy_decimals=1 - ), - cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1 - ), - cv.Optional(CONF_TODAY_GRID): sensor.sensor_schema( - unit_of_measurement=UNIT_KILOWATT_HOURS, - icon=ICON_POWER, - accuracy_decimals=1 - ), - cv.Optional(CONF_TOTAL_GRID): sensor.sensor_schema( - unit_of_measurement=UNIT_KILOWATT_HOURS, - icon=ICON_POWER, - accuracy_decimals=1 - ), -}).extend(cv.polling_component_schema('60s')).extend(modbus.modbus_device_schema(0x01)) - - -async def to_code(config): - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - await modbus.register_modbus_device(var, config) - - if CONF_INPUT_POWER in config: - conf = config[CONF_INPUT_POWER] - sens = await sensor.new_sensor(conf) - cg.add(var.set_input_power_sensor(sens)) - if CONF_PV1_VOLTAGE in config: - conf = config[CONF_PV1_VOLTAGE] - sens = await sensor.new_sensor(conf) - cg.add(var.set_pv1_voltage_sensor(sens)) - if CONF_PV1_CURRENT in config: - conf = config[CONF_PV1_CURRENT] - sens = await sensor.new_sensor(conf) - cg.add(var.set_pv1_current_sensor(sens)) - if CONF_PV1_POWER in config: - conf = config[CONF_PV1_POWER] - sens = await sensor.new_sensor(conf) - cg.add(var.set_pv1_power_sensor(sens)) - if CONF_PV2_VOLTAGE in config: - conf = config[CONF_PV2_VOLTAGE] - sens = await sensor.new_sensor(conf) - cg.add(var.set_pv2_voltage_sensor(sens)) - if CONF_PV2_CURRENT in config: - conf = config[CONF_PV2_CURRENT] - sens = await sensor.new_sensor(conf) - cg.add(var.set_pv2_current_sensor(sens)) - if CONF_PV2_POWER in config: - conf = config[CONF_PV2_POWER] - sens = await sensor.new_sensor(conf) - cg.add(var.set_pv2_power_sensor(sens)) - if CONF_OUTPUT_POWER in config: - conf = config[CONF_OUTPUT_POWER] - sens = await sensor.new_sensor(conf) - cg.add(var.set_output_power_sensor(sens)) - if CONF_GRID_FREQUENCY in config: - conf = config[CONF_GRID_FREQUENCY] - sens = await sensor.new_sensor(conf) - cg.add(var.set_grid_frequency_sensor(sens)) - if CONF_AC_VOLTAGE in config: - conf = config[CONF_AC_VOLTAGE] - sens = await sensor.new_sensor(conf) - cg.add(var.set_ac_voltage_sensor(sens)) - if CONF_AC_CURRENT in config: - conf = config[CONF_AC_CURRENT] - sens = await sensor.new_sensor(conf) - cg.add(var.set_ac_current_sensor(sens)) - if CONF_AC_POWER in config: - conf = config[CONF_AC_POWER] - sens = await sensor.new_sensor(conf) - cg.add(var.set_ac_power_sensor(sens)) - if CONF_TODAY_GEN in config: - conf = config[CONF_TODAY_GEN] - sens = await sensor.new_sensor(conf) - cg.add(var.set_today_gen_sensor(sens)) - if CONF_TOTAL_GEN in config: - conf = config[CONF_TOTAL_GEN] - sens = await sensor.new_sensor(conf) - cg.add(var.set_total_gen_sensor(sens)) - if CONF_TEMPERATURE in config: - conf = config[CONF_TEMPERATURE] - sens = await sensor.new_sensor(conf) - cg.add(var.set_temperature_sensor(sens)) - if CONF_TODAY_GRID in config: - conf = config[CONF_TODAY_GRID] - sens = await sensor.new_sensor(conf) - cg.add(var.set_today_grid_sensor(sens)) - if CONF_TOTAL_GRID in config: - conf = config[CONF_TOTAL_GRID] - sens = await sensor.new_sensor(conf) - cg.add(var.set_total_grid_sensor(sens)) diff --git a/components/key_collector/README.md b/components/key_collector/README.md deleted file mode 100644 index ad136b8..0000000 --- a/components/key_collector/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# This component has been merged to esphome: - -# key_collector component - -This component collects key presses from a `key_provider` like the `matrix_keypad` or `wiegand` components. - -You need at least one of the `end_keys` or `max_length` parameters. The rest are optional. -There is a `clear()` method with an optional `bool` (default true) parameter for whether or not to trigger the progress action. - -Example: -```yaml -key_collector: - - id: pin_reader - source_id: mykeypad - min_length: 4 - max_length: 4 - start_keys: "A" - end_keys: "#" - end_key_required: true # default is false - back_keys: "*" - clear_keys: "C" - timeout: 5s - allowed_keys: "0123456789" # if not included, then any otherwise unused keys will be allowed - on_progress: - - logger.log: - format: "input progress: '%s', started by '%c'" - args: [ 'x.c_str()', 'start' ] - on_result: - - logger.log: - format: "input result: '%s', started by '%c', ended by '%c'" - args: [ 'x.c_str()', 'start', 'end' ] -``` - diff --git a/components/key_collector/__init__.py b/components/key_collector/__init__.py deleted file mode 100644 index e8ec9ec..0000000 --- a/components/key_collector/__init__.py +++ /dev/null @@ -1,71 +0,0 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome import automation -from esphome.components import key_provider -from esphome.const import CONF_ID, CONF_MAX_LENGTH, CONF_MIN_LENGTH, CONF_SOURCE_ID, CONF_TIMEOUT - -CONF_START_KEYS = 'start_keys' -CONF_END_KEYS = 'end_keys' -CONF_END_KEY_REQUIRED = 'end_key_required' -CONF_BACK_KEYS = 'back_keys' -CONF_CLEAR_KEYS = 'clear_keys' -CONF_ALLOWED_KEYS = 'allowed_keys' -CONF_ON_PROGRESS = 'on_progress' -CONF_ON_RESULT = 'on_result' - -AUTO_LOAD = ['key_provider'] - -MULTI_CONF = True - -key_collector_ns = cg.esphome_ns.namespace('key_collector') -KeyCollector = key_collector_ns.class_('KeyCollector', cg.Component) - -CONFIG_SCHEMA = cv.All(cv.COMPONENT_SCHEMA.extend({ - cv.GenerateID(): cv.declare_id(KeyCollector), - cv.GenerateID(CONF_SOURCE_ID): cv.use_id(key_provider.KeyProvider), - cv.Optional(CONF_MIN_LENGTH): cv.int_, - cv.Optional(CONF_MAX_LENGTH): cv.int_, - cv.Optional(CONF_START_KEYS): cv.string, - cv.Optional(CONF_END_KEYS): cv.string, - cv.Optional(CONF_END_KEY_REQUIRED): cv.boolean, - cv.Optional(CONF_BACK_KEYS): cv.string, - cv.Optional(CONF_CLEAR_KEYS): cv.string, - cv.Optional(CONF_ALLOWED_KEYS): cv.string, - cv.Optional(CONF_ON_PROGRESS): automation.validate_automation(single=True), - cv.Optional(CONF_ON_RESULT): automation.validate_automation(single=True), - cv.Optional(CONF_TIMEOUT): cv.positive_time_period_milliseconds, -}), cv.has_at_least_one_key(CONF_END_KEYS, CONF_MAX_LENGTH)) - - -async def to_code(config): - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - source = await cg.get_variable(config[CONF_SOURCE_ID]) - cg.add(var.set_provider(source)) - if CONF_MIN_LENGTH in config: - cg.add(var.set_min_length(config[CONF_MIN_LENGTH])) - if CONF_MAX_LENGTH in config: - cg.add(var.set_max_length(config[CONF_MAX_LENGTH])) - if CONF_START_KEYS in config: - cg.add(var.set_start_keys(config[CONF_START_KEYS])) - if CONF_END_KEYS in config: - cg.add(var.set_end_keys(config[CONF_END_KEYS])) - if CONF_END_KEY_REQUIRED in config: - cg.add(var.set_end_key_required(config[CONF_END_KEY_REQUIRED])) - if CONF_BACK_KEYS in config: - cg.add(var.set_back_keys(config[CONF_BACK_KEYS])) - if CONF_CLEAR_KEYS in config: - cg.add(var.set_clear_keys(config[CONF_CLEAR_KEYS])) - if CONF_ALLOWED_KEYS in config: - cg.add(var.set_allowed_keys(config[CONF_ALLOWED_KEYS])) - if CONF_ON_PROGRESS in config: - await automation.build_automation(var.get_progress_trigger(), - [(cg.std_string, 'x'), (cg.uint8, 'start')], - config[CONF_ON_PROGRESS]) - if CONF_ON_RESULT in config: - await automation.build_automation(var.get_result_trigger(), - [(cg.std_string, 'x'), (cg.uint8, 'start'), (cg.uint8, 'end')], - config[CONF_ON_RESULT]) - if CONF_TIMEOUT in config: - cg.add(var.set_timeout(config[CONF_TIMEOUT])) - diff --git a/components/key_collector/key_collector.cpp b/components/key_collector/key_collector.cpp deleted file mode 100644 index 09af3b6..0000000 --- a/components/key_collector/key_collector.cpp +++ /dev/null @@ -1,94 +0,0 @@ -#include "key_collector.h" -#include "esphome/core/hal.h" -#include "esphome/core/log.h" - -namespace esphome { -namespace key_collector { - -static const char *const TAG = "key_collector"; - -KeyCollector::KeyCollector() : progress_trigger_(new Trigger()), result_trigger_(new Trigger()) {} - -void KeyCollector::loop() { - if ((this->timeout_ == 0) || (this->result_.size() == 0) || (millis() - this->last_key_time_ < this->timeout_)) - return; - this->clear(); -} - -void KeyCollector::dump_config() { - ESP_LOGCONFIG(TAG, "Key Collector:"); - if (this->min_length_ > 0) - ESP_LOGCONFIG(TAG, " min length: %d", this->min_length_); - if (this->max_length_ > 0) - ESP_LOGCONFIG(TAG, " max length: %d", this->max_length_); - if (!this->back_keys_.empty()) - ESP_LOGCONFIG(TAG, " erase keys '%s'", this->back_keys_.c_str()); - if (!this->clear_keys_.empty()) - ESP_LOGCONFIG(TAG, " clear keys '%s'", this->clear_keys_.c_str()); - if (!this->start_keys_.empty()) - ESP_LOGCONFIG(TAG, " start keys '%s'", this->start_keys_.c_str()); - if (!this->end_keys_.empty()) { - ESP_LOGCONFIG(TAG, " end keys '%s'", this->end_keys_.c_str()); - ESP_LOGCONFIG(TAG, " end key is required: %s", ONOFF(this->end_key_required_)); - } - if (!this->allowed_keys_.empty()) - ESP_LOGCONFIG(TAG, " allowed keys '%s'", this->allowed_keys_.c_str()); - if (this->timeout_ > 0) - ESP_LOGCONFIG(TAG, " entry timeout: %0.1f", this->timeout_ / 1000.0); -} - -void KeyCollector::set_provider(key_provider::KeyProvider *provider) { - provider->add_on_key_callback([this](uint8_t key) { - this->key_pressed_(key); - }); -} - -void KeyCollector::clear(bool progress_update) { - this->result_.clear(); - this->start_key_ = 0; - if (progress_update) - this->progress_trigger_->trigger(this->result_, 0); -} - -void KeyCollector::key_pressed_(uint8_t key) { - this->last_key_time_ = millis(); - if (!this->start_keys_.empty() && !this->start_key_) { - if (this->start_keys_.find(key) != std::string::npos) { - this->start_key_ = key; - this->progress_trigger_->trigger(this->result_, this->start_key_); - } - return; - } - if (this->back_keys_.find(key) != std::string::npos) { - if (!this->result_.empty()) { - this->result_.pop_back(); - this->progress_trigger_->trigger(this->result_, this->start_key_); - } - return; - } - if (this->clear_keys_.find(key) != std::string::npos) { - if (!this->result_.empty()) - this->clear(); - return; - } - if (this->end_keys_.find(key) != std::string::npos) { - if ((this->min_length_ == 0) || (this->result_.size() >= this->min_length_)) { - this->result_trigger_->trigger(this->result_, this->start_key_, key); - this->clear(); - } - return; - } - if (!this->allowed_keys_.empty() && (this->allowed_keys_.find(key) == std::string::npos)) - return; - if ((this->max_length_ == 0) || (this->result_.size() < this->max_length_)) - this->result_.push_back(key); - if ((this->max_length_ > 0) && (this->result_.size() == this->max_length_) && (!this->end_key_required_)) { - this->result_trigger_->trigger(this->result_, this->start_key_, 0); - this->clear(false); - } - this->progress_trigger_->trigger(this->result_, this->start_key_); -} - -} // namespace key_collector -} // namespace esphome - diff --git a/components/key_collector/key_collector.h b/components/key_collector/key_collector.h deleted file mode 100644 index 9b9f5ec..0000000 --- a/components/key_collector/key_collector.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include "esphome/components/key_provider/key_provider.h" -#include "esphome/core/automation.h" - -namespace esphome { -namespace key_collector { - -class KeyCollector : public Component { - public: - KeyCollector(); - void loop() override; - void dump_config() override; - void set_provider(key_provider::KeyProvider *provider); - void set_min_length(int min_length) { this->min_length_ = min_length; }; - void set_max_length(int max_length) { this->max_length_ = max_length; }; - void set_start_keys(std::string start_keys) { this->start_keys_ = start_keys; }; - void set_end_keys(std::string end_keys) { this->end_keys_ = end_keys; }; - void set_end_key_required(bool end_key_required) { this->end_key_required_ = end_key_required; }; - void set_back_keys(std::string back_keys) { this->back_keys_ = back_keys; }; - void set_clear_keys(std::string clear_keys) { this->clear_keys_ = clear_keys; }; - void set_allowed_keys(std::string allowed_keys) { this->allowed_keys_ = allowed_keys; }; - Trigger *get_progress_trigger() const { return this->progress_trigger_; }; - Trigger *get_result_trigger() const { return this->result_trigger_; }; - void set_timeout(int timeout) { this->timeout_ = timeout; }; - - void clear(bool progress_update = true); - - protected: - void key_pressed_(uint8_t key); - - int min_length_{0}; - int max_length_{0}; - std::string start_keys_; - std::string end_keys_; - bool end_key_required_{false}; - std::string back_keys_; - std::string clear_keys_; - std::string allowed_keys_; - std::string result_; - uint8_t start_key_{0}; - Trigger *progress_trigger_; - Trigger *result_trigger_; - uint32_t last_key_time_; - uint32_t timeout_{0}; -}; - -} // namespace key_collector -} // namespace esphome - diff --git a/components/key_provider/README.md b/components/key_provider/README.md deleted file mode 100644 index 9219ea9..0000000 --- a/components/key_provider/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# This component has been merged to esphome. - -# key_provider component - -This is an internal component required by any component that can provide key presses for the `key_collector`. diff --git a/components/key_provider/__init__.py b/components/key_provider/__init__.py deleted file mode 100644 index 39538e6..0000000 --- a/components/key_provider/__init__.py +++ /dev/null @@ -1,4 +0,0 @@ -import esphome.codegen as cg - -key_provider_ns = cg.esphome_ns.namespace("key_provider") -KeyProvider = key_provider_ns.class_("KeyProvider") diff --git a/components/key_provider/key_provider.cpp b/components/key_provider/key_provider.cpp deleted file mode 100644 index 244707b..0000000 --- a/components/key_provider/key_provider.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "key_provider.h" - -namespace esphome { -namespace key_provider { - -void KeyProvider::add_on_key_callback(std::function &&callback) { - this->key_callback_.add(std::move(callback)); -} - -void KeyProvider::send_key_(uint8_t key) { - this->key_callback_.call(key); -} - -} // namespace key_provider -} // namespace esphome diff --git a/components/key_provider/key_provider.h b/components/key_provider/key_provider.h deleted file mode 100644 index 272d3ee..0000000 --- a/components/key_provider/key_provider.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "esphome/core/automation.h" -#include "esphome/core/component.h" - -namespace esphome { -namespace key_provider { - -/// interface for components that provide keypresses -class KeyProvider { - public: - void add_on_key_callback(std::function &&callback); - - protected: - void send_key_(uint8_t key); - - CallbackManager key_callback_{}; -}; - -} // namespace key_provider -} // namespace esphome diff --git a/components/keypad/README.md b/components/keypad/README.md deleted file mode 100644 index f933d39..0000000 --- a/components/keypad/README.md +++ /dev/null @@ -1 +0,0 @@ -# the `keypad` component has been renamed to `matrix_keypad` diff --git a/components/kuntze/README.md b/components/kuntze/README.md deleted file mode 100644 index f70ca02..0000000 --- a/components/kuntze/README.md +++ /dev/null @@ -1,25 +0,0 @@ -# Kuntze pool monitor modbus interface - -A configured uart component is required. -A configured modbus component is usually optional. It will be automatically created. - -Example: -```yaml -sensor: - - platform: kuntze - id: my_kuntze - ph: - id: ph - temperature: - id: temperature -``` - -All sensors are optional. The available sensors are: -- `ph` -- `temperature` -- `dis1` -- `dis2` -- `redox` -- `ec` -- `oci` - diff --git a/components/kuntze/__init__.py b/components/kuntze/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/components/kuntze/kuntze.cpp b/components/kuntze/kuntze.cpp deleted file mode 100644 index b90c4e7..0000000 --- a/components/kuntze/kuntze.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include "kuntze.h" -#include "esphome/core/log.h" - -namespace esphome { -namespace kuntze { - -static const char *TAG = "kuntze"; - -static const uint8_t CMD_READ_REG = 0x03; -static const uint16_t REGISTER[] = {4136, 4160, 4680, 6000, 4688, 4728, 5832}; - -void Kuntze::on_modbus_data(const std::vector &data) { - auto get_16bit = [&](int i) -> uint16_t { - return (uint16_t(data[i * 2]) << 8) | uint16_t(data[i * 2 + 1]); - }; - - waiting_ = false; - ESP_LOGD(TAG, "Packet size is %d", data.size()); - //if (data.size() != 4) { - // ESP_LOGW(TAG, "Invalid data packet size (%d) for state %d", data.size(), state_); - // return; - //} - ESP_LOGVV(TAG, "Data: %s", hexencode(data).c_str()); - - float value = (float)get_16bit(0); - for (int i = 0; i < data[3]; i++) - value /= 10.0; - ESP_LOGD(TAG, "%d decimals", data[3]); - switch (state_) { - case 1: - ESP_LOGD(TAG, "pH=%.1f", value); - if (ph_sensor_ != nullptr) - ph_sensor_->publish_state(value); - break; - case 2: - ESP_LOGD(TAG, "temperature=%.1f", value); - if (temperature_sensor_ != nullptr) - temperature_sensor_->publish_state(value); - break; - case 3: - ESP_LOGD(TAG, "DIS1=%.1f", value); - if (dis1_sensor_ != nullptr) - dis1_sensor_->publish_state(value); - break; - case 4: - ESP_LOGD(TAG, "DIS2=%.1f", value); - if (dis2_sensor_ != nullptr) - dis2_sensor_->publish_state(value); - break; - case 5: - ESP_LOGD(TAG, "REDOX=%.1f", value); - if (redox_sensor_ != nullptr) - redox_sensor_->publish_state(value); - break; - case 6: - ESP_LOGD(TAG, "EC=%.1f", value); - if (ec_sensor_ != nullptr) - ec_sensor_->publish_state(value); - break; - case 7: - ESP_LOGD(TAG, "OCI=%.1f", value); - if (oci_sensor_ != nullptr) - oci_sensor_->publish_state(value); - break; - } - if (++state_ > 7) - state_ = 0; -} - -void Kuntze::loop() { - long now = millis(); - // timeout after 15 seconds - if (waiting_ && (now - last_send_ > 15000)) { - ESP_LOGW(TAG, "timed out waiting for response"); - waiting_ = false; - } - if (waiting_ || (state_ == 0)) - return; - last_send_ = now; - send(CMD_READ_REG, REGISTER[state_ - 1], 2); - waiting_ = true; -} - -void Kuntze::update() { state_ = 1; } - -void Kuntze::dump_config() { - ESP_LOGCONFIG(TAG, "Kuntze:"); - ESP_LOGCONFIG(TAG, " Address: 0x%02X", address_); - LOG_SENSOR("", "pH", ph_sensor_); - LOG_SENSOR("", "temperature", temperature_sensor_); - LOG_SENSOR("", "DIS1", dis1_sensor_); - LOG_SENSOR("", "DIS2", dis2_sensor_); - LOG_SENSOR("", "REDOX", redox_sensor_); - LOG_SENSOR("", "EC", ec_sensor_); - LOG_SENSOR("", "OCI", oci_sensor_); -} - -} // namespace kuntze -} // namespace esphome diff --git a/components/kuntze/kuntze.h b/components/kuntze/kuntze.h deleted file mode 100644 index 0cd418f..0000000 --- a/components/kuntze/kuntze.h +++ /dev/null @@ -1,42 +0,0 @@ -#pragma once - -#include "esphome/core/component.h" -#include "esphome/components/sensor/sensor.h" -#include "esphome/components/modbus/modbus.h" - -namespace esphome { -namespace kuntze { - -class Kuntze : public PollingComponent, public modbus::ModbusDevice { - public: - void set_ph_sensor(sensor::Sensor *ph_sensor) { ph_sensor_ = ph_sensor; } - void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; } - void set_dis1_sensor(sensor::Sensor *dis1_sensor) { dis1_sensor_ = dis1_sensor; } - void set_dis2_sensor(sensor::Sensor *dis2_sensor) { dis2_sensor_ = dis2_sensor; } - void set_redox_sensor(sensor::Sensor *redox_sensor) { redox_sensor_ = redox_sensor; } - void set_ec_sensor(sensor::Sensor *ec_sensor) { ec_sensor_ = ec_sensor; } - void set_oci_sensor(sensor::Sensor *oci_sensor) { oci_sensor_ = oci_sensor; } - - void loop() override; - void update() override; - - void on_modbus_data(const std::vector &data) override; - - void dump_config() override; - - protected: - int state_{0}; - bool waiting_{false}; - long last_send_{0}; - - sensor::Sensor *ph_sensor_; - sensor::Sensor *temperature_sensor_; - sensor::Sensor *dis1_sensor_; - sensor::Sensor *dis2_sensor_; - sensor::Sensor *redox_sensor_; - sensor::Sensor *ec_sensor_; - sensor::Sensor *oci_sensor_; -}; - -} // namespace kuntze -} // namespace esphome diff --git a/components/kuntze/sensor.py b/components/kuntze/sensor.py deleted file mode 100644 index c7f90e4..0000000 --- a/components/kuntze/sensor.py +++ /dev/null @@ -1,97 +0,0 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import sensor, modbus -from esphome.const import CONF_ID, UNIT_EMPTY, ICON_EMPTY, DEVICE_CLASS_EMPTY, CONF_TEMPERATURE, ICON_THERMOMETER, UNIT_CELSIUS, DEVICE_CLASS_TEMPERATURE - -AUTO_LOAD = ['modbus'] - -kuntze_ns = cg.esphome_ns.namespace('kuntze') -Kuntze = kuntze_ns.class_('Kuntze', cg.PollingComponent, modbus.ModbusDevice) - -CONF_PH = "ph" -CONF_DIS1 = "dis1" -CONF_DIS2 = "dis2" -CONF_REDOX = "redox" -CONF_EC = "ec" -CONF_OCI = "oci" - -CONFIG_SCHEMA = cv.Schema({ - cv.GenerateID(): cv.declare_id(Kuntze), - cv.Optional(CONF_PH): sensor.sensor_schema( - unit_of_measurement=UNIT_EMPTY, - icon=ICON_EMPTY, - accuracy_decimals=1, - device_class=DEVICE_CLASS_EMPTY - ), - cv.Optional(CONF_TEMPERATURE): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE - ), - cv.Optional(CONF_DIS1): sensor.sensor_schema( - unit_of_measurement=UNIT_EMPTY, - icon=ICON_EMPTY, - accuracy_decimals=1, - device_class=DEVICE_CLASS_EMPTY - ), - cv.Optional(CONF_DIS2): sensor.sensor_schema( - unit_of_measurement=UNIT_EMPTY, - icon=ICON_EMPTY, - accuracy_decimals=1, - device_class=DEVICE_CLASS_EMPTY - ), - cv.Optional(CONF_REDOX): sensor.sensor_schema( - unit_of_measurement=UNIT_EMPTY, - icon=ICON_EMPTY, - accuracy_decimals=1, - device_class=DEVICE_CLASS_EMPTY - ), - cv.Optional(CONF_EC): sensor.sensor_schema( - unit_of_measurement=UNIT_EMPTY, - icon=ICON_EMPTY, - accuracy_decimals=1, - device_class=DEVICE_CLASS_EMPTY - ), - cv.Optional(CONF_OCI): sensor.sensor_schema( - unit_of_measurement=UNIT_EMPTY, - icon=ICON_EMPTY, - accuracy_decimals=1, - device_class=DEVICE_CLASS_EMPTY - ), -}).extend(cv.polling_component_schema('60s')).extend(modbus.modbus_device_schema(0x01)) - - -async def to_code(config): - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - await modbus.register_modbus_device(var, config) - - if CONF_PH in config: - conf = config[CONF_PH] - sens = await sensor.new_sensor(conf) - cg.add(var.set_ph_sensor(sens)) - if CONF_TEMPERATURE in config: - conf = config[CONF_TEMPERATURE] - sens = await sensor.new_sensor(conf) - cg.add(var.set_temperature_sensor(sens)) - if CONF_DIS1 in config: - conf = config[CONF_DIS1] - sens = await sensor.new_sensor(conf) - cg.add(var.set_dis1_sensor(sens)) - if CONF_DIS2 in config: - conf = config[CONF_DIS2] - sens = await sensor.new_sensor(conf) - cg.add(var.set_dis2_sensor(sens)) - if CONF_REDOX in config: - conf = config[CONF_REDOX] - sens = await sensor.new_sensor(conf) - cg.add(var.set_redox_sensor(sens)) - if CONF_EC in config: - conf = config[CONF_EC] - sens = await sensor.new_sensor(conf) - cg.add(var.set_ec_sensor(sens)) - if CONF_OCI in config: - conf = config[CONF_OCI] - sens = await sensor.new_sensor(conf) - cg.add(var.set_oci_sensor(sens)) diff --git a/components/matrix_keypad/README.md b/components/matrix_keypad/README.md deleted file mode 100644 index 88c4e29..0000000 --- a/components/matrix_keypad/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# This component has been merged to esphome: - -# keypad component - -This component is for matrix keypads. Define a `keypad` component then add `binary_sensor`s to handle individual keys. You need to also import the `key_provider` component. -If you want automatic handling for multiple keys, e.g. PIN entry, use the `key_collector` component. - -The `keys` parameter is optional for the `keypad`, but then you won't be able to check for it in the `binary_sensor` -and the `input_builder` won't work if you want to use that. -The optional `has_diodes` parameter is for if the buttons have diodes and the row pins are output only. In that case, set it to true. - -For the `binary_sensor`, you need to provide either the `row` and `col` parameters or the `key` parameter. - -Example: -```yaml -keypad: - id: mykeypad - rows: - - pin: 21 - - pin: 19 - - pin: 18 - - pin: 5 - columns: - - pin: 17 - - pin: 16 - - pin: 4 - - pin: 15 - keys: "123A456B789C*0#D" - has_diodes: false - -binary_sensor: - - platform: keypad - keypad_id: mykeypad - id: key4 - row: 1 - col: 0 - - platform: keypad - id: keyA - key: A -``` - diff --git a/components/matrix_keypad/__init__.py b/components/matrix_keypad/__init__.py deleted file mode 100644 index 1c86505..0000000 --- a/components/matrix_keypad/__init__.py +++ /dev/null @@ -1,59 +0,0 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome import core, pins, automation -from esphome.automation import maybe_simple_id -from esphome.components import key_provider -from esphome.const import CONF_ID, CONF_PIN, CONF_LAMBDA - -AUTO_LOAD = [ "key_provider" ] - -MULTI_CONF = True - -keypad_ns = cg.esphome_ns.namespace('keypad') -Keypad = keypad_ns.class_('Keypad', key_provider.KeyProvider, cg.Component) - -CONF_KEYPAD_ID = 'keypad_id' -CONF_ROWS = 'rows' -CONF_COLUMNS = 'columns' -CONF_KEYS = 'keys' -CONF_DEBOUNCE_TIME = 'debounce_time' -CONF_HAS_DIODES = 'has_diodes' - -def check_keys(obj): - if CONF_KEYS in obj: - if len(obj[CONF_KEYS]) != len(obj[CONF_ROWS]) * len(obj[CONF_COLUMNS]): - raise cv.Invalid("The number of key codes must equal the number of buttons") - return obj - -CONFIG_SCHEMA = cv.All(cv.COMPONENT_SCHEMA.extend({ - cv.GenerateID(): cv.declare_id(Keypad), - cv.Required(CONF_ROWS): cv.All(cv.ensure_list({ - cv.Required(CONF_PIN): pins.gpio_output_pin_schema - }), cv.Length(min=1)), - cv.Required(CONF_COLUMNS): cv.All(cv.ensure_list({ - cv.Required(CONF_PIN): pins.gpio_input_pin_schema - }), cv.Length(min=1)), - cv.Optional(CONF_KEYS): cv.string, - cv.Optional(CONF_DEBOUNCE_TIME, default=1): cv.int_range(min=1, max=100), - cv.Optional(CONF_HAS_DIODES): cv.boolean, -}), check_keys) - -async def to_code(config): - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - pins = [] - for conf in config[CONF_ROWS]: - pin = await cg.gpio_pin_expression(conf[CONF_PIN]) - pins.append(pin) - cg.add(var.set_rows(pins)) - pins = [] - for conf in config[CONF_COLUMNS]: - pin = await cg.gpio_pin_expression(conf[CONF_PIN]) - pins.append(pin) - cg.add(var.set_columns(pins)) - if CONF_KEYS in config: - cg.add(var.set_keys(config[CONF_KEYS])) - cg.add(var.set_debounce_time(config[CONF_DEBOUNCE_TIME])) - if CONF_HAS_DIODES in config: - cg.add(var.set_has_diodes(config[CONF_HAS_DIODES])) - diff --git a/components/matrix_keypad/binary_sensor/__init__.py b/components/matrix_keypad/binary_sensor/__init__.py deleted file mode 100644 index bae83dd..0000000 --- a/components/matrix_keypad/binary_sensor/__init__.py +++ /dev/null @@ -1,45 +0,0 @@ -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 Keypad, keypad_ns, CONF_KEYPAD_ID - -CONF_KEY = 'key' -CONF_ROW = 'row' -CONF_COL = 'col' - -DEPENDENCIES = ['matrix_keypad'] - -KeypadBinarySensor = keypad_ns.class_('KeypadBinarySensor', binary_sensor.BinarySensor) - -def check_button(obj): - if CONF_ROW in obj or CONF_COL in obj: - if CONF_KEY in obj: - raise cv.Invalid("You can't provide both a key and a position") - elif CONF_ROW not in obj: - raise cv.Invalid("Missing row") - elif CONF_COL not in obj: - raise cv.Invalid("Missing col") - elif CONF_KEY not in obj: - raise cv.Invalid("Missing key or position") - elif len(obj[CONF_KEY]) != 1: - raise cv.Invalid("Key must be one character") - return obj - -CONFIG_SCHEMA = cv.All(binary_sensor.BINARY_SENSOR_SCHEMA.extend({ - cv.GenerateID(): cv.declare_id(KeypadBinarySensor), - cv.GenerateID(CONF_KEYPAD_ID): cv.use_id(Keypad), - cv.Optional(CONF_ROW): cv.int_, - cv.Optional(CONF_COL): cv.int_, - cv.Optional(CONF_KEY): cv.string, -}), check_button) - - -async def to_code(config): - if CONF_KEY in config: - var = cg.new_Pvariable(config[CONF_ID], config[CONF_KEY][0]) - else: - var = cg.new_Pvariable(config[CONF_ID], config[CONF_ROW], config[CONF_COL]) - await binary_sensor.register_binary_sensor(var, config) - keypad = await cg.get_variable(config[CONF_KEYPAD_ID]) - cg.add(keypad.register_listener(var)) diff --git a/components/matrix_keypad/binary_sensor/keypad_binary_sensor.h b/components/matrix_keypad/binary_sensor/keypad_binary_sensor.h deleted file mode 100644 index 06e26ad..0000000 --- a/components/matrix_keypad/binary_sensor/keypad_binary_sensor.h +++ /dev/null @@ -1,51 +0,0 @@ -#pragma once - -#include "esphome/components/matrix_keypad/keypad.h" -#include "esphome/components/binary_sensor/binary_sensor.h" - -namespace esphome { -namespace keypad { - -class KeypadBinarySensor : public KeypadListener, public binary_sensor::BinarySensor { - public: - KeypadBinarySensor(uint8_t key) : has_key_(true), key_(key) {}; - KeypadBinarySensor(const char *key) : has_key_(true), key_((uint8_t)key[0]) {}; - KeypadBinarySensor(int row, int col) : has_key_(false), row_(row), col_(col) {}; - - void key_pressed(uint8_t key) override { - if (!this->has_key_) - return; - if (key == this->key_) - this->publish_state(true); - } - - void key_released(uint8_t key) override { - if (!this->has_key_) - return; - if (key == this->key_) - this->publish_state(false); - } - - void button_pressed(int row, int col) override { - if (this->has_key_) - return; - if ((row == this->row_) && (col == this->col_)) - this->publish_state(true); - } - - void button_released(int row, int col) override { - if (this->has_key_) - return; - if ((row == this->row_) && (col == this->col_)) - this->publish_state(false); - } - - protected: - bool has_key_; - uint8_t key_; - int row_; - int col_; -}; - -} // namespace keypad -} // namespace esphome diff --git a/components/matrix_keypad/keypad.cpp b/components/matrix_keypad/keypad.cpp deleted file mode 100644 index f5ba6a8..0000000 --- a/components/matrix_keypad/keypad.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "keypad.h" -#include "esphome/core/log.h" - -namespace esphome { -namespace keypad { - -static const char *TAG = "keypad"; - -void Keypad::setup() { - for (auto *pin : this->rows_) - if (!has_diodes_) - pin->pin_mode(gpio::FLAG_INPUT); - else - pin->digital_write(true); - for (auto *pin : this->columns_) - pin->pin_mode(gpio::FLAG_INPUT | gpio::FLAG_PULLUP); -} - -void Keypad::loop() { - static unsigned long active_start = 0; - static int active_key = -1; - unsigned long now = millis(); - int key = -1; - bool error = false; - int pos = 0, row, col; - for (auto *row : this->rows_) { - if (!has_diodes_) - row->pin_mode(gpio::FLAG_OUTPUT); - row->digital_write(false); - for (auto *col : this->columns_) { - if (!col->digital_read()) { - if (key != -1) - error = true; - else - key = pos; - } - pos++; - } - row->digital_write(true); - if (!has_diodes_) - row->pin_mode(gpio::FLAG_INPUT); - } - if (error) - return; - - if (key != active_key) { - if ((active_key != -1) && (this->pressed_key_ == active_key)) { - row = this->pressed_key_ / this->columns_.size(); - col = this->pressed_key_ % this->columns_.size(); - ESP_LOGD(TAG, "key @ row %d, col %d released", row, col); - for (auto &listener : this->listeners_) - listener->button_released(row, col); - if (this->keys_.size()) { - uint8_t keycode = this->keys_[this->pressed_key_]; - ESP_LOGD(TAG, "key '%c' released", keycode); - for (auto &listener : this->listeners_) - listener->key_released(keycode); - } - this->pressed_key_ = -1; - } - - active_key = key; - if (key == -1) - return; - active_start = now; - } - - if ((this->pressed_key_ == key) || (now - active_start < this->debounce_time_)) - return; - - row = key / this->columns_.size(); - col = key % this->columns_.size(); - ESP_LOGD(TAG, "key @ row %d, col %d pressed", row, col); - for (auto &listener : this->listeners_) - listener->button_pressed(row, col); - if (this->keys_.size()) { - uint8_t keycode = this->keys_[key]; - ESP_LOGD(TAG, "key '%c' pressed", keycode); - for (auto &listener : this->listeners_) - listener->key_pressed(keycode); - this->send_key_(keycode); - } - this->pressed_key_ = key; -} - -void Keypad::dump_config() { - ESP_LOGCONFIG(TAG, "Keypad:"); - ESP_LOGCONFIG(TAG, " Rows:"); - for (auto &pin : this->rows_) - LOG_PIN(" Pin: ", pin); - ESP_LOGCONFIG(TAG, " Cols:"); - for (auto &pin : this->columns_) - LOG_PIN(" Pin: ", pin); -} - -void Keypad::register_listener(KeypadListener *listener) { - this->listeners_.push_back(listener); -} - -} // namespace keypad -} // namespace esphome - diff --git a/components/matrix_keypad/keypad.h b/components/matrix_keypad/keypad.h deleted file mode 100644 index 9a23f2a..0000000 --- a/components/matrix_keypad/keypad.h +++ /dev/null @@ -1,47 +0,0 @@ -#pragma once - -#include "esphome/components/key_provider/key_provider.h" -#include "esphome/core/component.h" -#include "esphome/core/hal.h" -#include "esphome/core/helpers.h" -#include - -namespace esphome { -namespace keypad { - -class KeypadListener { - public: - virtual void button_pressed(int row, int col) {}; - virtual void button_released(int row, int col) {}; - virtual void key_pressed(uint8_t key) {}; - virtual void key_released(uint8_t key) {}; -}; - -class Keypad : public key_provider::KeyProvider, public Component { - public: - void setup() override; - void loop() override; - void dump_config() override; - void set_columns(std::vector pins) { columns_ = pins; }; - void set_rows(std::vector pins) { rows_ = pins; }; - void set_keys(std::string keys) { keys_ = keys; }; - void set_debounce_time(int debounce_time) { debounce_time_ = debounce_time; }; - void set_has_diodes(int has_diodes) { has_diodes_ = has_diodes; }; - - void register_listener(KeypadListener *listener); - - protected: - std::vector rows_; - std::vector columns_; - std::string keys_; - int debounce_time_ = 0; - bool has_diodes_{false}; - int pressed_key_ = -1; - - std::vector listeners_{}; -}; - -} // namespace keypad -} // namespace esphome - - diff --git a/components/vbus/README.md b/components/vbus/README.md deleted file mode 100644 index 625aac8..0000000 --- a/components/vbus/README.md +++ /dev/null @@ -1,162 +0,0 @@ -# This component has been merged to esphome: - -# VBus protocol component - -A configured uart component is required. - -Example: -```yaml -vbus: - uart_id: the_uart - -sensor: - - platform: vbus - model: deltasol c - temperature_1: - name: Temperature 1 - temperature_2: - name: Temperature 2 - temperature_3: - name: Temperature 3 - temperature_4: - name: Temperature 4 - pump_speed_1: - name: Pump Speed 1 - pump_speed_2: - name: Pump Speed 2 - operating_hours_1: - name: Operating Hours 1 - operating_hours_2: - name: Operating Hours 2 - heat_quantity: - name: Heat Quantity - time: - name: System Time - - - platform: vbus - model: deltasol cs2 - temperature_1: - name: Temperature 1 - temperature_2: - name: Temperature 2 - temperature_3: - name: Temperature 3 - temperature_4: - name: Temperature 4 - pump_speed: - name: Pump Speed - operating_hours: - name: Operating Hours - heat_quantity: - name: Heat Quantity - version: - name: SW Version - - - platform: vbus - model: deltasol_bs_plus - temperature_1: - name: Temperature 1 - temperature_2: - name: Temperature 2 - temperature_3: - name: Temperature 3 - temperature_4: - name: Temperature 4 - pump_speed_1: - name: Pump Speed 1 - pump_speed_2: - name: Pump Speed 2 - operating_hours_1: - name: Operating Hours 1 - operating_hours_2: - name: Operating Hours 2 - heat_quantity: - name: Heat Quantity - time: - name: System Time - version: - name: SW Version - - - platform: vbus - model: custom - command: 0x100 - source: 0x1234 - dest: 0x10 - lambda: |- - // the data is in `x` - -text_sensor: - - platform: vbus - model: deltasol c - time: - name: System Time - - - platform: vbus - model: deltasol cs2 - version: - name: Version - - - platform: vbus - model: deltasol_bs_plus - time: - name: System Time - version: - name: Version - -binary_sensor: - - platform: vbus - model: deltasol c - sensor1_error: - name: Sensor 1 Error - sensor2_error: - name: Sensor 2 Error - sensor3_error: - name: Sensor 3 Error - sensor4_error: - name: Sensor 4 Error - - - platform: vbus - model: deltasol cs2 - sensor1_error: - name: Sensor 1 Error - sensor2_error: - name: Sensor 2 Error - sensor3_error: - name: Sensor 3 Error - sensor4_error: - name: Sensor 4 Error - - - platform: vbus - model: deltasol_bs_plus - relay1: - name: Relay 1 On - relay2: - name: Relay 2 On - sensor1_error: - name: Sensor 1 Error - sensor2_error: - name: Sensor 2 Error - sensor3_error: - name: Sensor 3 Error - sensor4_error: - name: Sensor 4 Error - collector_max: - name: Option Collector Max - collector_min: - name: Option Collector Min - collector_frost: - name: Option Collector Frost - tube_collector: - name: Option Tube Collector - recooling: - name: Option Recooling - hqm: - name: Option Heat Quantity Measurement -``` - -The `uart_id` is optional. - -All sensors are optional. - -For the custom sensor, all the parameters are optional and if not specified, will match any value. -``` diff --git a/components/vbus/__init__.py b/components/vbus/__init__.py deleted file mode 100644 index 70f130e..0000000 --- a/components/vbus/__init__.py +++ /dev/null @@ -1,32 +0,0 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import uart -from esphome.const import CONF_ID - -CODEOWNERS = ["@ssieb"] - -DEPENDENCIES = ["uart"] - -MULTI_CONF = True - -vbus_ns = cg.esphome_ns.namespace("vbus") -VBus = vbus_ns.class_("VBus", uart.UARTDevice, cg.Component) - -CONF_VBUS_ID = "vbus_id" - -CONF_DELTASOL_BS_PLUS = "deltasol_bs_plus" -CONF_DELTASOL_C = "deltasol_c" -CONF_DELTASOL_CS2 = "deltasol_cs2" -CONF_DELTASOL_CS_PLUS = "deltasol_cs_plus" - -CONFIG_SCHEMA = uart.UART_DEVICE_SCHEMA.extend( - { - cv.GenerateID(): cv.declare_id(VBus), - } -) - - -async def to_code(config): - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - await uart.register_uart_device(var, config) diff --git a/components/vbus/binary_sensor/__init__.py b/components/vbus/binary_sensor/__init__.py deleted file mode 100644 index 5de955f..0000000 --- a/components/vbus/binary_sensor/__init__.py +++ /dev/null @@ -1,252 +0,0 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import binary_sensor -from esphome.const import ( - CONF_ID, - CONF_MODEL, - DEVICE_CLASS_PROBLEM, - ENTITY_CATEGORY_DIAGNOSTIC, -) -from .. import ( - vbus_ns, - VBus, - CONF_VBUS_ID, - CONF_DELTASOL_BS_PLUS, - CONF_DELTASOL_C, - CONF_DELTASOL_CS2, - CONF_DELTASOL_CS_PLUS, -) - -DeltaSol_BS_Plus = vbus_ns.class_("DeltaSolBSPlusBSensor", cg.Component) -DeltaSol_C = vbus_ns.class_("DeltaSolCBSensor", cg.Component) -DeltaSol_CS2 = vbus_ns.class_("DeltaSolCS2BSensor", cg.Component) -DeltaSol_CS_Plus = vbus_ns.class_("DeltaSolCSPlusBSensor", cg.Component) - -CONF_RELAY1 = "relay1" -CONF_RELAY2 = "relay2" -CONF_SENSOR1_ERROR = "sensor1_error" -CONF_SENSOR2_ERROR = "sensor2_error" -CONF_SENSOR3_ERROR = "sensor3_error" -CONF_SENSOR4_ERROR = "sensor4_error" -CONF_COLLECTOR_MAX = "collector_max" -CONF_COLLECTOR_MIN = "collector_min" -CONF_COLLECTOR_FROST = "collector_frost" -CONF_TUBE_COLLECTOR = "tube_collector" -CONF_RECOOLING = "recooling" -CONF_HQM = "hqm" - -CONFIG_SCHEMA = cv.typed_schema( - { - CONF_DELTASOL_BS_PLUS: cv.COMPONENT_SCHEMA.extend( - { - cv.GenerateID(): cv.declare_id(DeltaSol_BS_Plus), - cv.GenerateID(CONF_VBUS_ID): cv.use_id(VBus), - cv.Optional(CONF_RELAY1): binary_sensor.binary_sensor_schema(), - cv.Optional(CONF_RELAY2): binary_sensor.binary_sensor_schema(), - cv.Optional(CONF_SENSOR1_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_SENSOR2_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_SENSOR3_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_SENSOR4_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_COLLECTOR_MAX): binary_sensor.binary_sensor_schema( - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_COLLECTOR_MIN): binary_sensor.binary_sensor_schema( - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_COLLECTOR_FROST): binary_sensor.binary_sensor_schema( - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_TUBE_COLLECTOR): binary_sensor.binary_sensor_schema( - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_RECOOLING): binary_sensor.binary_sensor_schema( - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_HQM): binary_sensor.binary_sensor_schema( - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - } - ), - CONF_DELTASOL_C: cv.COMPONENT_SCHEMA.extend( - { - cv.GenerateID(): cv.declare_id(DeltaSol_C), - cv.GenerateID(CONF_VBUS_ID): cv.use_id(VBus), - cv.Optional(CONF_SENSOR1_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_SENSOR2_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_SENSOR3_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_SENSOR4_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - } - ), - CONF_DELTASOL_CS2: cv.COMPONENT_SCHEMA.extend( - { - cv.GenerateID(): cv.declare_id(DeltaSol_CS2), - cv.GenerateID(CONF_VBUS_ID): cv.use_id(VBus), - cv.Optional(CONF_SENSOR1_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_SENSOR2_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_SENSOR3_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_SENSOR4_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - } - ), - CONF_DELTASOL_CS_PLUS: cv.COMPONENT_SCHEMA.extend( - { - cv.GenerateID(): cv.declare_id(DeltaSol_CS_Plus), - cv.GenerateID(CONF_VBUS_ID): cv.use_id(VBus), - cv.Optional(CONF_SENSOR1_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_SENSOR2_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_SENSOR3_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_SENSOR4_ERROR): binary_sensor.binary_sensor_schema( - device_class=DEVICE_CLASS_PROBLEM, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - } - ), - }, - key=CONF_MODEL, - lower=True, - space="_", -) - - -async def to_code(config): - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - - if config[CONF_MODEL] == CONF_DELTASOL_BS_PLUS: - cg.add(var.set_command(0x0100)) - cg.add(var.set_source(0x4221)) - cg.add(var.set_dest(0x0010)) - if CONF_RELAY1 in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_RELAY1]) - cg.add(var.set_relay1_bsensor(sens)) - if CONF_RELAY2 in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_RELAY2]) - cg.add(var.set_relay2_bsensor(sens)) - if CONF_SENSOR1_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR1_ERROR]) - cg.add(var.set_s1_error_bsensor(sens)) - if CONF_SENSOR2_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR2_ERROR]) - cg.add(var.set_s2_error_bsensor(sens)) - if CONF_SENSOR3_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR3_ERROR]) - cg.add(var.set_s3_error_bsensor(sens)) - if CONF_SENSOR4_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR4_ERROR]) - cg.add(var.set_s4_error_bsensor(sens)) - if CONF_COLLECTOR_MAX in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_COLLECTOR_MAX]) - cg.add(var.set_collector_max_bsensor(sens)) - if CONF_COLLECTOR_MIN in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_COLLECTOR_MIN]) - cg.add(var.set_collector_min_bsensor(sens)) - if CONF_COLLECTOR_FROST in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_COLLECTOR_FROST]) - cg.add(var.set_collector_frost_bsensor(sens)) - if CONF_TUBE_COLLECTOR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_TUBE_COLLECTOR]) - cg.add(var.set_tube_collector_bsensor(sens)) - if CONF_RECOOLING in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_RECOOLING]) - cg.add(var.set_recooling_bsensor(sens)) - if CONF_HQM in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_HQM]) - cg.add(var.set_hqm_bsensor(sens)) - - elif config[CONF_MODEL] == CONF_DELTASOL_C: - cg.add(var.set_command(0x0100)) - cg.add(var.set_source(0x4212)) - cg.add(var.set_dest(0x0010)) - if CONF_SENSOR1_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR1_ERROR]) - cg.add(var.set_s1_error_bsensor(sens)) - if CONF_SENSOR2_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR2_ERROR]) - cg.add(var.set_s2_error_bsensor(sens)) - if CONF_SENSOR3_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR3_ERROR]) - cg.add(var.set_s3_error_bsensor(sens)) - if CONF_SENSOR4_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR4_ERROR]) - cg.add(var.set_s4_error_bsensor(sens)) - - elif config[CONF_MODEL] == CONF_DELTASOL_CS2: - cg.add(var.set_command(0x0100)) - cg.add(var.set_source(0x1121)) - cg.add(var.set_dest(0x0010)) - if CONF_SENSOR1_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR1_ERROR]) - cg.add(var.set_s1_error_bsensor(sens)) - if CONF_SENSOR2_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR2_ERROR]) - cg.add(var.set_s2_error_bsensor(sens)) - if CONF_SENSOR3_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR3_ERROR]) - cg.add(var.set_s3_error_bsensor(sens)) - if CONF_SENSOR4_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR4_ERROR]) - cg.add(var.set_s4_error_bsensor(sens)) - - elif config[CONF_MODEL] == CONF_DELTASOL_CS_PLUS: - cg.add(var.set_command(0x0100)) - cg.add(var.set_source(0x2211)) - cg.add(var.set_dest(0x0010)) - if CONF_SENSOR1_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR1_ERROR]) - cg.add(var.set_s1_error_bsensor(sens)) - if CONF_SENSOR2_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR2_ERROR]) - cg.add(var.set_s2_error_bsensor(sens)) - if CONF_SENSOR3_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR3_ERROR]) - cg.add(var.set_s3_error_bsensor(sens)) - if CONF_SENSOR4_ERROR in config: - sens = await binary_sensor.new_binary_sensor(config[CONF_SENSOR4_ERROR]) - cg.add(var.set_s4_error_bsensor(sens)) - - vbus = await cg.get_variable(config[CONF_VBUS_ID]) - cg.add(vbus.register_listener(var)) diff --git a/components/vbus/binary_sensor/vbus_binary_sensor.cpp b/components/vbus/binary_sensor/vbus_binary_sensor.cpp deleted file mode 100644 index 8320551..0000000 --- a/components/vbus/binary_sensor/vbus_binary_sensor.cpp +++ /dev/null @@ -1,111 +0,0 @@ -#include "vbus_binary_sensor.h" -#include "esphome/core/helpers.h" -#include "esphome/core/log.h" - -namespace esphome { -namespace vbus { - -static const char *const TAG = "vbus.binary_sensor"; - -void DeltaSolBSPlusBSensor::dump_config() { - ESP_LOGCONFIG(TAG, "Deltasol BS Plus:"); - LOG_BINARY_SENSOR(" ", "Relay 1 On", this->relay1_bsensor_); - LOG_BINARY_SENSOR(" ", "Relay 2 On", this->relay2_bsensor_); - LOG_BINARY_SENSOR(" ", "Sensor 1 Error", this->s1_error_bsensor_); - LOG_BINARY_SENSOR(" ", "Sensor 2 Error", this->s2_error_bsensor_); - LOG_BINARY_SENSOR(" ", "Sensor 3 Error", this->s3_error_bsensor_); - LOG_BINARY_SENSOR(" ", "Sensor 4 Error", this->s4_error_bsensor_); - LOG_BINARY_SENSOR(" ", "Option Collector Max", this->collector_max_bsensor_); - LOG_BINARY_SENSOR(" ", "Option Collector Min", this->collector_min_bsensor_); - LOG_BINARY_SENSOR(" ", "Option Collector Frost", this->collector_frost_bsensor_); - LOG_BINARY_SENSOR(" ", "Option Tube Collector", this->tube_collector_bsensor_); - LOG_BINARY_SENSOR(" ", "Option Recooling", this->recooling_bsensor_); - LOG_BINARY_SENSOR(" ", "Option Heat Quantity Measurement", this->hqm_bsensor_); -} - -void DeltaSolBSPlusBSensor::handle_message(std::vector &message) { - if (this->relay1_bsensor_ != nullptr) - this->relay1_bsensor_->publish_state(message[10] & 1); - if (this->relay2_bsensor_ != nullptr) - this->relay2_bsensor_->publish_state(message[10] & 2); - if (this->s1_error_bsensor_ != nullptr) - this->s1_error_bsensor_->publish_state(message[11] & 1); - if (this->s2_error_bsensor_ != nullptr) - this->s2_error_bsensor_->publish_state(message[11] & 2); - if (this->s3_error_bsensor_ != nullptr) - this->s3_error_bsensor_->publish_state(message[11] & 4); - if (this->s4_error_bsensor_ != nullptr) - this->s4_error_bsensor_->publish_state(message[11] & 8); - if (this->collector_max_bsensor_ != nullptr) - this->collector_max_bsensor_->publish_state(message[15] & 1); - if (this->collector_min_bsensor_ != nullptr) - this->collector_min_bsensor_->publish_state(message[15] & 2); - if (this->collector_frost_bsensor_ != nullptr) - this->collector_frost_bsensor_->publish_state(message[15] & 4); - if (this->tube_collector_bsensor_ != nullptr) - this->tube_collector_bsensor_->publish_state(message[15] & 8); - if (this->recooling_bsensor_ != nullptr) - this->recooling_bsensor_->publish_state(message[15] & 0x10); - if (this->hqm_bsensor_ != nullptr) - this->hqm_bsensor_->publish_state(message[15] & 0x20); -} - -void DeltaSolCBSensor::dump_config() { - ESP_LOGCONFIG(TAG, "Deltasol C:"); - LOG_BINARY_SENSOR(" ", "Sensor 1 Error", this->s1_error_bsensor_); - LOG_BINARY_SENSOR(" ", "Sensor 2 Error", this->s2_error_bsensor_); - LOG_BINARY_SENSOR(" ", "Sensor 3 Error", this->s3_error_bsensor_); - LOG_BINARY_SENSOR(" ", "Sensor 4 Error", this->s4_error_bsensor_); -} - -void DeltaSolCBSensor::handle_message(std::vector &message) { - if (this->s1_error_bsensor_ != nullptr) - this->s1_error_bsensor_->publish_state(message[10] & 1); - if (this->s2_error_bsensor_ != nullptr) - this->s2_error_bsensor_->publish_state(message[10] & 2); - if (this->s3_error_bsensor_ != nullptr) - this->s3_error_bsensor_->publish_state(message[10] & 4); - if (this->s4_error_bsensor_ != nullptr) - this->s4_error_bsensor_->publish_state(message[10] & 8); -} - -void DeltaSolCS2BSensor::dump_config() { - ESP_LOGCONFIG(TAG, "Deltasol CS2:"); - LOG_BINARY_SENSOR(" ", "Sensor 1 Error", this->s1_error_bsensor_); - LOG_BINARY_SENSOR(" ", "Sensor 2 Error", this->s2_error_bsensor_); - LOG_BINARY_SENSOR(" ", "Sensor 3 Error", this->s3_error_bsensor_); - LOG_BINARY_SENSOR(" ", "Sensor 4 Error", this->s4_error_bsensor_); -} - -void DeltaSolCS2BSensor::handle_message(std::vector &message) { - if (this->s1_error_bsensor_ != nullptr) - this->s1_error_bsensor_->publish_state(message[18] & 1); - if (this->s2_error_bsensor_ != nullptr) - this->s2_error_bsensor_->publish_state(message[18] & 2); - if (this->s3_error_bsensor_ != nullptr) - this->s3_error_bsensor_->publish_state(message[18] & 4); - if (this->s4_error_bsensor_ != nullptr) - this->s4_error_bsensor_->publish_state(message[18] & 8); -} - -void DeltaSolCSPlusBSensor::dump_config() { - ESP_LOGCONFIG(TAG, "Deltasol CS Plus:"); - LOG_BINARY_SENSOR(" ", "Sensor 1 Error", this->s1_error_bsensor_); - LOG_BINARY_SENSOR(" ", "Sensor 2 Error", this->s2_error_bsensor_); - LOG_BINARY_SENSOR(" ", "Sensor 3 Error", this->s3_error_bsensor_); - LOG_BINARY_SENSOR(" ", "Sensor 4 Error", this->s4_error_bsensor_); -} - -void DeltaSolCSPlusBSensor::handle_message(std::vector &message) { - if (this->s1_error_bsensor_ != nullptr) - this->s1_error_bsensor_->publish_state(message[20] & 1); - if (this->s2_error_bsensor_ != nullptr) - this->s2_error_bsensor_->publish_state(message[20] & 2); - if (this->s3_error_bsensor_ != nullptr) - this->s3_error_bsensor_->publish_state(message[20] & 4); - if (this->s4_error_bsensor_ != nullptr) - this->s4_error_bsensor_->publish_state(message[20] & 8); -} - -} // namespace vbus -} // namespace esphome diff --git a/components/vbus/binary_sensor/vbus_binary_sensor.h b/components/vbus/binary_sensor/vbus_binary_sensor.h deleted file mode 100644 index fd99869..0000000 --- a/components/vbus/binary_sensor/vbus_binary_sensor.h +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once - -#include "../vbus.h" -#include "esphome/components/binary_sensor/binary_sensor.h" - -namespace esphome { -namespace vbus { - -using message_handler_t = std::function &)>; - -class DeltaSolBSPlusBSensor : public VBusListener, public Component { - public: - void dump_config() override; - void set_relay1_bsensor(binary_sensor::BinarySensor *bsensor) { this->relay1_bsensor_ = bsensor; } - void set_relay2_bsensor(binary_sensor::BinarySensor *bsensor) { this->relay2_bsensor_ = bsensor; } - void set_s1_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s1_error_bsensor_ = bsensor; } - void set_s2_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s2_error_bsensor_ = bsensor; } - void set_s3_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s3_error_bsensor_ = bsensor; } - void set_s4_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s4_error_bsensor_ = bsensor; } - void set_collector_max_bsensor(binary_sensor::BinarySensor *bsensor) { this->collector_max_bsensor_ = bsensor; } - void set_collector_min_bsensor(binary_sensor::BinarySensor *bsensor) { this->collector_min_bsensor_ = bsensor; } - void set_collector_frost_bsensor(binary_sensor::BinarySensor *bsensor) { this->collector_frost_bsensor_ = bsensor; } - void set_tube_collector_bsensor(binary_sensor::BinarySensor *bsensor) { this->tube_collector_bsensor_ = bsensor; } - void set_recooling_bsensor(binary_sensor::BinarySensor *bsensor) { this->recooling_bsensor_ = bsensor; } - void set_hqm_bsensor(binary_sensor::BinarySensor *bsensor) { this->hqm_bsensor_ = bsensor; } - - protected: - binary_sensor::BinarySensor *relay1_bsensor_{nullptr}; - binary_sensor::BinarySensor *relay2_bsensor_{nullptr}; - binary_sensor::BinarySensor *s1_error_bsensor_{nullptr}; - binary_sensor::BinarySensor *s2_error_bsensor_{nullptr}; - binary_sensor::BinarySensor *s3_error_bsensor_{nullptr}; - binary_sensor::BinarySensor *s4_error_bsensor_{nullptr}; - binary_sensor::BinarySensor *collector_max_bsensor_{nullptr}; - binary_sensor::BinarySensor *collector_min_bsensor_{nullptr}; - binary_sensor::BinarySensor *collector_frost_bsensor_{nullptr}; - binary_sensor::BinarySensor *tube_collector_bsensor_{nullptr}; - binary_sensor::BinarySensor *recooling_bsensor_{nullptr}; - binary_sensor::BinarySensor *hqm_bsensor_{nullptr}; - - void handle_message(std::vector &message) override; -}; - -class DeltaSolCBSensor : public VBusListener, public Component { - public: - void dump_config() override; - void set_s1_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s1_error_bsensor_ = bsensor; } - void set_s2_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s2_error_bsensor_ = bsensor; } - void set_s3_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s3_error_bsensor_ = bsensor; } - void set_s4_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s4_error_bsensor_ = bsensor; } - - protected: - binary_sensor::BinarySensor *s1_error_bsensor_{nullptr}; - binary_sensor::BinarySensor *s2_error_bsensor_{nullptr}; - binary_sensor::BinarySensor *s3_error_bsensor_{nullptr}; - binary_sensor::BinarySensor *s4_error_bsensor_{nullptr}; - - void handle_message(std::vector &message) override; -}; - -class DeltaSolCS2BSensor : public VBusListener, public Component { - public: - void dump_config() override; - void set_s1_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s1_error_bsensor_ = bsensor; } - void set_s2_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s2_error_bsensor_ = bsensor; } - void set_s3_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s3_error_bsensor_ = bsensor; } - void set_s4_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s4_error_bsensor_ = bsensor; } - - protected: - binary_sensor::BinarySensor *s1_error_bsensor_{nullptr}; - binary_sensor::BinarySensor *s2_error_bsensor_{nullptr}; - binary_sensor::BinarySensor *s3_error_bsensor_{nullptr}; - binary_sensor::BinarySensor *s4_error_bsensor_{nullptr}; - - void handle_message(std::vector &message) override; -}; - -class DeltaSolCSPlusBSensor : public VBusListener, public Component { - public: - void dump_config() override; - void set_s1_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s1_error_bsensor_ = bsensor; } - void set_s2_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s2_error_bsensor_ = bsensor; } - void set_s3_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s3_error_bsensor_ = bsensor; } - void set_s4_error_bsensor(binary_sensor::BinarySensor *bsensor) { this->s4_error_bsensor_ = bsensor; } - - protected: - binary_sensor::BinarySensor *s1_error_bsensor_{nullptr}; - binary_sensor::BinarySensor *s2_error_bsensor_{nullptr}; - binary_sensor::BinarySensor *s3_error_bsensor_{nullptr}; - binary_sensor::BinarySensor *s4_error_bsensor_{nullptr}; - - void handle_message(std::vector &message) override; -}; - -} // namespace vbus -} // namespace esphome diff --git a/components/vbus/sensor/__init__.py b/components/vbus/sensor/__init__.py deleted file mode 100644 index fbc20c7..0000000 --- a/components/vbus/sensor/__init__.py +++ /dev/null @@ -1,556 +0,0 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome.components import sensor -from esphome.const import ( - CONF_ID, - CONF_COMMAND, - CONF_LAMBDA, - CONF_MODEL, - CONF_SOURCE, - CONF_TIME, - CONF_VERSION, - DEVICE_CLASS_DURATION, - DEVICE_CLASS_EMPTY, - DEVICE_CLASS_ENERGY, - DEVICE_CLASS_TEMPERATURE, - ENTITY_CATEGORY_DIAGNOSTIC, - ICON_PERCENT, - ICON_RADIATOR, - ICON_THERMOMETER, - ICON_TIMER, - STATE_CLASS_MEASUREMENT, - UNIT_CELSIUS, - UNIT_MINUTE, - UNIT_PERCENT, - UNIT_WATT_HOURS, -) -from .. import ( - vbus_ns, - VBus, - CONF_VBUS_ID, - CONF_DELTASOL_BS_PLUS, - CONF_DELTASOL_C, - CONF_DELTASOL_CS2, - CONF_DELTASOL_CS_PLUS, -) - -DeltaSol_BS_Plus = vbus_ns.class_("DeltaSolBSPlusSensor", cg.Component) -DeltaSol_C = vbus_ns.class_("DeltaSolCSensor", cg.Component) -DeltaSol_CS2 = vbus_ns.class_("DeltaSolCS2Sensor", cg.Component) -DeltaSol_CS_Plus = vbus_ns.class_("DeltaSolCSPlusSensor", cg.Component) -VBusCustom = vbus_ns.class_("VBusCustomSensor", cg.Component) - -CONF_CUSTOM = "custom" -CONF_DEST = "dest" -CONF_FLOW_RATE = "flow_rate" -CONF_HEAT_QUANTITY = "heat_quantity" -CONF_OPERATING_HOURS = "operating_hours" -CONF_OPERATING_HOURS_1 = "operating_hours_1" -CONF_OPERATING_HOURS_2 = "operating_hours_2" -CONF_PUMP_SPEED = "pump_speed" -CONF_PUMP_SPEED_1 = "pump_speed_1" -CONF_PUMP_SPEED_2 = "pump_speed_2" -CONF_TEMPERATURE_1 = "temperature_1" -CONF_TEMPERATURE_2 = "temperature_2" -CONF_TEMPERATURE_3 = "temperature_3" -CONF_TEMPERATURE_4 = "temperature_4" -CONF_TEMPERATURE_5 = "temperature_5" - -UNIT_HOUR = "h" - -CONFIG_SCHEMA = cv.typed_schema( - { - CONF_DELTASOL_BS_PLUS: cv.COMPONENT_SCHEMA.extend( - { - cv.GenerateID(): cv.declare_id(DeltaSol_BS_Plus), - cv.GenerateID(CONF_VBUS_ID): cv.use_id(VBus), - cv.Optional(CONF_TEMPERATURE_1): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TEMPERATURE_2): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TEMPERATURE_3): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TEMPERATURE_4): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_PUMP_SPEED_1): sensor.sensor_schema( - unit_of_measurement=UNIT_PERCENT, - icon=ICON_PERCENT, - accuracy_decimals=0, - device_class=DEVICE_CLASS_EMPTY, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_PUMP_SPEED_2): sensor.sensor_schema( - unit_of_measurement=UNIT_PERCENT, - icon=ICON_PERCENT, - accuracy_decimals=0, - device_class=DEVICE_CLASS_EMPTY, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_OPERATING_HOURS_1): sensor.sensor_schema( - unit_of_measurement=UNIT_HOUR, - icon=ICON_TIMER, - accuracy_decimals=0, - device_class=DEVICE_CLASS_DURATION, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_OPERATING_HOURS_2): sensor.sensor_schema( - unit_of_measurement=UNIT_HOUR, - icon=ICON_TIMER, - accuracy_decimals=0, - device_class=DEVICE_CLASS_DURATION, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_HEAT_QUANTITY): sensor.sensor_schema( - unit_of_measurement=UNIT_WATT_HOURS, - icon=ICON_RADIATOR, - accuracy_decimals=0, - device_class=DEVICE_CLASS_ENERGY, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TIME): sensor.sensor_schema( - unit_of_measurement=UNIT_MINUTE, - icon=ICON_TIMER, - accuracy_decimals=0, - device_class=DEVICE_CLASS_DURATION, - state_class=STATE_CLASS_MEASUREMENT, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_VERSION): sensor.sensor_schema( - accuracy_decimals=2, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - } - ), - CONF_DELTASOL_C: cv.COMPONENT_SCHEMA.extend( - { - cv.GenerateID(): cv.declare_id(DeltaSol_C), - cv.GenerateID(CONF_VBUS_ID): cv.use_id(VBus), - cv.Optional(CONF_TEMPERATURE_1): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TEMPERATURE_2): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TEMPERATURE_3): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TEMPERATURE_4): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_PUMP_SPEED_1): sensor.sensor_schema( - unit_of_measurement=UNIT_PERCENT, - icon=ICON_PERCENT, - accuracy_decimals=0, - device_class=DEVICE_CLASS_EMPTY, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_PUMP_SPEED_2): sensor.sensor_schema( - unit_of_measurement=UNIT_PERCENT, - icon=ICON_PERCENT, - accuracy_decimals=0, - device_class=DEVICE_CLASS_EMPTY, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_OPERATING_HOURS_1): sensor.sensor_schema( - unit_of_measurement=UNIT_HOUR, - icon=ICON_TIMER, - accuracy_decimals=0, - device_class=DEVICE_CLASS_DURATION, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_OPERATING_HOURS_2): sensor.sensor_schema( - unit_of_measurement=UNIT_HOUR, - icon=ICON_TIMER, - accuracy_decimals=0, - device_class=DEVICE_CLASS_DURATION, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_HEAT_QUANTITY): sensor.sensor_schema( - unit_of_measurement=UNIT_WATT_HOURS, - icon=ICON_RADIATOR, - accuracy_decimals=0, - device_class=DEVICE_CLASS_ENERGY, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TIME): sensor.sensor_schema( - unit_of_measurement=UNIT_MINUTE, - icon=ICON_TIMER, - accuracy_decimals=0, - device_class=DEVICE_CLASS_DURATION, - state_class=STATE_CLASS_MEASUREMENT, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - } - ), - CONF_DELTASOL_CS2: cv.COMPONENT_SCHEMA.extend( - { - cv.GenerateID(): cv.declare_id(DeltaSol_CS2), - cv.GenerateID(CONF_VBUS_ID): cv.use_id(VBus), - cv.Optional(CONF_TEMPERATURE_1): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TEMPERATURE_2): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TEMPERATURE_3): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TEMPERATURE_4): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_PUMP_SPEED): sensor.sensor_schema( - unit_of_measurement=UNIT_PERCENT, - icon=ICON_PERCENT, - accuracy_decimals=0, - device_class=DEVICE_CLASS_EMPTY, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_OPERATING_HOURS): sensor.sensor_schema( - unit_of_measurement=UNIT_HOUR, - icon=ICON_TIMER, - accuracy_decimals=0, - device_class=DEVICE_CLASS_DURATION, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_HEAT_QUANTITY): sensor.sensor_schema( - unit_of_measurement=UNIT_WATT_HOURS, - icon=ICON_RADIATOR, - accuracy_decimals=0, - device_class=DEVICE_CLASS_ENERGY, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_VERSION): sensor.sensor_schema( - accuracy_decimals=2, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - } - ), - CONF_DELTASOL_CS_PLUS: cv.COMPONENT_SCHEMA.extend( - { - cv.GenerateID(): cv.declare_id(DeltaSol_CS_Plus), - cv.GenerateID(CONF_VBUS_ID): cv.use_id(VBus), - cv.Optional(CONF_TEMPERATURE_1): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TEMPERATURE_2): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TEMPERATURE_3): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TEMPERATURE_4): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TEMPERATURE_5): sensor.sensor_schema( - unit_of_measurement=UNIT_CELSIUS, - icon=ICON_THERMOMETER, - accuracy_decimals=1, - device_class=DEVICE_CLASS_TEMPERATURE, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_PUMP_SPEED_1): sensor.sensor_schema( - unit_of_measurement=UNIT_PERCENT, - icon=ICON_PERCENT, - accuracy_decimals=0, - device_class=DEVICE_CLASS_EMPTY, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_PUMP_SPEED_2): sensor.sensor_schema( - unit_of_measurement=UNIT_PERCENT, - icon=ICON_PERCENT, - accuracy_decimals=0, - device_class=DEVICE_CLASS_EMPTY, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_OPERATING_HOURS_1): sensor.sensor_schema( - unit_of_measurement=UNIT_HOUR, - icon=ICON_TIMER, - accuracy_decimals=0, - device_class=DEVICE_CLASS_DURATION, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_OPERATING_HOURS_2): sensor.sensor_schema( - unit_of_measurement=UNIT_HOUR, - icon=ICON_TIMER, - accuracy_decimals=0, - device_class=DEVICE_CLASS_DURATION, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_HEAT_QUANTITY): sensor.sensor_schema( - unit_of_measurement=UNIT_WATT_HOURS, - icon=ICON_RADIATOR, - accuracy_decimals=0, - device_class=DEVICE_CLASS_ENERGY, - state_class=STATE_CLASS_MEASUREMENT, - ), - cv.Optional(CONF_TIME): sensor.sensor_schema( - unit_of_measurement=UNIT_MINUTE, - icon=ICON_TIMER, - accuracy_decimals=0, - device_class=DEVICE_CLASS_DURATION, - state_class=STATE_CLASS_MEASUREMENT, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_VERSION): sensor.sensor_schema( - accuracy_decimals=2, - entity_category=ENTITY_CATEGORY_DIAGNOSTIC, - ), - cv.Optional(CONF_FLOW_RATE): sensor.sensor_schema( - accuracy_decimals=0, - device_class=DEVICE_CLASS_EMPTY, - state_class=STATE_CLASS_MEASUREMENT, - ), - } - ), - CONF_CUSTOM: cv.COMPONENT_SCHEMA.extend( - { - cv.GenerateID(): cv.declare_id(VBusCustom), - cv.GenerateID(CONF_VBUS_ID): cv.use_id(VBus), - cv.Optional(CONF_COMMAND): cv.uint16_t, - cv.Optional(CONF_SOURCE): cv.uint16_t, - cv.Optional(CONF_DEST): cv.uint16_t, - cv.Optional(CONF_LAMBDA): cv.lambda_, - } - ), - }, - key=CONF_MODEL, - lower=True, - space="_", -) - - -async def to_code(config): - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - - if config[CONF_MODEL] == CONF_DELTASOL_BS_PLUS: - cg.add(var.set_command(0x0100)) - cg.add(var.set_source(0x4221)) - cg.add(var.set_dest(0x0010)) - if CONF_TEMPERATURE_1 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_1]) - cg.add(var.set_temperature1_sensor(sens)) - if CONF_TEMPERATURE_2 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_2]) - cg.add(var.set_temperature2_sensor(sens)) - if CONF_TEMPERATURE_3 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_3]) - cg.add(var.set_temperature3_sensor(sens)) - if CONF_TEMPERATURE_4 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_4]) - cg.add(var.set_temperature4_sensor(sens)) - if CONF_PUMP_SPEED_1 in config: - sens = await sensor.new_sensor(config[CONF_PUMP_SPEED_1]) - cg.add(var.set_pump_speed1_sensor(sens)) - if CONF_PUMP_SPEED_2 in config: - sens = await sensor.new_sensor(config[CONF_PUMP_SPEED_2]) - cg.add(var.set_pump_speed2_sensor(sens)) - if CONF_OPERATING_HOURS_1 in config: - sens = await sensor.new_sensor(config[CONF_OPERATING_HOURS_1]) - cg.add(var.set_operating_hours1_sensor(sens)) - if CONF_OPERATING_HOURS_2 in config: - sens = await sensor.new_sensor(config[CONF_OPERATING_HOURS_2]) - cg.add(var.set_operating_hours2_sensor(sens)) - if CONF_HEAT_QUANTITY in config: - sens = await sensor.new_sensor(config[CONF_HEAT_QUANTITY]) - cg.add(var.set_heat_quantity_sensor(sens)) - if CONF_TIME in config: - sens = await sensor.new_sensor(config[CONF_TIME]) - cg.add(var.set_time_sensor(sens)) - if CONF_VERSION in config: - sens = await sensor.new_sensor(config[CONF_VERSION]) - cg.add(var.set_version_sensor(sens)) - - elif config[CONF_MODEL] == CONF_DELTASOL_C: - cg.add(var.set_command(0x0100)) - cg.add(var.set_source(0x4212)) - cg.add(var.set_dest(0x0010)) - if CONF_TEMPERATURE_1 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_1]) - cg.add(var.set_temperature1_sensor(sens)) - if CONF_TEMPERATURE_2 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_2]) - cg.add(var.set_temperature2_sensor(sens)) - if CONF_TEMPERATURE_3 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_3]) - cg.add(var.set_temperature3_sensor(sens)) - if CONF_TEMPERATURE_4 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_4]) - cg.add(var.set_temperature4_sensor(sens)) - if CONF_PUMP_SPEED_1 in config: - sens = await sensor.new_sensor(config[CONF_PUMP_SPEED_1]) - cg.add(var.set_pump_speed1_sensor(sens)) - if CONF_PUMP_SPEED_2 in config: - sens = await sensor.new_sensor(config[CONF_PUMP_SPEED_2]) - cg.add(var.set_pump_speed2_sensor(sens)) - if CONF_OPERATING_HOURS_1 in config: - sens = await sensor.new_sensor(config[CONF_OPERATING_HOURS_1]) - cg.add(var.set_operating_hours1_sensor(sens)) - if CONF_OPERATING_HOURS_2 in config: - sens = await sensor.new_sensor(config[CONF_OPERATING_HOURS_2]) - cg.add(var.set_operating_hours2_sensor(sens)) - if CONF_HEAT_QUANTITY in config: - sens = await sensor.new_sensor(config[CONF_HEAT_QUANTITY]) - cg.add(var.set_heat_quantity_sensor(sens)) - if CONF_TIME in config: - sens = await sensor.new_sensor(config[CONF_TIME]) - cg.add(var.set_time_sensor(sens)) - - elif config[CONF_MODEL] == CONF_DELTASOL_CS2: - cg.add(var.set_command(0x0100)) - cg.add(var.set_source(0x1121)) - cg.add(var.set_dest(0x0010)) - if CONF_TEMPERATURE_1 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_1]) - cg.add(var.set_temperature1_sensor(sens)) - if CONF_TEMPERATURE_2 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_2]) - cg.add(var.set_temperature2_sensor(sens)) - if CONF_TEMPERATURE_3 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_3]) - cg.add(var.set_temperature3_sensor(sens)) - if CONF_TEMPERATURE_4 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_4]) - cg.add(var.set_temperature4_sensor(sens)) - if CONF_PUMP_SPEED in config: - sens = await sensor.new_sensor(config[CONF_PUMP_SPEED]) - cg.add(var.set_pump_speed_sensor(sens)) - if CONF_OPERATING_HOURS in config: - sens = await sensor.new_sensor(config[CONF_OPERATING_HOURS]) - cg.add(var.set_operating_hours_sensor(sens)) - if CONF_HEAT_QUANTITY in config: - sens = await sensor.new_sensor(config[CONF_HEAT_QUANTITY]) - cg.add(var.set_heat_quantity_sensor(sens)) - if CONF_VERSION in config: - sens = await sensor.new_sensor(config[CONF_VERSION]) - cg.add(var.set_version_sensor(sens)) - - if config[CONF_MODEL] == CONF_DELTASOL_CS_PLUS: - cg.add(var.set_command(0x0100)) - cg.add(var.set_source(0x2211)) - cg.add(var.set_dest(0x0010)) - if CONF_TEMPERATURE_1 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_1]) - cg.add(var.set_temperature1_sensor(sens)) - if CONF_TEMPERATURE_2 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_2]) - cg.add(var.set_temperature2_sensor(sens)) - if CONF_TEMPERATURE_3 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_3]) - cg.add(var.set_temperature3_sensor(sens)) - if CONF_TEMPERATURE_4 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_4]) - cg.add(var.set_temperature4_sensor(sens)) - if CONF_TEMPERATURE_5 in config: - sens = await sensor.new_sensor(config[CONF_TEMPERATURE_5]) - cg.add(var.set_temperature5_sensor(sens)) - if CONF_PUMP_SPEED_1 in config: - sens = await sensor.new_sensor(config[CONF_PUMP_SPEED_1]) - cg.add(var.set_pump_speed1_sensor(sens)) - if CONF_PUMP_SPEED_2 in config: - sens = await sensor.new_sensor(config[CONF_PUMP_SPEED_2]) - cg.add(var.set_pump_speed2_sensor(sens)) - if CONF_OPERATING_HOURS_1 in config: - sens = await sensor.new_sensor(config[CONF_OPERATING_HOURS_1]) - cg.add(var.set_operating_hours1_sensor(sens)) - if CONF_OPERATING_HOURS_2 in config: - sens = await sensor.new_sensor(config[CONF_OPERATING_HOURS_2]) - cg.add(var.set_operating_hours2_sensor(sens)) - if CONF_HEAT_QUANTITY in config: - sens = await sensor.new_sensor(config[CONF_HEAT_QUANTITY]) - cg.add(var.set_heat_quantity_sensor(sens)) - if CONF_TIME in config: - sens = await sensor.new_sensor(config[CONF_TIME]) - cg.add(var.set_time_sensor(sens)) - if CONF_VERSION in config: - sens = await sensor.new_sensor(config[CONF_VERSION]) - cg.add(var.set_version_sensor(sens)) - if CONF_FLOW_RATE in config: - sens = await sensor.new_sensor(config[CONF_FLOW_RATE]) - cg.add(var.set_flow_rate_sensor(sens)) - - elif config[CONF_MODEL] == CONF_CUSTOM: - if CONF_COMMAND in config: - cg.add(var.set_command(config[CONF_COMMAND])) - if CONF_SOURCE in config: - cg.add(var.set_source(config[CONF_SOURCE])) - if CONF_DEST in config: - cg.add(var.set_dest(config[CONF_DEST])) - if CONF_LAMBDA in config: - lambda_ = await cg.process_lambda( - config[CONF_LAMBDA], - [(cg.std_vector.template(cg.uint8), "x")], - return_type=cg.void, - ) - cg.add(var.set_message_handler(lambda_)) - - vbus = await cg.get_variable(config[CONF_VBUS_ID]) - cg.add(vbus.register_listener(var)) diff --git a/components/vbus/sensor/vbus_sensor.cpp b/components/vbus/sensor/vbus_sensor.cpp deleted file mode 100644 index 8693505..0000000 --- a/components/vbus/sensor/vbus_sensor.cpp +++ /dev/null @@ -1,201 +0,0 @@ -#include "vbus_sensor.h" -#include "esphome/core/helpers.h" -#include "esphome/core/log.h" - -namespace esphome { -namespace vbus { - -static const char *const TAG = "vbus.sensor"; - -static inline uint16_t get_u16(std::vector &message, int start) { - return (message[start + 1] << 8) + message[start]; -} - -static inline int16_t get_i16(std::vector &message, int start) { - return (int16_t)((message[start + 1] << 8) + message[start]); -} - -void DeltaSolBSPlusSensor::dump_config() { - ESP_LOGCONFIG(TAG, "Deltasol BS Plus:"); - LOG_SENSOR(" ", "Temperature 1", this->temperature1_sensor_); - LOG_SENSOR(" ", "Temperature 2", this->temperature2_sensor_); - LOG_SENSOR(" ", "Temperature 3", this->temperature3_sensor_); - LOG_SENSOR(" ", "Temperature 4", this->temperature4_sensor_); - LOG_SENSOR(" ", "Pump Speed 1", this->pump_speed1_sensor_); - LOG_SENSOR(" ", "Pump Speed 2", this->pump_speed2_sensor_); - LOG_SENSOR(" ", "Operating Hours 1", this->operating_hours1_sensor_); - LOG_SENSOR(" ", "Operating Hours 2", this->operating_hours2_sensor_); - LOG_SENSOR(" ", "Heat Quantity", this->heat_quantity_sensor_); - LOG_SENSOR(" ", "System Time", this->time_sensor_); - LOG_SENSOR(" ", "FW Version", this->version_sensor_); -} - -void DeltaSolBSPlusSensor::handle_message(std::vector &message) { - if (this->temperature1_sensor_ != nullptr) - this->temperature1_sensor_->publish_state(get_i16(message, 0) * 0.1f); - if (this->temperature2_sensor_ != nullptr) - this->temperature2_sensor_->publish_state(get_i16(message, 2) * 0.1f); - if (this->temperature3_sensor_ != nullptr) - this->temperature3_sensor_->publish_state(get_i16(message, 4) * 0.1f); - if (this->temperature4_sensor_ != nullptr) - this->temperature4_sensor_->publish_state(get_i16(message, 6) * 0.1f); - if (this->pump_speed1_sensor_ != nullptr) - this->pump_speed1_sensor_->publish_state(message[8]); - if (this->pump_speed2_sensor_ != nullptr) - this->pump_speed2_sensor_->publish_state(message[9]); - if (this->operating_hours1_sensor_ != nullptr) - this->operating_hours1_sensor_->publish_state(get_u16(message, 16)); - if (this->operating_hours2_sensor_ != nullptr) - this->operating_hours2_sensor_->publish_state(get_u16(message, 18)); - if (this->heat_quantity_sensor_ != nullptr) { - this->heat_quantity_sensor_->publish_state(get_u16(message, 20) + get_u16(message, 22) * 1000 + - get_u16(message, 24) * 1000000); - } - if (this->time_sensor_ != nullptr) - this->time_sensor_->publish_state(get_u16(message, 12)); - if (this->version_sensor_ != nullptr) - this->version_sensor_->publish_state(get_u16(message, 26) * 0.01f); -} - -void DeltaSolCSensor::dump_config() { - ESP_LOGCONFIG(TAG, "Deltasol C:"); - LOG_SENSOR(" ", "Temperature 1", this->temperature1_sensor_); - LOG_SENSOR(" ", "Temperature 2", this->temperature2_sensor_); - LOG_SENSOR(" ", "Temperature 3", this->temperature3_sensor_); - LOG_SENSOR(" ", "Temperature 4", this->temperature4_sensor_); - LOG_SENSOR(" ", "Pump Speed 1", this->pump_speed1_sensor_); - LOG_SENSOR(" ", "Pump Speed 2", this->pump_speed2_sensor_); - LOG_SENSOR(" ", "Operating Hours 1", this->operating_hours1_sensor_); - LOG_SENSOR(" ", "Operating Hours 2", this->operating_hours2_sensor_); - LOG_SENSOR(" ", "Heat Quantity", this->heat_quantity_sensor_); - LOG_SENSOR(" ", "System Time", this->time_sensor_); -} - -void DeltaSolCSensor::handle_message(std::vector &message) { - if (this->temperature1_sensor_ != nullptr) - this->temperature1_sensor_->publish_state(get_i16(message, 0) * 0.1f); - if (this->temperature2_sensor_ != nullptr) - this->temperature2_sensor_->publish_state(get_i16(message, 2) * 0.1f); - if (this->temperature3_sensor_ != nullptr) - this->temperature3_sensor_->publish_state(get_i16(message, 4) * 0.1f); - if (this->temperature4_sensor_ != nullptr) - this->temperature4_sensor_->publish_state(get_i16(message, 6) * 0.1f); - if (this->pump_speed1_sensor_ != nullptr) - this->pump_speed1_sensor_->publish_state(message[8]); - if (this->pump_speed2_sensor_ != nullptr) - this->pump_speed2_sensor_->publish_state(message[9]); - if (this->operating_hours1_sensor_ != nullptr) - this->operating_hours1_sensor_->publish_state(get_u16(message, 12)); - if (this->operating_hours2_sensor_ != nullptr) - this->operating_hours2_sensor_->publish_state(get_u16(message, 14)); - if (this->heat_quantity_sensor_ != nullptr) { - this->heat_quantity_sensor_->publish_state(get_u16(message, 16) + get_u16(message, 18) * 1000 + - get_u16(message, 20) * 1000000); - } - if (this->time_sensor_ != nullptr) - this->time_sensor_->publish_state(get_u16(message, 22)); -} - -void DeltaSolCS2Sensor::dump_config() { - ESP_LOGCONFIG(TAG, "Deltasol CS2:"); - LOG_SENSOR(" ", "Temperature 1", this->temperature1_sensor_); - LOG_SENSOR(" ", "Temperature 2", this->temperature2_sensor_); - LOG_SENSOR(" ", "Temperature 3", this->temperature3_sensor_); - LOG_SENSOR(" ", "Temperature 4", this->temperature4_sensor_); - LOG_SENSOR(" ", "Pump Speed", this->pump_speed_sensor_); - LOG_SENSOR(" ", "Operating Hours", this->operating_hours_sensor_); - LOG_SENSOR(" ", "Heat Quantity", this->heat_quantity_sensor_); - LOG_SENSOR(" ", "FW Version", this->version_sensor_); -} - -void DeltaSolCS2Sensor::handle_message(std::vector &message) { - if (this->temperature1_sensor_ != nullptr) - this->temperature1_sensor_->publish_state(get_i16(message, 0) * 0.1f); - if (this->temperature2_sensor_ != nullptr) - this->temperature2_sensor_->publish_state(get_i16(message, 2) * 0.1f); - if (this->temperature3_sensor_ != nullptr) - this->temperature3_sensor_->publish_state(get_i16(message, 4) * 0.1f); - if (this->temperature4_sensor_ != nullptr) - this->temperature4_sensor_->publish_state(get_i16(message, 6) * 0.1f); - if (this->pump_speed_sensor_ != nullptr) - this->pump_speed_sensor_->publish_state(message[12]); - if (this->operating_hours_sensor_ != nullptr) - this->operating_hours_sensor_->publish_state(get_u16(message, 14)); - if (this->heat_quantity_sensor_ != nullptr) - this->heat_quantity_sensor_->publish_state((get_u16(message, 26) << 16) + get_u16(message, 24)); - if (this->version_sensor_ != nullptr) - this->version_sensor_->publish_state(get_u16(message, 28) * 0.01f); -} - -void DeltaSolCSPlusSensor::dump_config() { - ESP_LOGCONFIG(TAG, "Deltasol CS Plus:"); - LOG_SENSOR(" ", "Temperature 1", this->temperature1_sensor_); - LOG_SENSOR(" ", "Temperature 2", this->temperature2_sensor_); - LOG_SENSOR(" ", "Temperature 3", this->temperature3_sensor_); - LOG_SENSOR(" ", "Temperature 4", this->temperature4_sensor_); - LOG_SENSOR(" ", "Temperature 5", this->temperature5_sensor_); - LOG_SENSOR(" ", "Pump Speed 1", this->pump_speed1_sensor_); - LOG_SENSOR(" ", "Pump Speed 2", this->pump_speed2_sensor_); - LOG_SENSOR(" ", "Operating Hours 1", this->operating_hours1_sensor_); - LOG_SENSOR(" ", "Operating Hours 2", this->operating_hours2_sensor_); - LOG_SENSOR(" ", "Heat Quantity", this->heat_quantity_sensor_); - LOG_SENSOR(" ", "System Time", this->time_sensor_); - LOG_SENSOR(" ", "FW Version", this->version_sensor_); - LOG_SENSOR(" ", "Flow Rate", this->flow_rate_sensor_); -} - -void DeltaSolCSPlusSensor::handle_message(std::vector &message) { - if (this->temperature1_sensor_ != nullptr) - this->temperature1_sensor_->publish_state(get_i16(message, 0) * 0.1f); - if (this->temperature2_sensor_ != nullptr) - this->temperature2_sensor_->publish_state(get_i16(message, 2) * 0.1f); - if (this->temperature3_sensor_ != nullptr) - this->temperature3_sensor_->publish_state(get_i16(message, 4) * 0.1f); - if (this->temperature4_sensor_ != nullptr) - this->temperature4_sensor_->publish_state(get_i16(message, 6) * 0.1f); - if (this->temperature5_sensor_ != nullptr) - this->temperature5_sensor_->publish_state(get_i16(message, 36) * 0.1f); - if (this->pump_speed1_sensor_ != nullptr) - this->pump_speed1_sensor_->publish_state(message[8]); - if (this->pump_speed2_sensor_ != nullptr) - this->pump_speed2_sensor_->publish_state(message[12]); - if (this->operating_hours1_sensor_ != nullptr) - this->operating_hours1_sensor_->publish_state(get_u16(message, 10)); - if (this->operating_hours2_sensor_ != nullptr) - this->operating_hours2_sensor_->publish_state(get_u16(message, 14)); - if (this->heat_quantity_sensor_ != nullptr) - this->heat_quantity_sensor_->publish_state((get_u16(message, 30) << 16) + get_u16(message, 28)); - if (this->time_sensor_ != nullptr) - this->time_sensor_->publish_state(get_u16(message, 12)); - if (this->version_sensor_ != nullptr) - this->version_sensor_->publish_state(get_u16(message, 26) * 0.01f); - if (this->flow_rate_sensor_ != nullptr) - this->flow_rate_sensor_->publish_state(get_u16(message, 38)); -} - -void VBusCustomSensor::dump_config() { - ESP_LOGCONFIG(TAG, "VBus Custom:"); - if (this->source_ == 0xffff) { - ESP_LOGCONFIG(TAG, " Source address: ANY"); - } else { - ESP_LOGCONFIG(TAG, " Source address: 0x%04x", this->source_); - } - if (this->dest_ == 0xffff) { - ESP_LOGCONFIG(TAG, " Dest address: ANY"); - } else { - ESP_LOGCONFIG(TAG, " Dest address: 0x%04x", this->dest_); - } - if (this->command_ == 0xffff) { - ESP_LOGCONFIG(TAG, " Command: ANY"); - } else { - ESP_LOGCONFIG(TAG, " Command: 0x%04x", this->command_); - } -} - -void VBusCustomSensor::handle_message(std::vector &message) { - if (this->message_handler_.has_value()) - (*this->message_handler_)(message); -} - -} // namespace vbus -} // namespace esphome diff --git a/components/vbus/sensor/vbus_sensor.h b/components/vbus/sensor/vbus_sensor.h deleted file mode 100644 index 15a83f1..0000000 --- a/components/vbus/sensor/vbus_sensor.h +++ /dev/null @@ -1,142 +0,0 @@ -#pragma once - -#include "../vbus.h" -#include "esphome/components/sensor/sensor.h" - -namespace esphome { -namespace vbus { - -using message_handler_t = std::function &)>; - -class DeltaSolBSPlusSensor : public VBusListener, public Component { - public: - void dump_config() override; - void set_temperature1_sensor(sensor::Sensor *sensor) { this->temperature1_sensor_ = sensor; } - void set_temperature2_sensor(sensor::Sensor *sensor) { this->temperature2_sensor_ = sensor; } - void set_temperature3_sensor(sensor::Sensor *sensor) { this->temperature3_sensor_ = sensor; } - void set_temperature4_sensor(sensor::Sensor *sensor) { this->temperature4_sensor_ = sensor; } - void set_pump_speed1_sensor(sensor::Sensor *sensor) { this->pump_speed1_sensor_ = sensor; } - void set_pump_speed2_sensor(sensor::Sensor *sensor) { this->pump_speed2_sensor_ = sensor; } - void set_operating_hours1_sensor(sensor::Sensor *sensor) { this->operating_hours1_sensor_ = sensor; } - void set_operating_hours2_sensor(sensor::Sensor *sensor) { this->operating_hours2_sensor_ = sensor; } - void set_heat_quantity_sensor(sensor::Sensor *sensor) { this->heat_quantity_sensor_ = sensor; } - void set_time_sensor(sensor::Sensor *sensor) { this->time_sensor_ = sensor; } - void set_version_sensor(sensor::Sensor *sensor) { this->version_sensor_ = sensor; } - - protected: - sensor::Sensor *temperature1_sensor_{nullptr}; - sensor::Sensor *temperature2_sensor_{nullptr}; - sensor::Sensor *temperature3_sensor_{nullptr}; - sensor::Sensor *temperature4_sensor_{nullptr}; - sensor::Sensor *pump_speed1_sensor_{nullptr}; - sensor::Sensor *pump_speed2_sensor_{nullptr}; - sensor::Sensor *operating_hours1_sensor_{nullptr}; - sensor::Sensor *operating_hours2_sensor_{nullptr}; - sensor::Sensor *heat_quantity_sensor_{nullptr}; - sensor::Sensor *time_sensor_{nullptr}; - sensor::Sensor *version_sensor_{nullptr}; - - void handle_message(std::vector &message) override; -}; - -class DeltaSolCSensor : public VBusListener, public Component { - public: - void dump_config() override; - void set_temperature1_sensor(sensor::Sensor *sensor) { this->temperature1_sensor_ = sensor; } - void set_temperature2_sensor(sensor::Sensor *sensor) { this->temperature2_sensor_ = sensor; } - void set_temperature3_sensor(sensor::Sensor *sensor) { this->temperature3_sensor_ = sensor; } - void set_temperature4_sensor(sensor::Sensor *sensor) { this->temperature4_sensor_ = sensor; } - void set_pump_speed1_sensor(sensor::Sensor *sensor) { this->pump_speed1_sensor_ = sensor; } - void set_pump_speed2_sensor(sensor::Sensor *sensor) { this->pump_speed2_sensor_ = sensor; } - void set_operating_hours1_sensor(sensor::Sensor *sensor) { this->operating_hours1_sensor_ = sensor; } - void set_operating_hours2_sensor(sensor::Sensor *sensor) { this->operating_hours2_sensor_ = sensor; } - void set_heat_quantity_sensor(sensor::Sensor *sensor) { this->heat_quantity_sensor_ = sensor; } - void set_time_sensor(sensor::Sensor *sensor) { this->time_sensor_ = sensor; } - - protected: - sensor::Sensor *temperature1_sensor_{nullptr}; - sensor::Sensor *temperature2_sensor_{nullptr}; - sensor::Sensor *temperature3_sensor_{nullptr}; - sensor::Sensor *temperature4_sensor_{nullptr}; - sensor::Sensor *pump_speed1_sensor_{nullptr}; - sensor::Sensor *pump_speed2_sensor_{nullptr}; - sensor::Sensor *operating_hours1_sensor_{nullptr}; - sensor::Sensor *operating_hours2_sensor_{nullptr}; - sensor::Sensor *heat_quantity_sensor_{nullptr}; - sensor::Sensor *time_sensor_{nullptr}; - - void handle_message(std::vector &message) override; -}; - -class DeltaSolCS2Sensor : public VBusListener, public Component { - public: - void dump_config() override; - void set_temperature1_sensor(sensor::Sensor *sensor) { this->temperature1_sensor_ = sensor; } - void set_temperature2_sensor(sensor::Sensor *sensor) { this->temperature2_sensor_ = sensor; } - void set_temperature3_sensor(sensor::Sensor *sensor) { this->temperature3_sensor_ = sensor; } - void set_temperature4_sensor(sensor::Sensor *sensor) { this->temperature4_sensor_ = sensor; } - void set_pump_speed_sensor(sensor::Sensor *sensor) { this->pump_speed_sensor_ = sensor; } - void set_operating_hours_sensor(sensor::Sensor *sensor) { this->operating_hours_sensor_ = sensor; } - void set_heat_quantity_sensor(sensor::Sensor *sensor) { this->heat_quantity_sensor_ = sensor; } - void set_version_sensor(sensor::Sensor *sensor) { this->version_sensor_ = sensor; } - - protected: - sensor::Sensor *temperature1_sensor_{nullptr}; - sensor::Sensor *temperature2_sensor_{nullptr}; - sensor::Sensor *temperature3_sensor_{nullptr}; - sensor::Sensor *temperature4_sensor_{nullptr}; - sensor::Sensor *pump_speed_sensor_{nullptr}; - sensor::Sensor *operating_hours_sensor_{nullptr}; - sensor::Sensor *heat_quantity_sensor_{nullptr}; - sensor::Sensor *version_sensor_{nullptr}; - - void handle_message(std::vector &message) override; -}; - -class DeltaSolCSPlusSensor : public VBusListener, public Component { - public: - void dump_config() override; - void set_temperature1_sensor(sensor::Sensor *sensor) { this->temperature1_sensor_ = sensor; } - void set_temperature2_sensor(sensor::Sensor *sensor) { this->temperature2_sensor_ = sensor; } - void set_temperature3_sensor(sensor::Sensor *sensor) { this->temperature3_sensor_ = sensor; } - void set_temperature4_sensor(sensor::Sensor *sensor) { this->temperature4_sensor_ = sensor; } - void set_temperature5_sensor(sensor::Sensor *sensor) { this->temperature5_sensor_ = sensor; } - void set_pump_speed1_sensor(sensor::Sensor *sensor) { this->pump_speed1_sensor_ = sensor; } - void set_pump_speed2_sensor(sensor::Sensor *sensor) { this->pump_speed2_sensor_ = sensor; } - void set_operating_hours1_sensor(sensor::Sensor *sensor) { this->operating_hours1_sensor_ = sensor; } - void set_operating_hours2_sensor(sensor::Sensor *sensor) { this->operating_hours2_sensor_ = sensor; } - void set_heat_quantity_sensor(sensor::Sensor *sensor) { this->heat_quantity_sensor_ = sensor; } - void set_time_sensor(sensor::Sensor *sensor) { this->time_sensor_ = sensor; } - void set_version_sensor(sensor::Sensor *sensor) { this->version_sensor_ = sensor; } - void set_flow_rate_sensor(sensor::Sensor *sensor) { this->flow_rate_sensor_ = sensor; } - - protected: - sensor::Sensor *temperature1_sensor_{nullptr}; - sensor::Sensor *temperature2_sensor_{nullptr}; - sensor::Sensor *temperature3_sensor_{nullptr}; - sensor::Sensor *temperature4_sensor_{nullptr}; - sensor::Sensor *temperature5_sensor_{nullptr}; - sensor::Sensor *pump_speed1_sensor_{nullptr}; - sensor::Sensor *pump_speed2_sensor_{nullptr}; - sensor::Sensor *operating_hours1_sensor_{nullptr}; - sensor::Sensor *operating_hours2_sensor_{nullptr}; - sensor::Sensor *heat_quantity_sensor_{nullptr}; - sensor::Sensor *time_sensor_{nullptr}; - sensor::Sensor *version_sensor_{nullptr}; - sensor::Sensor *flow_rate_sensor_{nullptr}; - - void handle_message(std::vector &message) override; -}; - -class VBusCustomSensor : public VBusListener, public Component { - public: - void dump_config() override; - void set_message_handler(message_handler_t &&handler) { this->message_handler_ = handler; }; - - protected: - optional message_handler_{}; - void handle_message(std::vector &message) override; -}; - -} // namespace vbus -} // namespace esphome diff --git a/components/vbus/vbus.cpp b/components/vbus/vbus.cpp deleted file mode 100644 index c975889..0000000 --- a/components/vbus/vbus.cpp +++ /dev/null @@ -1,124 +0,0 @@ -#include "vbus.h" -#include "esphome/core/helpers.h" -#include "esphome/core/log.h" - -namespace esphome { -namespace vbus { - -static const char *const TAG = "vbus"; - -void VBus::dump_config() { - ESP_LOGCONFIG(TAG, "VBus:"); - check_uart_settings(9600); -} - -static void septet_spread(uint8_t *data, int start, int count, uint8_t septet) { - for (int i = 0; i < count; i++, septet >>= 1) { - if (septet & 1) - data[start + i] |= 0x80; - } -} - -static bool checksum(const uint8_t *data, int start, int count) { - uint8_t csum = 0x7f; - for (int i = 0; i < count; i++) - csum = (csum - data[start + i]) & 0x7f; - return csum == 0; -} - -void VBus::loop() { - if (!available()) - return; - - while (available()) { - uint8_t c; - read_byte(&c); - - if (c == 0xaa) { - this->state_ = 1; - this->buffer_.clear(); - continue; - } - if (c & 0x80) { - this->state_ = 0; - continue; - } - if (this->state_ == 0) - continue; - - if (this->state_ == 1) { - this->buffer_.push_back(c); - if (this->buffer_.size() == 7) { - this->protocol_ = this->buffer_[4]; - this->source_ = (this->buffer_[3] << 8) + this->buffer_[2]; - this->dest_ = (this->buffer_[1] << 8) + this->buffer_[0]; - this->command_ = (this->buffer_[6] << 8) + this->buffer_[5]; - } - if ((this->protocol_ == 0x20) && (this->buffer_.size() == 15)) { - this->state_ = 0; - if (!checksum(this->buffer_.data(), 0, 15)) { - ESP_LOGE(TAG, "P2 checksum failed"); - continue; - } - septet_spread(this->buffer_.data(), 7, 6, this->buffer_[13]); - uint16_t id = (this->buffer_[8] << 8) + this->buffer_[7]; - uint32_t value = - (this->buffer_[12] << 24) + (this->buffer_[11] << 16) + (this->buffer_[10] << 8) + this->buffer_[9]; - ESP_LOGV(TAG, "P1 C%04x %04x->%04x: %04x %04x (%d)", this->command_, this->source_, this->dest_, id, value, - value); - } else if ((this->protocol_ == 0x10) && (this->buffer_.size() == 9)) { - if (!checksum(this->buffer_.data(), 0, 9)) { - ESP_LOGE(TAG, "P1 checksum failed"); - this->state_ = 0; - continue; - } - this->frames_ = this->buffer_[7]; - if (this->frames_) { - this->state_ = 2; - this->cframe_ = 0; - this->fbcount_ = 0; - this->buffer_.clear(); - } else { - this->state_ = 0; - ESP_LOGD(TAG, "P1 empty message"); - } - } - continue; - } - - if (this->state_ == 2) { - this->fbytes_[this->fbcount_++] = c; - if (this->fbcount_ < 6) - continue; - this->fbcount_ = 0; - if (!checksum(this->fbytes_, 0, 6)) { - ESP_LOGE(TAG, "frame checksum failed"); - continue; - } - septet_spread(this->fbytes_, 0, 4, this->fbytes_[4]); - for (int i = 0; i < 4; i++) - this->buffer_.push_back(this->fbytes_[i]); - if (++this->cframe_ < this->frames_) - continue; - ESP_LOGV(TAG, "P2 C%04x %04x->%04x: %s", this->command_, this->source_, this->dest_, - format_hex(this->buffer_).c_str()); - for (auto &listener : this->listeners_) - listener->on_message(this->command_, this->source_, this->dest_, this->buffer_); - this->state_ = 0; - continue; - } - } -} - -void VBusListener::on_message(uint16_t command, uint16_t source, uint16_t dest, std::vector &message) { - if ((this->command_ != 0xffff) && (this->command_ != command)) - return; - if ((this->source_ != 0xffff) && (this->source_ != source)) - return; - if ((this->dest_ != 0xffff) && (this->dest_ != dest)) - return; - this->handle_message(message); -} - -} // namespace vbus -} // namespace esphome diff --git a/components/vbus/vbus.h b/components/vbus/vbus.h deleted file mode 100644 index 7bddd3f..0000000 --- a/components/vbus/vbus.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include "esphome/core/component.h" -#include "esphome/components/uart/uart.h" - -namespace esphome { -namespace vbus { - -class VBus; - -class VBusListener { - public: - void set_command(uint16_t command) { this->command_ = command; } - void set_source(uint16_t source) { this->source_ = source; } - void set_dest(uint16_t dest) { this->dest_ = dest; } - - void on_message(uint16_t command, uint16_t source, uint16_t dest, std::vector &message); - - protected: - uint16_t command_{0xffff}; - uint16_t source_{0xffff}; - uint16_t dest_{0xffff}; - - virtual void handle_message(std::vector &message) = 0; -}; - -class VBus : public uart::UARTDevice, public Component { - public: - void dump_config() override; - void loop() override; - float get_setup_priority() const override { return setup_priority::DATA; } - - void register_listener(VBusListener *listener) { this->listeners_.push_back(listener); } - - protected: - int state_{0}; - std::vector buffer_; - uint8_t protocol_; - uint16_t source_; - uint16_t dest_; - uint16_t command_; - uint8_t frames_; - uint8_t cframe_; - uint8_t fbytes_[6]; - int fbcount_; - std::vector listeners_{}; -}; - -} // namespace vbus -} // namespace esphome diff --git a/components/wiegand/README.md b/components/wiegand/README.md deleted file mode 100644 index 40cd05a..0000000 --- a/components/wiegand/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# This component has been merged to esphome: - -# Wiegard card reader - -Reads a card or key presses from a Wiegand interface. -You must also import the `key_provider` component. - -If you want automatic handling for multiple keys, e.g. PIN entry, use the `key_collector` component. - -Example: -```yaml -wiegand: - - id: reader - d0: 4 - d1: 5 - on_tag: - - lambda: ESP_LOGD("TEST", "received tag %s", x.c_str()); - on_raw: - - lambda: ESP_LOGD("TEST", "received raw %d bits, value %llx", bits, value); - on_key: - - lambda: ESP_LOGD("TEST", "received key %d", x); -``` - diff --git a/components/wiegand/__init__.py b/components/wiegand/__init__.py deleted file mode 100644 index 9779b36..0000000 --- a/components/wiegand/__init__.py +++ /dev/null @@ -1,75 +0,0 @@ -import esphome.codegen as cg -import esphome.config_validation as cv -from esphome import pins, automation -from esphome.components import key_provider -from esphome.const import CONF_ID, CONF_KEY, CONF_ON_TAG, CONF_TRIGGER_ID - -AUTO_LOAD = [ "key_provider" ] - -MULTI_CONF = True - -wiegand_ns = cg.esphome_ns.namespace('wiegand') - -Wiegand = wiegand_ns.class_('Wiegand', key_provider.KeyProvider, cg.Component) -WiegandTagTrigger = wiegand_ns.class_( - "WiegandTagTrigger", automation.Trigger.template(cg.std_string) -) -WiegandRawTrigger = wiegand_ns.class_( - "WiegandRawTrigger", automation.Trigger.template(cg.uint8, cg.uint64) -) -WiegandKeyTrigger = wiegand_ns.class_( - "WiegandKeyTrigger", automation.Trigger.template(cg.uint8) -) - -CONF_D0 = "d0" -CONF_D1 = "d1" -CONF_ON_KEY = "on_key" -CONF_ON_RAW = "on_raw" - -CONFIG_SCHEMA = cv.Schema( - { - cv.GenerateID(): cv.declare_id(Wiegand), - cv.Required(CONF_D0): pins.internal_gpio_input_pin_schema, - cv.Required(CONF_D1): pins.internal_gpio_input_pin_schema, - cv.Optional(CONF_ON_TAG): automation.validate_automation( - { - cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(WiegandTagTrigger), - } - ), - cv.Optional(CONF_ON_RAW): automation.validate_automation( - { - cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(WiegandRawTrigger), - } - ), - cv.Optional(CONF_ON_KEY): automation.validate_automation( - { - cv.GenerateID(CONF_TRIGGER_ID): cv.declare_id(WiegandKeyTrigger), - } - ), - } -) - - -async def to_code(config): - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - pin = await cg.gpio_pin_expression(config[CONF_D0]) - cg.add(var.set_d0_pin(pin)) - pin = await cg.gpio_pin_expression(config[CONF_D1]) - cg.add(var.set_d1_pin(pin)) - - for conf in config.get(CONF_ON_TAG, []): - trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID]) - cg.add(var.register_tag_trigger(trigger)) - await automation.build_automation(trigger, [(cg.std_string, "x")], conf) - - for conf in config.get(CONF_ON_RAW, []): - trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID]) - cg.add(var.register_raw_trigger(trigger)) - await automation.build_automation(trigger, [(cg.uint8, "bits"), (cg.uint64, "value")], conf) - - for conf in config.get(CONF_ON_KEY, []): - trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID]) - cg.add(var.register_key_trigger(trigger)) - await automation.build_automation(trigger, [(cg.uint8, "x")], conf) - diff --git a/components/wiegand/wiegand.cpp b/components/wiegand/wiegand.cpp deleted file mode 100644 index 9e8df9c..0000000 --- a/components/wiegand/wiegand.cpp +++ /dev/null @@ -1,115 +0,0 @@ -#include "wiegand.h" -#include "esphome/core/log.h" -#include "esphome/core/helpers.h" - -namespace esphome { -namespace wiegand { - -static const char *TAG = "wiegand.text_sensor"; -static const char *KEYS = "0123456789*#"; - -void IRAM_ATTR HOT WiegandStore::d0_gpio_intr(WiegandStore *arg) { - if (arg->d0.digital_read()) - return; - arg->count++; - arg->value <<= 1; - arg->last_bit_time = millis(); - arg->done = false; -} - -void IRAM_ATTR HOT WiegandStore::d1_gpio_intr(WiegandStore *arg) { - if (arg->d1.digital_read()) - return; - arg->count++; - arg->value = (arg->value << 1) | 1; - arg->last_bit_time = millis(); - arg->done = false; -} - -void Wiegand::setup() { - this->d0_pin_->setup(); - this->store_.d0 = this->d0_pin_->to_isr(); - this->d1_pin_->setup(); - this->store_.d1 = this->d1_pin_->to_isr(); - this->d0_pin_->attach_interrupt(WiegandStore::d0_gpio_intr, &this->store_, gpio::INTERRUPT_FALLING_EDGE); - this->d1_pin_->attach_interrupt(WiegandStore::d1_gpio_intr, &this->store_, gpio::INTERRUPT_FALLING_EDGE); -} - -bool check_eparity(uint64_t value, int start, int length) { - int parity = 0; - uint64_t mask = 1LL << start; - for (int i = 0; i < length; i++, mask <<= 1) - if (value & mask) - parity++; - return !(parity & 1); -} - -bool check_oparity(uint64_t value, int start, int length) { - int parity = 0; - uint64_t mask = 1LL << start; - for (int i = 0; i < length; i++, mask <<= 1) - if (value & mask) - parity++; - return parity & 1; -} - -void Wiegand::loop() { - if (this->store_.done) - return; - if (millis() - this->store_.last_bit_time < 100) - return; - uint8_t count = this->store_.count; - uint64_t value = this->store_.value; - this->store_.count = 0; - this->store_.value = 0; - this->store_.done = true; - ESP_LOGV(TAG, "received %d-bit value: %llx", count, value); - for (auto *trigger : this->raw_triggers_) - trigger->trigger(count, value); - if (count == 26) { - std::string tag = to_string((value >> 1) & 0xffffff); - ESP_LOGD(TAG, "received 26-bit tag: %s", tag.c_str()); - if (!check_eparity(value, 13, 13) || !check_oparity(value, 0, 13)) { - ESP_LOGW(TAG, "invalid parity"); - return; - } - for (auto *trigger : this->tag_triggers_) - trigger->trigger(tag); - } else if (count == 34) { - std::string tag = to_string((value >> 1) & 0xffffffff); - ESP_LOGD(TAG, "received 34-bit tag: %s", tag.c_str()); - if (!check_eparity(value, 17, 17) || !check_oparity(value, 0, 17)) { - ESP_LOGW(TAG, "invalid parity"); - return; - } - for (auto *trigger : this->tag_triggers_) - trigger->trigger(tag); - } else if (count == 37) { - std::string tag = to_string((value >> 1) & 0x7ffffffff); - ESP_LOGD(TAG, "received 37-bit tag: %s", tag.c_str()); - if (!check_eparity(value, 18, 19) || !check_oparity(value, 0, 19)) { - ESP_LOGW(TAG, "invalid parity"); - return; - } - for (auto *trigger : this->tag_triggers_) - trigger->trigger(tag); - } else if (count == 4) { - for (auto *trigger : this->key_triggers_) - trigger->trigger(value); - if (value < 12) { - uint8_t key = KEYS[value]; - this->send_key_(key); - } - } else { - ESP_LOGD(TAG, "received unknown %d-bit value: %llx", count, value); - } -} - -void Wiegand::dump_config() { - ESP_LOGCONFIG(TAG, "Wiegand reader:"); - LOG_PIN(" D0 pin: ", this->d0_pin_); - LOG_PIN(" D1 pin: ", this->d1_pin_); -} - -} // namespace wiegand -} // namespace esphome diff --git a/components/wiegand/wiegand.h b/components/wiegand/wiegand.h deleted file mode 100644 index 6ff0260..0000000 --- a/components/wiegand/wiegand.h +++ /dev/null @@ -1,57 +0,0 @@ -#pragma once - -#include "esphome/components/key_provider/key_provider.h" -#include "esphome/core/automation.h" -#include "esphome/core/component.h" -#include "esphome/core/hal.h" - -namespace esphome { -namespace wiegand { - -class Wiegand; - -struct WiegandStore { - ISRInternalGPIOPin d0; - ISRInternalGPIOPin d1; - volatile uint64_t value{0}; - volatile uint32_t last_bit_time{0}; - volatile bool done{true}; - volatile uint8_t count{0}; - - static void d0_gpio_intr(WiegandStore *arg); - static void d1_gpio_intr(WiegandStore *arg); -}; - -class WiegandTagTrigger : public Trigger { -}; - -class WiegandRawTrigger : public Trigger { -}; - -class WiegandKeyTrigger : public Trigger { -}; - -class Wiegand : public key_provider::KeyProvider, public Component { - public: - float get_setup_priority() const override { return setup_priority::HARDWARE; } - void setup() override; - void loop() override; - void dump_config() override; - - void set_d0_pin(InternalGPIOPin *pin) { this->d0_pin_ = pin; }; - void set_d1_pin(InternalGPIOPin *pin) { this->d1_pin_ = pin; }; - void register_tag_trigger(WiegandTagTrigger *trig) { this->tag_triggers_.push_back(trig); } - void register_raw_trigger(WiegandRawTrigger *trig) { this->raw_triggers_.push_back(trig); } - void register_key_trigger(WiegandKeyTrigger *trig) { this->key_triggers_.push_back(trig); } - - protected: - InternalGPIOPin *d0_pin_; - InternalGPIOPin *d1_pin_; - WiegandStore store_{}; - std::vector tag_triggers_; - std::vector raw_triggers_; - std::vector key_triggers_; -}; - -} // namespace wiegand -} // namespace esphome