diff --git a/esphome/components/optolink/optolink.cpp b/esphome/components/optolink/optolink.cpp index efe2c90b1f..d421bcc952 100644 --- a/esphome/components/optolink/optolink.cpp +++ b/esphome/components/optolink/optolink.cpp @@ -78,6 +78,21 @@ size_t Optolink::write(uint8_t ch) { return 1; } +void OptolinkDeviceInfoSensor::setup() { + datapoint_ = new Datapoint(get_name().c_str(), "optolink", 0x00f8, false); + datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) { + uint32_t value = dp_value.getU32(); + ESP_LOGI(TAG, "recieved data for datapoint %s: %d", dp.getName(), value); + uint8_t *bytes = (uint8_t *) &value; + uint16_t tmp = esphome::byteswap(*((uint16_t *) bytes)); + std::string geraetekennung = esphome::format_hex_pretty(&tmp, 1); + std::string hardware_revision = esphome::format_hex_pretty((uint8_t *) bytes + 2, 1); + std::string software_index = esphome::format_hex_pretty((uint8_t *) bytes + 3, 1); + publish_state("Device ID: " + geraetekennung + "|Hardware Revision: " + hardware_revision + + "|Software Index: " + software_index); + }); +} + } // namespace optolink } // namespace esphome diff --git a/esphome/components/optolink/optolink.h b/esphome/components/optolink/optolink.h index 7389f60126..b7aaefab7c 100644 --- a/esphome/components/optolink/optolink.h +++ b/esphome/components/optolink/optolink.h @@ -39,6 +39,41 @@ class Optolink : public esphome::Component, public Print { std::string get_error() { return error_; } }; +class OptolinkStateSensor : public esphome::text_sensor::TextSensor, public esphome::PollingComponent { + public: + OptolinkStateSensor(std::string name, Optolink *optolink) { + optolink_ = optolink; + set_name(name.c_str()); + set_update_interval(1000); + set_entity_category(esphome::ENTITY_CATEGORY_DIAGNOSTIC); + } + + protected: + void setup() override{}; + void update() override { publish_state(optolink_->get_error()); } + + private: + Optolink *optolink_; +}; + +class OptolinkDeviceInfoSensor : public esphome::text_sensor::TextSensor, public esphome::PollingComponent { + public: + OptolinkDeviceInfoSensor(const std::string &name, Optolink *optolink) { + optolink_ = optolink; + set_name(name.c_str()); + set_update_interval(1800000); + set_entity_category(esphome::ENTITY_CATEGORY_DIAGNOSTIC); + } + + protected: + void setup() override; + void update() override { optolink_->read_value(datapoint_); } + + private: + Optolink *optolink_; + IDatapoint *datapoint_; +}; + } // namespace optolink } // namespace esphome diff --git a/esphome/components/optolink/text_sensor/__init__.py b/esphome/components/optolink/text_sensor/__init__.py index 56110527a6..31556adb37 100644 --- a/esphome/components/optolink/text_sensor/__init__.py +++ b/esphome/components/optolink/text_sensor/__init__.py @@ -29,7 +29,7 @@ DAY_OF_WEEK = { "SATURDAY": 5, "SUNDAY": 6, } -CONF_DOW = "day_of_week" +CONF_DAY_OF_WEEK = "day_of_week" OptolinkTextSensor = optolink_ns.class_( "OptolinkTextSensor", text_sensor.TextSensor, cg.PollingComponent @@ -55,15 +55,15 @@ def check_dow(): def validator_(config): if ( config[CONF_MODE] in ["DAY_SCHEDULE", "DAY_SCHEDULE_SYNCHRONIZED"] - and CONF_DOW not in config + and CONF_DAY_OF_WEEK not in config ): - raise cv.Invalid(f"{CONF_DOW} is required in mode DAY_SCHEDULE") + raise cv.Invalid(f"{CONF_DAY_OF_WEEK} is required in mode DAY_SCHEDULE") if ( config[CONF_MODE] not in ["DAY_SCHEDULE", "DAY_SCHEDULE_SYNCHRONIZED"] - and CONF_DOW in config + and CONF_DAY_OF_WEEK in config ): raise cv.Invalid( - f"{CONF_DOW} is only allowed in mode DAY_SCHEDULE or DAY_SCHEDULE_SYNCHRONIZED" + f"{CONF_DAY_OF_WEEK} is only allowed in mode DAY_SCHEDULE or DAY_SCHEDULE_SYNCHRONIZED" ) return config @@ -97,7 +97,7 @@ CONFIG_SCHEMA = cv.All( { cv.Optional(CONF_MODE, default="MAP"): cv.enum(MODE, upper=True), cv.Optional(CONF_BYTES): cv.int_range(min=1, max=9), - cv.Optional(CONF_DOW): cv.enum(DAY_OF_WEEK, upper=True), + cv.Optional(CONF_DAY_OF_WEEK): cv.enum(DAY_OF_WEEK, upper=True), cv.Optional(CONF_ENTITY_ID): cv.entity_id, } ) @@ -120,7 +120,7 @@ async def to_code(config): cg.add(var.set_div_ratio(config[CONF_DIV_RATIO])) if CONF_BYTES in config: cg.add(var.set_bytes(config[CONF_BYTES])) - if CONF_DOW in config: - cg.add(var.set_day_of_week(config[CONF_DOW])) + if CONF_DAY_OF_WEEK in config: + cg.add(var.set_day_of_week(config[CONF_DAY_OF_WEEK])) if CONF_ENTITY_ID in config: cg.add(var.set_entity_id(config[CONF_ENTITY_ID])) diff --git a/esphome/components/optolink/text_sensor/optolink_device_info_sensor.cpp b/esphome/components/optolink/text_sensor/optolink_device_info_sensor.cpp deleted file mode 100644 index 9de361841f..0000000000 --- a/esphome/components/optolink/text_sensor/optolink_device_info_sensor.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifdef USE_ARDUINO - -#include "esphome/core/log.h" -#include "optolink_device_info_sensor.h" - -namespace esphome { -namespace optolink { - -static const char *const TAG = "optolink.text_sensor"; - -void OptolinkDeviceInfoSensor::setup() { - datapoint_ = new Datapoint(get_name().c_str(), "optolink", 0x00f8, false); - datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) { - uint32_t value = dp_value.getU32(); - ESP_LOGI(TAG, "recieved data for datapoint %s: %d", dp.getName(), value); - uint8_t *bytes = (uint8_t *) &value; - uint16_t tmp = esphome::byteswap(*((uint16_t *) bytes)); - std::string geraetekennung = esphome::format_hex_pretty(&tmp, 1); - std::string hardware_revision = esphome::format_hex_pretty((uint8_t *) bytes + 2, 1); - std::string software_index = esphome::format_hex_pretty((uint8_t *) bytes + 3, 1); - publish_state("Device ID: " + geraetekennung + "|Hardware Revision: " + hardware_revision + - "|Software Index: " + software_index); - }); -} -} // namespace optolink -} // namespace esphome - -#endif diff --git a/esphome/components/optolink/text_sensor/optolink_device_info_sensor.h b/esphome/components/optolink/text_sensor/optolink_device_info_sensor.h deleted file mode 100644 index 73ce0cc326..0000000000 --- a/esphome/components/optolink/text_sensor/optolink_device_info_sensor.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once - -#ifdef USE_ARDUINO - -#include "esphome/components/text_sensor/text_sensor.h" -#include "../optolink.h" -#include "../optolink_sensor_base.h" -#include "VitoWiFi.h" - -namespace esphome { -namespace optolink { - -class OptolinkDeviceInfoSensor : public esphome::text_sensor::TextSensor, public esphome::PollingComponent { - public: - OptolinkDeviceInfoSensor(const std::string &name, Optolink *optolink) { - optolink_ = optolink; - set_name(name.c_str()); - set_update_interval(1800000); - set_entity_category(esphome::ENTITY_CATEGORY_DIAGNOSTIC); - } - - protected: - void setup() override; - void update() override { optolink_->read_value(datapoint_); } - - private: - Optolink *optolink_; - IDatapoint *datapoint_; -}; - -} // namespace optolink -} // namespace esphome - -#endif diff --git a/esphome/components/optolink/text_sensor/optolink_state_sensor.h b/esphome/components/optolink/text_sensor/optolink_state_sensor.h deleted file mode 100644 index 0d67602b68..0000000000 --- a/esphome/components/optolink/text_sensor/optolink_state_sensor.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#ifdef USE_ARDUINO - -#include "esphome/components/text_sensor/text_sensor.h" -#include "../optolink.h" -#include "../optolink_sensor_base.h" -#include "VitoWiFi.h" - -namespace esphome { -namespace optolink { - -class OptolinkStateSensor : public esphome::text_sensor::TextSensor, public esphome::PollingComponent { - public: - OptolinkStateSensor(std::string name, Optolink *optolink) { - optolink_ = optolink; - set_name(name.c_str()); - set_update_interval(1000); - set_entity_category(esphome::ENTITY_CATEGORY_DIAGNOSTIC); - } - - protected: - void setup() override{}; - void update() override { publish_state(optolink_->get_error()); } - - private: - Optolink *optolink_; -}; -} // namespace optolink -} // namespace esphome - -#endif diff --git a/tests/test1.yaml b/tests/test1.yaml index 67552f46df..a82cc38945 100644 --- a/tests/test1.yaml +++ b/tests/test1.yaml @@ -3395,11 +3395,6 @@ text_sensor: tag_name: OPTARIF name: optarif teleinfo_id: myteleinfo - - platform: optolink - name: Error history 1 - address: 0x7590 - bytes: 9 - raw: true - platform: ld2410 version: name: "presenece sensor version"