diff --git a/esphome/components/optolink/binary_sensor/optolink_binary_sensor.h b/esphome/components/optolink/binary_sensor/optolink_binary_sensor.h index 2e1b5158b4..0f595bf04c 100644 --- a/esphome/components/optolink/binary_sensor/optolink_binary_sensor.h +++ b/esphome/components/optolink/binary_sensor/optolink_binary_sensor.h @@ -23,7 +23,7 @@ class OptolinkBinarySensor : public DatapointComponent, void update() override { datapoint_read_request_(); } const StringRef &get_component_name() override { return get_name(); } - void datapoint_value_changed(uint8_t state) override { publish_state(state); }; + void datapoint_value_changed(uint8_t value) override { publish_state(value); }; }; } // namespace optolink } // namespace esphome diff --git a/esphome/components/optolink/datapoint_component.cpp b/esphome/components/optolink/datapoint_component.cpp index 7c13c6cd95..662aa303be 100644 --- a/esphome/components/optolink/datapoint_component.cpp +++ b/esphome/components/optolink/datapoint_component.cpp @@ -259,7 +259,7 @@ void DatapointComponent::set_optolink_state_(const char *format, ...) { std::string DatapointComponent::get_optolink_state_() { return optolink_->get_state(); } -void DatapointComponent::subscribe_hass_(std::string entity_id, std::function f) { +void DatapointComponent::subscribe_hass_(const std::string entity_id, std::function f) { for (auto &subscription : hass_subscriptions_) { if (subscription.entity_id == entity_id) { subscription.callbacks.push_back(f); @@ -273,13 +273,13 @@ void DatapointComponent::subscribe_hass_(std::string entity_id, std::functionsubscribe_home_assistant_state( - entity_id, optional(), [this, entity_id](const std::string &state) { + entity_id, optional(), [entity_id](const std::string &state) { ESP_LOGD(TAG, "received schedule plan from HASS entity '%s': %s", entity_id.c_str(), state.c_str()); for (auto &subscription : hass_subscriptions_) { if (subscription.last_state != state) { if (subscription.entity_id == entity_id) { subscription.last_state = state; - for (auto callback : subscription.callbacks) { + for (const auto &callback : subscription.callbacks) { callback(state); } } diff --git a/esphome/components/optolink/datapoint_component.h b/esphome/components/optolink/datapoint_component.h index 970f6abe06..5eb751e10b 100644 --- a/esphome/components/optolink/datapoint_component.h +++ b/esphome/components/optolink/datapoint_component.h @@ -55,7 +55,7 @@ class DatapointComponent { void set_optolink_state_(const char *format, ...); std::string get_optolink_state_(); - void subscribe_hass_(std::string entity_id, std::function f); + void subscribe_hass_(const std::string entity_id, std::function f); private: const size_t max_retries_until_reset_ = 10; diff --git a/esphome/components/optolink/number/optolink_number.cpp b/esphome/components/optolink/number/optolink_number.cpp index 31450c02b5..3a57e4c3ff 100644 --- a/esphome/components/optolink/number/optolink_number.cpp +++ b/esphome/components/optolink/number/optolink_number.cpp @@ -19,27 +19,27 @@ void OptolinkNumber::control(float value) { } }; -void OptolinkNumber::datapoint_value_changed(uint8_t state) { +void OptolinkNumber::datapoint_value_changed(uint8_t value) { if (traits.get_min_value() >= 0) { - publish_state(state); + publish_state(value); } else { - publish_state((int8_t) state); + publish_state((int8_t) value); } }; -void OptolinkNumber::datapoint_value_changed(uint16_t state) { +void OptolinkNumber::datapoint_value_changed(uint16_t value) { if (traits.get_min_value() >= 0) { - publish_state(state); + publish_state(value); } else { - publish_state((int16_t) state); + publish_state((int16_t) value); } }; -void OptolinkNumber::datapoint_value_changed(uint32_t state) { +void OptolinkNumber::datapoint_value_changed(uint32_t value) { if (traits.get_min_value() >= 0) { - publish_state(state); + publish_state(value); } else { - publish_state((int32_t) state); + publish_state((int32_t) value); } }; diff --git a/esphome/components/optolink/number/optolink_number.h b/esphome/components/optolink/number/optolink_number.h index b202a9b770..c081fcd376 100644 --- a/esphome/components/optolink/number/optolink_number.h +++ b/esphome/components/optolink/number/optolink_number.h @@ -19,10 +19,10 @@ class OptolinkNumber : public DatapointComponent, public esphome::number::Number void control(float value) override; const StringRef &get_component_name() override { return get_name(); } - void datapoint_value_changed(float state) override { publish_state(state); }; - void datapoint_value_changed(uint8_t state) override; - void datapoint_value_changed(uint16_t state) override; - void datapoint_value_changed(uint32_t state) override; + void datapoint_value_changed(float value) override { publish_state(value); }; + void datapoint_value_changed(uint8_t value) override; + void datapoint_value_changed(uint16_t value) override; + void datapoint_value_changed(uint32_t value) override; }; } // namespace optolink diff --git a/esphome/components/optolink/select/optolink_select.cpp b/esphome/components/optolink/select/optolink_select.cpp index a40378580f..6e01decbed 100644 --- a/esphome/components/optolink/select/optolink_select.cpp +++ b/esphome/components/optolink/select/optolink_select.cpp @@ -23,33 +23,33 @@ void OptolinkSelect::control(const std::string &value) { } }; -void OptolinkSelect::datapoint_value_changed(std::string key) { - auto pos = mapping_->find(key); +void OptolinkSelect::datapoint_value_changed(std::string value) { + auto pos = mapping_->find(value); if (pos == mapping_->end()) { - set_optolink_state_("value %s not found in select %s", key.c_str(), get_component_name().c_str()); - ESP_LOGE(TAG, "value %s not found in select %s", key.c_str(), get_component_name().c_str()); + set_optolink_state_("value %s not found in select %s", value.c_str(), get_component_name().c_str()); + ESP_LOGE(TAG, "value %s not found in select %s", value.c_str(), get_component_name().c_str()); } else { publish_state(pos->second); } } -void OptolinkSelect::datapoint_value_changed(uint8_t state) { - std::string key = std::to_string(state); +void OptolinkSelect::datapoint_value_changed(uint8_t value) { + std::string key = std::to_string(value); datapoint_value_changed(key); } -void OptolinkSelect::datapoint_value_changed(uint16_t state) { - std::string key = std::to_string(state); +void OptolinkSelect::datapoint_value_changed(uint16_t value) { + std::string key = std::to_string(value); datapoint_value_changed(key); } -void OptolinkSelect::datapoint_value_changed(uint32_t state) { - std::string key = std::to_string(state); +void OptolinkSelect::datapoint_value_changed(uint32_t value) { + std::string key = std::to_string(value); datapoint_value_changed(key); } -void OptolinkSelect::datapoint_value_changed(float state) { - std::string key = std::to_string(state); +void OptolinkSelect::datapoint_value_changed(float value) { + std::string key = std::to_string(value); datapoint_value_changed(key); } diff --git a/esphome/components/optolink/select/optolink_select.h b/esphome/components/optolink/select/optolink_select.h index a712715e16..33d705cbe0 100644 --- a/esphome/components/optolink/select/optolink_select.h +++ b/esphome/components/optolink/select/optolink_select.h @@ -29,11 +29,11 @@ class OptolinkSelect : public DatapointComponent, public esphome::select::Select void control(const std::string &value) override; const StringRef &get_component_name() override { return get_name(); } - void datapoint_value_changed(std::string state) override; - void datapoint_value_changed(uint8_t state) override; - void datapoint_value_changed(uint16_t state) override; - void datapoint_value_changed(uint32_t state) override; - void datapoint_value_changed(float state) override; + void datapoint_value_changed(std::string value) override; + void datapoint_value_changed(uint8_t value) override; + void datapoint_value_changed(uint16_t value) override; + void datapoint_value_changed(uint32_t value) override; + void datapoint_value_changed(float value) override; private: std::map *mapping_ = nullptr; diff --git a/esphome/components/optolink/sensor/optolink_sensor.cpp b/esphome/components/optolink/sensor/optolink_sensor.cpp index dab0d6ccb4..15407c25d7 100644 --- a/esphome/components/optolink/sensor/optolink_sensor.cpp +++ b/esphome/components/optolink/sensor/optolink_sensor.cpp @@ -11,27 +11,27 @@ static const char *const TAG = "optolink.sensor"; void OptolinkSensor::set_min_value(float min_value) { min_value_ = -29.3; } // NOLINTBEGIN -void OptolinkSensor::datapoint_value_changed(uint8_t state) { +void OptolinkSensor::datapoint_value_changed(uint8_t value) { if (min_value_ >= 0.0) { - publish_state(state); + publish_state(value); } else { - publish_state((int8_t) state); + publish_state((int8_t) value); } }; -void OptolinkSensor::datapoint_value_changed(uint16_t state) { +void OptolinkSensor::datapoint_value_changed(uint16_t value) { if (min_value_ >= 0.0) { - publish_state(state); + publish_state(value); } else { - publish_state((int16_t) state); + publish_state((int16_t) value); } } -void OptolinkSensor::datapoint_value_changed(uint32_t state) { +void OptolinkSensor::datapoint_value_changed(uint32_t value) { if (min_value_ >= 0.0) { - publish_state(state); + publish_state(value); } else { - publish_state((int32_t) state); + publish_state((int32_t) value); } }; // NOLINTEND diff --git a/esphome/components/optolink/sensor/optolink_sensor.h b/esphome/components/optolink/sensor/optolink_sensor.h index 3bfb0e8ddd..cb42146b3d 100644 --- a/esphome/components/optolink/sensor/optolink_sensor.h +++ b/esphome/components/optolink/sensor/optolink_sensor.h @@ -23,10 +23,10 @@ class OptolinkSensor : public DatapointComponent, public esphome::sensor::Sensor void update() override { datapoint_read_request_(); } const StringRef &get_component_name() override { return get_name(); } - void datapoint_value_changed(float state) override { publish_state(state); }; - void datapoint_value_changed(uint8_t state) override; - void datapoint_value_changed(uint16_t state) override; - void datapoint_value_changed(uint32_t state) override; + void datapoint_value_changed(float value) override { publish_state(value); }; + void datapoint_value_changed(uint8_t value) override; + void datapoint_value_changed(uint16_t value) override; + void datapoint_value_changed(uint32_t value) override; private: float min_value_ = -FLT_MAX; diff --git a/esphome/components/optolink/switch/optolink_switch.h b/esphome/components/optolink/switch/optolink_switch.h index 880e66618a..f1c9919c34 100644 --- a/esphome/components/optolink/switch/optolink_switch.h +++ b/esphome/components/optolink/switch/optolink_switch.h @@ -22,7 +22,7 @@ class OptolinkSwitch : public DatapointComponent, public esphome::switch_::Switc void write_state(bool value) override; const StringRef &get_component_name() override { return get_name(); } - void datapoint_value_changed(uint8_t state) override { publish_state(state); }; + void datapoint_value_changed(uint8_t value) override { publish_state(state); }; }; } // namespace optolink diff --git a/esphome/components/optolink/text_sensor/optolink_text_sensor.cpp b/esphome/components/optolink/text_sensor/optolink_text_sensor.cpp index d10f1af6c1..ed8779132c 100644 --- a/esphome/components/optolink/text_sensor/optolink_text_sensor.cpp +++ b/esphome/components/optolink/text_sensor/optolink_text_sensor.cpp @@ -16,17 +16,14 @@ struct Time { }; bool check_time_sequence(const Time &t1, const Time &t2) { - if (t2.hours > t1.hours || (t2.hours == t1.hours && t2.minutes >= t1.minutes)) { - return true; - } - return false; + return t2.hours > t1.hours || (t2.hours == t1.hours && t2.minutes >= t1.minutes); } bool check_time_values(const Time &time) { return (time.hours >= 0 && time.hours <= 23) && (time.minutes >= 0 && time.minutes <= 59); } -uint8_t *encode_time_string(std::string input) { +uint8_t *encode_time_string(const std::string input) { char buffer[49]; strncpy(buffer, input.c_str(), sizeof(buffer)); buffer[sizeof(buffer) - 1] = 0x00; @@ -45,18 +42,18 @@ uint8_t *encode_time_string(std::string input) { ESP_LOGE( TAG, "Time values should be in the format hh:mm and in increasing order within the range of 00:00 to 23:59"); - return 0; + return nullptr; } } else { ESP_LOGE(TAG, "Invalid time format"); - return 0; + return nullptr; } token = strtok(nullptr, " "); } if (time_count % 2) { ESP_LOGE(TAG, "Number of time values must be even"); - return 0; + return nullptr; } while (time_count < 8) { @@ -64,11 +61,9 @@ uint8_t *encode_time_string(std::string input) { } static uint8_t data[8]; - // ESP_LOGD(TAG, "Parsed time values:"); for (int i = 0; i < 8; i++) { Time time = time_values[i]; data[i] = (time.hours << 3) + (time.minutes / 10); - // ESP_LOGD(TAG, " %02d:%02d => %d", time.hours, time.minutes, data[i]); } return data; diff --git a/esphome/components/optolink/text_sensor/optolink_text_sensor.h b/esphome/components/optolink/text_sensor/optolink_text_sensor.h index 1583da1d99..fe97a68434 100644 --- a/esphome/components/optolink/text_sensor/optolink_text_sensor.h +++ b/esphome/components/optolink/text_sensor/optolink_text_sensor.h @@ -26,11 +26,11 @@ class OptolinkTextSensor : public DatapointComponent, void update() override; const StringRef &get_component_name() override { return get_name(); } - void datapoint_value_changed(float state) override { publish_state(std::to_string(state)); }; - void datapoint_value_changed(uint8_t state) override { publish_state(std::to_string(state)); }; - void datapoint_value_changed(uint16_t state) override { publish_state(std::to_string(state)); }; - void datapoint_value_changed(uint32_t state) override; - void datapoint_value_changed(uint8_t *state, size_t length) override; + void datapoint_value_changed(float value) override { publish_state(std::to_string(value)); }; + void datapoint_value_changed(uint8_t value) override { publish_state(std::to_string(value)); }; + void datapoint_value_changed(uint16_t value) override { publish_state(std::to_string(value)); }; + void datapoint_value_changed(uint32_t value) override; + void datapoint_value_changed(uint8_t *value, size_t length) override; private: TextSensorMode mode_ = MAP;