diff --git a/esphome/components/optolink/__init__.py b/esphome/components/optolink/__init__.py index 1944fd57a3..6359dbe64e 100644 --- a/esphome/components/optolink/__init__.py +++ b/esphome/components/optolink/__init__.py @@ -19,6 +19,8 @@ MULTI_CONF = False CONF_DEVICE_INFO = "device_info" optolink_ns = cg.esphome_ns.namespace("optolink") +CONF_OPTOLINK_ID = "optolink_id" + OptolinkComponent = optolink_ns.class_("Optolink", cg.Component) StateSensor = optolink_ns.class_( "OptolinkStateSensor", ts.TextSensor, cg.PollingComponent diff --git a/esphome/components/optolink/binary_sensor.py b/esphome/components/optolink/binary_sensor.py index 57f51f2c3e..f55b9c6d16 100644 --- a/esphome/components/optolink/binary_sensor.py +++ b/esphome/components/optolink/binary_sensor.py @@ -3,12 +3,11 @@ import esphome.codegen as cg import esphome.config_validation as cv from esphome.components import binary_sensor from esphome.const import CONF_ID, CONF_ADDRESS, CONF_UPDATE_INTERVAL -from . import optolink_ns, OptolinkComponent +from . import OptolinkComponent, optolink_ns, CONF_OPTOLINK_ID OptolinkBinarySensor = optolink_ns.class_( "OptolinkBinarySensor", binary_sensor.BinarySensor, cg.PollingComponent ) -CONF_OPTOLINK_ID = "optolink_id" CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(OptolinkBinarySensor).extend( { cv.GenerateID(CONF_OPTOLINK_ID): cv.use_id(OptolinkComponent), diff --git a/esphome/components/optolink/number.py b/esphome/components/optolink/number.py index 2de32e186a..2f4802cd9b 100644 --- a/esphome/components/optolink/number.py +++ b/esphome/components/optolink/number.py @@ -2,7 +2,6 @@ from esphome import core import esphome.codegen as cg import esphome.config_validation as cv from esphome.components import number -from esphome.components.optolink.sensor import SENSOR_BASE_SCHEMA from esphome.const import ( CONF_ADDRESS, CONF_BYTES, @@ -13,13 +12,13 @@ from esphome.const import ( CONF_STEP, CONF_UPDATE_INTERVAL, ) -from . import OptolinkComponent, optolink_ns +from .sensor import SENSOR_BASE_SCHEMA +from . import OptolinkComponent, optolink_ns, CONF_OPTOLINK_ID OptolinkNumber = optolink_ns.class_( "OptolinkNumber", number.Number, cg.PollingComponent ) -CONF_OPTOLINK_ID = "optolink_id" CONFIG_SCHEMA = ( number.NUMBER_SCHEMA.extend( { diff --git a/esphome/components/optolink/optolink.cpp b/esphome/components/optolink/optolink.cpp index 3fbad9732d..b2081831ea 100644 --- a/esphome/components/optolink/optolink.cpp +++ b/esphome/components/optolink/optolink.cpp @@ -1,13 +1,19 @@ #include "esphome/core/defines.h" -#include "esphome/components/optolink/optolink.h" -#include +#include "optolink.h" +#include "VitoWiFi.h" -VitoWiFiClass VitoWiFi; +#if defined(VITOWIFI_PROTOCOL) +// NOLINTNEXTLINE +VitoWiFiClass VitoWiFi; // VITOWIFI_PROTOCOL always is set +#else +// NOLINTNEXTLINE +VitoWiFiClass VitoWiFi; // this is not really a fallback but dedicated to clang-lint +#endif namespace esphome { namespace optolink { -void Optolink::_comm() { +void Optolink::comm_() { ESP_LOGD("Optolink", "enter _comm"); VitoWiFi.readAll(); ESP_LOGD("Optolink", "exit _comm"); @@ -32,11 +38,11 @@ void Optolink::setup() { void Optolink::loop() { VitoWiFi.loop(); } -void Optolink::set_error(const std::string &format, ...) { +void Optolink::set_error(const char *format, ...) { va_list args; va_start(args, format); char buffer[128]; - size_t n = std::vsnprintf(buffer, sizeof(buffer), format.c_str(), args); + std::vsnprintf(buffer, sizeof(buffer), format, args); va_end(args); error_ = buffer; @@ -49,12 +55,12 @@ void Optolink::read_value(IDatapoint *datapoint) { } } -void Optolink::write_value(IDatapoint *datapoint, DPValue dpValue) { +void Optolink::write_value(IDatapoint *datapoint, DPValue dp_value) { if (datapoint != nullptr) { char buffer[64]; - dpValue.getString(buffer, sizeof(buffer)); + dp_value.getString(buffer, sizeof(buffer)); ESP_LOGI("Optolink", " write value %s of datapoint %s", buffer, datapoint->getName()); - VitoWiFi.writeDatapoint(*datapoint, dpValue); + VitoWiFi.writeDatapoint(*datapoint, dp_value); } } diff --git a/esphome/components/optolink/optolink.h b/esphome/components/optolink/optolink.h old mode 100755 new mode 100644 index 3e64c62de4..fe4eb396cd --- a/esphome/components/optolink/optolink.h +++ b/esphome/components/optolink/optolink.h @@ -4,19 +4,11 @@ #include "esphome/components/sensor/sensor.h" #include "esphome/components/binary_sensor/binary_sensor.h" #include "esphome/components/text_sensor/text_sensor.h" -#include - -using namespace esphome; -using namespace sensor; -using namespace binary_sensor; -using namespace text_sensor; +#include "VitoWiFi.h" namespace esphome { namespace optolink { -// '00' ='WW' '01' ='RED' '02' ='NORM' '03' ='H+WW' '04' ='H+WW FS' '05' ='ABSCHALT' - -//===================================================================================================================== class Optolink : public esphome::Component, public Print { protected: std::string error_ = "OK"; @@ -25,7 +17,7 @@ class Optolink : public esphome::Component, public Print { int rx_pin_; int tx_pin_; - void _comm(); + void comm_(); public: void setup() override; @@ -38,10 +30,10 @@ class Optolink : public esphome::Component, public Print { void set_rx_pin(int rx_pin) { rx_pin_ = rx_pin; } void set_tx_pin(int tx_pin) { tx_pin_ = tx_pin; } - void write_value(IDatapoint *datapoint, DPValue dpValue); + void write_value(IDatapoint *datapoint, DPValue dp_value); void read_value(IDatapoint *datapoint); - void set_error(const std::string &format, ...); + void set_error(const char *format, ...); std::string get_error() { return error_; } }; diff --git a/esphome/components/optolink/optolink_binary_sensor.h b/esphome/components/optolink/optolink_binary_sensor.h index 22d8dd5878..1aa20b9208 100644 --- a/esphome/components/optolink/optolink_binary_sensor.h +++ b/esphome/components/optolink/optolink_binary_sensor.h @@ -3,7 +3,7 @@ #include "esphome/components/binary_sensor/binary_sensor.h" #include "optolink.h" #include "optolink_sensor_base.h" -#include +#include "VitoWiFi.h" namespace esphome { namespace optolink { @@ -18,7 +18,7 @@ class OptolinkBinarySensor : public OptolinkSensorBase, } protected: - void setup() override { setup_datapoint(); } + void setup() override { setup_datapoint_(); } void update() override { optolink_->read_value(datapoint_); } const std::string &get_sensor_name() override { return get_name(); } diff --git a/esphome/components/optolink/optolink_device_info_sensor.cpp b/esphome/components/optolink/optolink_device_info_sensor.cpp new file mode 100644 index 0000000000..5fad8ec52b --- /dev/null +++ b/esphome/components/optolink/optolink_device_info_sensor.cpp @@ -0,0 +1,22 @@ +#include "esphome/core/log.h" +#include "optolink_device_info_sensor.h" + +namespace esphome { +namespace optolink { + +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_LOGD("OptolinkTextSensor", "Datapoint %s - %s: %d", dp.getGroup(), 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_device_info_sensor.h b/esphome/components/optolink/optolink_device_info_sensor.h index 7611459807..3555cd4215 100644 --- a/esphome/components/optolink/optolink_device_info_sensor.h +++ b/esphome/components/optolink/optolink_device_info_sensor.h @@ -3,14 +3,14 @@ #include "esphome/components/text_sensor/text_sensor.h" #include "optolink.h" #include "optolink_sensor_base.h" -#include +#include "VitoWiFi.h" namespace esphome { namespace optolink { class OptolinkDeviceInfoSensor : public esphome::text_sensor::TextSensor, public esphome::PollingComponent { public: - OptolinkDeviceInfoSensor(std::string name, Optolink *optolink) { + OptolinkDeviceInfoSensor(const std::string &name, Optolink *optolink) { optolink_ = optolink; set_name(name); set_update_interval(1800000); @@ -18,20 +18,7 @@ class OptolinkDeviceInfoSensor : public esphome::text_sensor::TextSensor, public } protected: - void setup() override { - datapoint_ = new Datapoint(get_name().c_str(), "optolink", 0x00f8, false); - datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) { - uint32_t value = dpValue.getU32(); - ESP_LOGD("OptolinkTextSensor", "Datapoint %s - %s: %d", dp.getGroup(), 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); - }); - } + void setup() override; void update() override { optolink_->read_value(datapoint_); } private: diff --git a/esphome/components/optolink/optolink_number.cpp b/esphome/components/optolink/optolink_number.cpp index 1032645009..5c071284f2 100644 --- a/esphome/components/optolink/optolink_number.cpp +++ b/esphome/components/optolink/optolink_number.cpp @@ -1,6 +1,6 @@ #include "optolink_number.h" #include "optolink.h" -#include +#include "VitoWiFi.h" namespace esphome { namespace optolink { @@ -11,7 +11,7 @@ void OptolinkNumber::control(float value) { ESP_LOGE("OptolinkNumber", "datapoint value of number %s not in allowed range", get_sensor_name().c_str()); } else { ESP_LOGI("OptolinkNumber", "control of number %s to value %f", get_sensor_name().c_str(), value); - update_datapoint(value); + update_datapoint_(value); publish_state(value); } }; diff --git a/esphome/components/optolink/optolink_number.h b/esphome/components/optolink/optolink_number.h index 2cc73a46db..5868eddccd 100644 --- a/esphome/components/optolink/optolink_number.h +++ b/esphome/components/optolink/optolink_number.h @@ -3,7 +3,7 @@ #include "esphome/components/number/number.h" #include "optolink_sensor_base.h" #include "optolink.h" -#include +#include "VitoWiFi.h" namespace esphome { namespace optolink { @@ -13,7 +13,7 @@ class OptolinkNumber : public OptolinkSensorBase, public esphome::number::Number OptolinkNumber(Optolink *optolink) : OptolinkSensorBase(optolink, true) {} protected: - void setup() override { setup_datapoint(); } + void setup() override { setup_datapoint_(); } void update() override { optolink_->read_value(datapoint_); } const std::string &get_sensor_name() override { return get_name(); } diff --git a/esphome/components/optolink/optolink_select.cpp b/esphome/components/optolink/optolink_select.cpp index f7c53077f6..3831984ae7 100644 --- a/esphome/components/optolink/optolink_select.cpp +++ b/esphome/components/optolink/optolink_select.cpp @@ -1,6 +1,6 @@ #include "optolink_select.h" #include "optolink.h" -#include +#include "VitoWiFi.h" namespace esphome { namespace optolink { @@ -9,7 +9,7 @@ void OptolinkSelect::control(const std::string &value) { for (auto it = mapping_->begin(); it != mapping_->end(); ++it) { if (it->second == value) { ESP_LOGI("OptolinkSelect", "control of select %s to value %s", get_sensor_name().c_str(), it->first.c_str()); - update_datapoint(std::stof(it->first)); + update_datapoint_(std::stof(it->first)); publish_state(it->second); break; } diff --git a/esphome/components/optolink/optolink_select.h b/esphome/components/optolink/optolink_select.h index 63b379c1e5..454230fb0e 100644 --- a/esphome/components/optolink/optolink_select.h +++ b/esphome/components/optolink/optolink_select.h @@ -4,7 +4,7 @@ #include "esphome/components/select/select.h" #include "optolink.h" #include "optolink_sensor_base.h" -#include +#include "VitoWiFi.h" namespace esphome { namespace optolink { @@ -16,14 +16,14 @@ class OptolinkSelect : public OptolinkSensorBase, public esphome::select::Select void set_map(std::map *mapping) { mapping_ = mapping; std::vector values; - for (auto it = mapping->begin(); it != mapping->end(); ++it) { - values.push_back(it->second); + for (auto &it : *mapping) { + values.push_back(it.second); } traits.set_options(values); }; protected: - void setup() override { setup_datapoint(); } + void setup() override { setup_datapoint_(); } void update() override { optolink_->read_value(datapoint_); } const std::string &get_sensor_name() override { return get_name(); } diff --git a/esphome/components/optolink/optolink_sensor.h b/esphome/components/optolink/optolink_sensor.h index b8613fc470..dd10697de2 100644 --- a/esphome/components/optolink/optolink_sensor.h +++ b/esphome/components/optolink/optolink_sensor.h @@ -3,7 +3,7 @@ #include "esphome/components/sensor/sensor.h" #include "optolink.h" #include "optolink_sensor_base.h" -#include +#include "VitoWiFi.h" namespace esphome { namespace optolink { @@ -15,7 +15,7 @@ class OptolinkSensor : public OptolinkSensorBase, public esphome::sensor::Sensor } protected: - void setup() { setup_datapoint(); } + void setup() { setup_datapoint_(); } void update() override { optolink_->read_value(datapoint_); } const std::string &get_sensor_name() override { return get_name(); } diff --git a/esphome/components/optolink/optolink_sensor_base.cpp b/esphome/components/optolink/optolink_sensor_base.cpp index 599f4b791d..26ea2ed000 100644 --- a/esphome/components/optolink/optolink_sensor_base.cpp +++ b/esphome/components/optolink/optolink_sensor_base.cpp @@ -4,7 +4,7 @@ namespace esphome { namespace optolink { -void OptolinkSensorBase::update_datapoint(float value) { +void OptolinkSensorBase::update_datapoint_(float value) { if (!writeable_) { optolink_->set_error("try to control not writable number %s", get_sensor_name().c_str()); ESP_LOGE("OptolinkSensorBase", "try to control not writable number %s", get_sensor_name().c_str()); @@ -31,8 +31,6 @@ void OptolinkSensorBase::update_datapoint(float value) { optolink_->write_value(datapoint_, DPValue((uint16_t) value)); break; case 10: - optolink_->write_value(datapoint_, DPValue((float) value)); - break; case 100: optolink_->write_value(datapoint_, DPValue((float) value)); break; @@ -66,22 +64,22 @@ void OptolinkSensorBase::update_datapoint(float value) { } } -void OptolinkSensorBase::setup_datapoint() { +void OptolinkSensorBase::setup_datapoint_() { switch (bytes_) { case 1: switch (div_ratio_) { case 1: datapoint_ = new Datapoint(get_sensor_name().c_str(), "optolink", address_, writeable_); - datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) { - ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), dpValue.getU8()); - value_changed(dpValue.getU8()); + datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) { + ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), dp_value.getU8()); + value_changed(dp_value.getU8()); }); break; case 10: datapoint_ = new Datapoint(get_sensor_name().c_str(), "optolink", address_, writeable_); - datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) { - ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dpValue.getFloat()); - value_changed(dpValue.getFloat()); + datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) { + ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dp_value.getFloat()); + value_changed(dp_value.getFloat()); }); break; default: @@ -94,23 +92,23 @@ void OptolinkSensorBase::setup_datapoint() { switch (div_ratio_) { case 1: datapoint_ = new Datapoint(get_sensor_name().c_str(), "optolink", address_, writeable_); - datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) { - ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), dpValue.getU16()); - value_changed(dpValue.getU16()); + datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) { + ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), dp_value.getU16()); + value_changed(dp_value.getU16()); }); break; case 10: datapoint_ = new Datapoint(get_sensor_name().c_str(), "optolink", address_, writeable_); - datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) { - ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dpValue.getFloat()); - value_changed(dpValue.getFloat()); + datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) { + ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dp_value.getFloat()); + value_changed(dp_value.getFloat()); }); break; case 100: datapoint_ = new Datapoint(get_sensor_name().c_str(), "optolink", address_, writeable_); - datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) { - ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dpValue.getFloat()); - value_changed(dpValue.getFloat()); + datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) { + ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dp_value.getFloat()); + value_changed(dp_value.getFloat()); }); break; default: @@ -123,16 +121,16 @@ void OptolinkSensorBase::setup_datapoint() { switch (div_ratio_) { case 1: datapoint_ = new Datapoint(get_sensor_name().c_str(), "optolink", address_, writeable_); - datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) { - ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), dpValue.getU32()); - value_changed(dpValue.getU32()); + datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) { + ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %d", dp.getGroup(), dp.getName(), dp_value.getU32()); + value_changed(dp_value.getU32()); }); break; case 3600: datapoint_ = new Datapoint(get_sensor_name().c_str(), "optolink", address_, writeable_); - datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) { - ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dpValue.getFloat()); - value_changed(dpValue.getFloat()); + datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) { + ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: %f", dp.getGroup(), dp.getName(), dp_value.getFloat()); + value_changed(dp_value.getFloat()); }); break; default: @@ -153,6 +151,7 @@ void conv2_100_F::encode(uint8_t *out, DPValue in) { out[1] = tmp >> 8; out[0] = tmp & 0xFF; } + DPValue conv2_100_F::decode(const uint8_t *in) { int16_t tmp = in[1] << 8 | in[0]; DPValue out(tmp / 100.0f); diff --git a/esphome/components/optolink/optolink_sensor_base.h b/esphome/components/optolink/optolink_sensor_base.h index 93074ea2f2..acb6992d94 100644 --- a/esphome/components/optolink/optolink_sensor_base.h +++ b/esphome/components/optolink/optolink_sensor_base.h @@ -2,7 +2,7 @@ #pragma once #include "esphome/core/log.h" -#include +#include "VitoWiFi.h" namespace esphome { namespace optolink { @@ -18,8 +18,8 @@ class OptolinkSensorBase { int bytes_; int div_ratio_ = 1; - void setup_datapoint(); - void update_datapoint(float value); + void setup_datapoint_(); + void update_datapoint_(float value); public: OptolinkSensorBase(Optolink *optolink, bool writeable = false) { @@ -36,11 +36,12 @@ class OptolinkSensorBase { virtual void value_changed(float state) = 0; }; +// NOLINTNEXTLINE class conv2_100_F : public DPType { public: void encode(uint8_t *out, DPValue in); DPValue decode(const uint8_t *in); - const size_t getLength() const { return 2; } + size_t get_length() const { return 2; } }; } // namespace optolink diff --git a/esphome/components/optolink/optolink_state_sensor.h b/esphome/components/optolink/optolink_state_sensor.h index 78d99ac19d..324c320a5c 100644 --- a/esphome/components/optolink/optolink_state_sensor.h +++ b/esphome/components/optolink/optolink_state_sensor.h @@ -3,7 +3,7 @@ #include "esphome/components/text_sensor/text_sensor.h" #include "optolink.h" #include "optolink_sensor_base.h" -#include +#include "VitoWiFi.h" namespace esphome { namespace optolink { diff --git a/esphome/components/optolink/optolink_switch.cpp b/esphome/components/optolink/optolink_switch.cpp index 226dd3d484..514ae5a677 100644 --- a/esphome/components/optolink/optolink_switch.cpp +++ b/esphome/components/optolink/optolink_switch.cpp @@ -1,6 +1,6 @@ #include "optolink_switch.h" #include "optolink.h" -#include +#include "VitoWiFi.h" namespace esphome { namespace optolink { @@ -11,7 +11,7 @@ void OptolinkSwitch::write_state(bool value) { ESP_LOGE("OptolinkSwitch", "datapoint value of switch %s not 0 or 1", get_sensor_name().c_str()); } else { ESP_LOGI("OptolinkSwitch", "control of switch %s to value %d", get_sensor_name().c_str(), value); - update_datapoint(value); + update_datapoint_(value); publish_state(value); } }; diff --git a/esphome/components/optolink/optolink_switch.h b/esphome/components/optolink/optolink_switch.h index faf283dacf..33378b59a0 100644 --- a/esphome/components/optolink/optolink_switch.h +++ b/esphome/components/optolink/optolink_switch.h @@ -3,7 +3,7 @@ #include "esphome/components/switch/switch.h" #include "optolink_sensor_base.h" #include "optolink.h" -#include +#include "VitoWiFi.h" namespace esphome { namespace optolink { @@ -16,13 +16,13 @@ class OptolinkSwitch : public OptolinkSensorBase, public esphome::switch_::Switc } protected: - void setup() override { setup_datapoint(); } + void setup() override { setup_datapoint_(); } void update() override { optolink_->read_value(datapoint_); } const std::string &get_sensor_name() override { return get_name(); } void value_changed(float state) override { publish_state(state); }; - void write_state(bool state) override; + void write_state(bool value) override; }; } // namespace optolink diff --git a/esphome/components/optolink/optolink_text_sensor.cpp b/esphome/components/optolink/optolink_text_sensor.cpp index f226f4f5d0..4f6f656aca 100644 --- a/esphome/components/optolink/optolink_text_sensor.cpp +++ b/esphome/components/optolink/optolink_text_sensor.cpp @@ -1,20 +1,20 @@ #include "optolink_text_sensor.h" #include "optolink.h" -#include +#include "VitoWiFi.h" namespace esphome { namespace optolink { void OptolinkTextSensor::setup() { if (!raw_) { - setup_datapoint(); + setup_datapoint_(); } else { datapoint_ = new Datapoint(get_sensor_name().c_str(), "optolink", address_, writeable_); datapoint_->setLength(bytes_); - datapoint_->setCallback([this](const IDatapoint &dp, DPValue dpValue) { + datapoint_->setCallback([this](const IDatapoint &dp, DPValue dp_value) { ESP_LOGD("OptolinkSensorBase", "Datapoint %s - %s: ", dp.getGroup(), dp.getName()); uint8_t buffer[bytes_ + 1]; - dpValue.getRaw(buffer); + dp_value.getRaw(buffer); buffer[bytes_] = 0x0; publish_state((char *) buffer); }); diff --git a/esphome/components/optolink/optolink_text_sensor.h b/esphome/components/optolink/optolink_text_sensor.h index bb181c3965..56d7c0464a 100644 --- a/esphome/components/optolink/optolink_text_sensor.h +++ b/esphome/components/optolink/optolink_text_sensor.h @@ -3,7 +3,7 @@ #include "esphome/components/text_sensor/text_sensor.h" #include "optolink.h" #include "optolink_sensor_base.h" -#include +#include "VitoWiFi.h" namespace esphome { namespace optolink { diff --git a/esphome/components/optolink/select.py b/esphome/components/optolink/select.py index 34c3482206..5d6aa2ff85 100644 --- a/esphome/components/optolink/select.py +++ b/esphome/components/optolink/select.py @@ -2,7 +2,6 @@ from esphome import core import esphome.codegen as cg import esphome.config_validation as cv from esphome.components import select -from esphome.components.optolink.sensor import SENSOR_BASE_SCHEMA from esphome.const import ( CONF_ADDRESS, CONF_BYTES, @@ -12,7 +11,8 @@ from esphome.const import ( CONF_TO, CONF_UPDATE_INTERVAL, ) -from . import OptolinkComponent, optolink_ns +from . import OptolinkComponent, optolink_ns, CONF_OPTOLINK_ID +from .sensor import SENSOR_BASE_SCHEMA OptolinkSelect = optolink_ns.class_( "OptolinkSelect", select.Select, cg.PollingComponent @@ -32,7 +32,6 @@ def validate_mapping(value): )(value) -CONF_OPTOLINK_ID = "optolink_id" CONF_MAP = "map" MAP_ID = "mappings" CONFIG_SCHEMA = ( diff --git a/esphome/components/optolink/text_sensor.py b/esphome/components/optolink/text_sensor.py index 662474236e..09280c91aa 100644 --- a/esphome/components/optolink/text_sensor.py +++ b/esphome/components/optolink/text_sensor.py @@ -1,6 +1,5 @@ from esphome import core import esphome.codegen as cg -from esphome.components.optolink.sensor import SENSOR_BASE_SCHEMA import esphome.config_validation as cv from esphome.components import text_sensor from esphome.const import ( @@ -11,13 +10,13 @@ from esphome.const import ( CONF_RAW, CONF_UPDATE_INTERVAL, ) -from . import optolink_ns, OptolinkComponent +from . import optolink_ns, OptolinkComponent, CONF_OPTOLINK_ID +from .sensor import SENSOR_BASE_SCHEMA OptolinkTextSensor = optolink_ns.class_( "OptolinkTextSensor", text_sensor.TextSensor, cg.PollingComponent ) -CONF_OPTOLINK_ID = "optolink_id" CONFIG_SCHEMA = cv.All( text_sensor.text_sensor_schema(OptolinkTextSensor) .extend( diff --git a/platformio.ini b/platformio.ini index 3df6446ff1..06823d5dd2 100644 --- a/platformio.ini +++ b/platformio.ini @@ -65,6 +65,7 @@ lib_deps = rweather/Crypto@0.4.0 ; dsmr dudanov/MideaUART@1.1.8 ; midea tonia/HeatpumpIR@1.0.20 ; heatpumpir + bertmelis/VitoWiFi@1.0.2 ; optolink build_flags = ${common.build_flags} -DUSE_ARDUINO