From 85d1afe874f7e6cc8a8a0e82b4b1980a1b40a7be Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 22 Mar 2023 15:51:13 +0100 Subject: [PATCH] Split TrumaiNetBoxApp into multiple files. --- .../TrumaStausFrameResponseStorage.h | 3 + .../truma_inetbox/TrumaStausFrameStorage.h | 7 ++- components/truma_inetbox/TrumaStructs.h | 15 +++++ components/truma_inetbox/TrumaiNetBoxApp.cpp | 62 ------------------ components/truma_inetbox/TrumaiNetBoxApp.h | 63 ++++++------------- .../TrumaiNetBoxAppAirconAuto.cpp | 24 +++++++ .../truma_inetbox/TrumaiNetBoxAppAirconAuto.h | 16 +++++ .../TrumaiNetBoxAppAirconManual.cpp | 24 +++++++ .../TrumaiNetBoxAppAirconManual.h | 16 +++++ .../truma_inetbox/TrumaiNetBoxAppClock.h | 12 ++++ .../truma_inetbox/TrumaiNetBoxAppConfig.h | 12 ++++ .../truma_inetbox/TrumaiNetBoxAppHeater.cpp | 27 ++++++++ .../truma_inetbox/TrumaiNetBoxAppHeater.h | 15 +++++ .../truma_inetbox/TrumaiNetBoxAppTimer.cpp | 32 ++++++++++ .../truma_inetbox/TrumaiNetBoxAppTimer.h | 15 +++++ .../TrumaiNetBoxApp_automation.cpp | 42 ++++++------- components/truma_inetbox/automation.h | 2 +- .../binary_sensor/TrumaHeaterBinarySensor.cpp | 2 +- .../binary_sensor/TrumaTimerBinarySensor.cpp | 2 +- .../climate/TrumaRoomClimate.cpp | 6 +- .../climate/TrumaWaterClimate.cpp | 4 +- .../number/TrumaHeaterNumber.cpp | 2 +- .../truma_inetbox/sensor/TrumaSensor.cpp | 2 +- components/truma_inetbox/time/TrumaTime.cpp | 6 +- 24 files changed, 268 insertions(+), 143 deletions(-) create mode 100644 components/truma_inetbox/TrumaiNetBoxAppAirconAuto.cpp create mode 100644 components/truma_inetbox/TrumaiNetBoxAppAirconAuto.h create mode 100644 components/truma_inetbox/TrumaiNetBoxAppAirconManual.cpp create mode 100644 components/truma_inetbox/TrumaiNetBoxAppAirconManual.h create mode 100644 components/truma_inetbox/TrumaiNetBoxAppClock.h create mode 100644 components/truma_inetbox/TrumaiNetBoxAppConfig.h create mode 100644 components/truma_inetbox/TrumaiNetBoxAppHeater.cpp create mode 100644 components/truma_inetbox/TrumaiNetBoxAppHeater.h create mode 100644 components/truma_inetbox/TrumaiNetBoxAppTimer.cpp create mode 100644 components/truma_inetbox/TrumaiNetBoxAppTimer.h diff --git a/components/truma_inetbox/TrumaStausFrameResponseStorage.h b/components/truma_inetbox/TrumaStausFrameResponseStorage.h index 89cfa3d..2755c86 100644 --- a/components/truma_inetbox/TrumaStausFrameResponseStorage.h +++ b/components/truma_inetbox/TrumaStausFrameResponseStorage.h @@ -8,6 +8,9 @@ namespace truma_inetbox { template class TrumaStausFrameResponseStorage : public TrumaStausFrameStorage { public: void reset(); + bool can_update() { return this->data_valid_; } + virtual TResponse *update_prepare() = 0; + void update_submit() { this->update_status_unsubmitted_ = true; } // Prepared means `update_status_` was copied from `data_`. bool update_status_prepared_ = false; diff --git a/components/truma_inetbox/TrumaStausFrameStorage.h b/components/truma_inetbox/TrumaStausFrameStorage.h index f871f9d..f436674 100644 --- a/components/truma_inetbox/TrumaStausFrameStorage.h +++ b/components/truma_inetbox/TrumaStausFrameStorage.h @@ -13,8 +13,11 @@ template class TrumaStausFrameStorage { // Value has changed notify listeners. bool data_updated_ = false; - // bool get_status_valid() { return this->data_valid_; } - // const T *get_status() { return &this->data_; } + void add_on_message_callback(std::function callback) { + this->state_callback_.add(std::move(callback)); + } + bool get_status_valid() { return this->data_valid_; } + const T *get_status() { return &this->data_; } void update(); void reset(); }; diff --git a/components/truma_inetbox/TrumaStructs.h b/components/truma_inetbox/TrumaStructs.h index 8f43392..21ee20e 100644 --- a/components/truma_inetbox/TrumaStructs.h +++ b/components/truma_inetbox/TrumaStructs.h @@ -229,6 +229,21 @@ struct StatusFrameAirconAuto { // NOLINT(altera-struct-pack-align) TargetTemp target_temp; } __attribute__((packed)); +// TODO +struct StatusFrameAirconAutoResponse { // NOLINT(altera-struct-pack-align) + EnergyMix energy_mix_a; + u_int8_t unknown_02; // 0x00 + EnergyMix energy_mix_b; + u_int8_t unknown_04; // 0x00 + u_int8_t unknown_05; // 0x00 + u_int8_t unknown_06; // 0x00 + TargetTemp target_temp_aircon_auto; + ElectricPowerLevel el_power_level_a; + u_int8_t unknown_11; // 0x00 + u_int8_t unknown_12; // 0x00 + ElectricPowerLevel el_power_level_b; +} __attribute__((packed)); + // Length 20 (0x14) // TODO struct StatusFrameAirconAutoInit { // NOLINT(altera-struct-pack-align) diff --git a/components/truma_inetbox/TrumaiNetBoxApp.cpp b/components/truma_inetbox/TrumaiNetBoxApp.cpp index b4dcae4..4e96e8b 100644 --- a/components/truma_inetbox/TrumaiNetBoxApp.cpp +++ b/components/truma_inetbox/TrumaiNetBoxApp.cpp @@ -92,68 +92,6 @@ template void TrumaStausFrameResponseStorageupdate_status_stale_ = false; } -StatusFrameHeaterResponse *TrumaiNetBoxApp::update_heater_prepare() { - // An update is currently going on. - if (this->heater_.update_status_prepared_ || this->heater_.update_status_stale_) { - return &this->heater_.update_status_; - } - - // prepare status heater response - this->heater_.update_status_ = {}; - this->heater_.update_status_.target_temp_room = this->heater_.data_.target_temp_room; - this->heater_.update_status_.heating_mode = this->heater_.data_.heating_mode; - this->heater_.update_status_.el_power_level_a = this->heater_.data_.el_power_level_a; - this->heater_.update_status_.target_temp_water = this->heater_.data_.target_temp_water; - this->heater_.update_status_.el_power_level_b = this->heater_.data_.el_power_level_b; - this->heater_.update_status_.energy_mix_a = this->heater_.data_.energy_mix_a; - this->heater_.update_status_.energy_mix_b = this->heater_.data_.energy_mix_b; - - this->heater_.update_status_prepared_ = true; - return &this->heater_.update_status_; -} - -StatusFrameTimerResponse *TrumaiNetBoxApp::update_timer_prepare() { - // An update is currently going on. - if (this->timer_.update_status_prepared_ || this->timer_.update_status_stale_) { - return &this->timer_.update_status_; - } - - // prepare status heater response - this->timer_.update_status_ = {}; - this->timer_.update_status_.timer_target_temp_room = this->timer_.data_.timer_target_temp_room; - this->timer_.update_status_.timer_heating_mode = this->timer_.data_.timer_heating_mode; - this->timer_.update_status_.timer_el_power_level_a = this->timer_.data_.timer_el_power_level_a; - this->timer_.update_status_.timer_target_temp_water = this->timer_.data_.timer_target_temp_water; - this->timer_.update_status_.timer_el_power_level_b = this->timer_.data_.timer_el_power_level_b; - this->timer_.update_status_.timer_energy_mix_a = this->timer_.data_.timer_energy_mix_a; - this->timer_.update_status_.timer_energy_mix_b = this->timer_.data_.timer_energy_mix_b; - this->timer_.update_status_.timer_resp_active = this->timer_.data_.timer_active; - this->timer_.update_status_.timer_resp_start_minutes = this->timer_.data_.timer_start_minutes; - this->timer_.update_status_.timer_resp_start_hours = this->timer_.data_.timer_start_hours; - this->timer_.update_status_.timer_resp_stop_minutes = this->timer_.data_.timer_stop_minutes; - this->timer_.update_status_.timer_resp_stop_hours = this->timer_.data_.timer_stop_hours; - - this->timer_.update_status_prepared_ = true; - return &this->timer_.update_status_; -} - -StatusFrameAirconManualResponse *TrumaiNetBoxApp::update_aircon_prepare() { - // An update is currently going on. - if (this->airconManual_.update_status_prepared_ || this->airconManual_.update_status_stale_) { - return &this->airconManual_.update_status_; - } - - // prepare status response - this->airconManual_.update_status_ = {}; - this->airconManual_.update_status_.mode = this->airconManual_.data_.mode; - this->airconManual_.update_status_.operation = this->airconManual_.data_.operation; - this->airconManual_.update_status_.energy_mix = this->airconManual_.data_.energy_mix; - this->airconManual_.update_status_.target_temp_aircon = this->airconManual_.data_.target_temp_aircon; - - this->airconManual_.update_status_prepared_ = true; - return &this->airconManual_.update_status_; -} - bool TrumaiNetBoxApp::answer_lin_order_(const u_int8_t pid) { // Alive message if (pid == LIN_PID_TRUMA_INET_BOX) { diff --git a/components/truma_inetbox/TrumaiNetBoxApp.h b/components/truma_inetbox/TrumaiNetBoxApp.h index 1608435..139a2df 100644 --- a/components/truma_inetbox/TrumaiNetBoxApp.h +++ b/components/truma_inetbox/TrumaiNetBoxApp.h @@ -4,6 +4,12 @@ #include "LinBusProtocol.h" #include "esphome/core/automation.h" #include "TrumaEnums.h" +#include "TrumaiNetBoxAppAirconAuto.h" +#include "TrumaiNetBoxAppAirconManual.h" +#include "TrumaiNetBoxAppClock.h" +#include "TrumaiNetBoxAppConfig.h" +#include "TrumaiNetBoxAppHeater.h" +#include "TrumaiNetBoxAppTimer.h" #include "TrumaStausFrameResponseStorage.h" #include "TrumaStausFrameStorage.h" #include "TrumaStructs.h" @@ -69,7 +75,6 @@ union StatusFrame { // NOLINT(altera-struct-pack-align) } inner; } __attribute__((packed)); - class TrumaiNetBoxApp : public LinBusProtocol { public: void update() override; @@ -78,48 +83,15 @@ class TrumaiNetBoxApp : public LinBusProtocol { void lin_heartbeat() override; void lin_reset_device() override; - bool get_status_heater_valid() { return this->heater_.data_valid_; } - const StatusFrameHeater *get_status_heater() { return &this->heater_.data_; } - - bool get_status_timer_valid() { return this->timer_.data_valid_; } - const StatusFrameTimer *get_status_timer() { return &this->timer_.data_; } - - bool get_status_clock_valid() { return this->clock_.data_valid_; } - const StatusFrameClock *get_status_clock() { return &this->clock_.data_; } - - bool get_status_config_valid() { return this->config_.data_valid_; } - const StatusFrameConfig *get_status_config() { return &this->config_.data_; } - - bool truma_heater_can_update() { return this->heater_.data_valid_; } - StatusFrameHeaterResponse *update_heater_prepare(); - void update_heater_submit() { this->heater_.update_status_unsubmitted_ = true; } - - bool truma_timer_can_update() { return this->timer_.data_valid_; } - StatusFrameTimerResponse *update_timer_prepare(); - void update_timer_submit() { this->timer_.update_status_unsubmitted_ = true; } - - bool truma_aircon_can_update() { return this->airconManual_.data_valid_; } - StatusFrameAirconManualResponse *update_aircon_prepare(); - void update_aircon_submit() { this->airconManual_.update_status_unsubmitted_ = true; } + TrumaiNetBoxAppAirconAuto *get_aircon_auto() { return &this->airconAuto_; } + TrumaiNetBoxAppAirconManual *get_aircon_manual() { return &this->airconManual_; } + TrumaiNetBoxAppClock *get_clock() { return &this->clock_; } + TrumaiNetBoxAppConfig *get_config() { return &this->config_; } + TrumaiNetBoxAppHeater *get_heater() { return &this->heater_; } + TrumaiNetBoxAppTimer *get_timer() { return &this->timer_; } int64_t get_last_cp_plus_request() { return this->device_registered_; } - // Automation - void add_on_heater_message_callback(std::function callback) { - this->heater_.state_callback_.add(std::move(callback)); - } - void add_on_timer_message_callback(std::function callback) { - this->timer_.state_callback_.add(std::move(callback)); - } - void add_on_clock_message_callback(std::function callback) { - this->clock_.state_callback_.add(std::move(callback)); - } - void add_on_config_message_callback(std::function callback) { - this->config_.state_callback_.add(std::move(callback)); - } - void add_on_aircon_manual_message_callback(std::function callback) { - this->airconManual_.state_callback_.add(std::move(callback)); - } bool action_heater_room(u_int8_t temperature, HeatingMode mode = HeatingMode::HEATING_MODE_OFF); bool action_heater_water(u_int8_t temperature); bool action_heater_water(TargetTemp temperature); @@ -150,11 +122,12 @@ class TrumaiNetBoxApp : public LinBusProtocol { TRUMA_DEVICE heater_device_ = TRUMA_DEVICE::HEATER_COMBI4; TRUMA_DEVICE aircon_device_ = TRUMA_DEVICE::UNKNOWN; - TrumaStausFrameResponseStorage heater_; - TrumaStausFrameResponseStorage timer_; - TrumaStausFrameResponseStorage airconManual_; - TrumaStausFrameStorage config_; - TrumaStausFrameStorage clock_; + TrumaiNetBoxAppAirconAuto airconAuto_{}; + TrumaiNetBoxAppAirconManual airconManual_{}; + TrumaiNetBoxAppClock clock_{}; + TrumaiNetBoxAppConfig config_{}; + TrumaiNetBoxAppHeater heater_{}; + TrumaiNetBoxAppTimer timer_{}; // last time CP plus was informed I got an update msg. uint32_t update_time_ = 0; diff --git a/components/truma_inetbox/TrumaiNetBoxAppAirconAuto.cpp b/components/truma_inetbox/TrumaiNetBoxAppAirconAuto.cpp new file mode 100644 index 0000000..ece4dfd --- /dev/null +++ b/components/truma_inetbox/TrumaiNetBoxAppAirconAuto.cpp @@ -0,0 +1,24 @@ +#include "TrumaiNetBoxAppAirconAuto.h" + +namespace esphome { +namespace truma_inetbox { + +StatusFrameAirconAutoResponse *TrumaiNetBoxAppAirconAuto::update_prepare() { + // An update is currently going on. + if (this->update_status_prepared_ || this->update_status_stale_) { + return &this->update_status_; + } + + // prepare status response + this->update_status_ = {}; + // this->update_status_.mode = this->data_.mode; + // this->update_status_.operation = this->data_.operation; + // this->update_status_.energy_mix = this->data_.energy_mix; + // this->update_status_.target_temp_aircon = this->data_.target_temp_aircon; + + this->update_status_prepared_ = true; + return &this->update_status_; +} + +} // namespace truma_inetbox +} // namespace esphome \ No newline at end of file diff --git a/components/truma_inetbox/TrumaiNetBoxAppAirconAuto.h b/components/truma_inetbox/TrumaiNetBoxAppAirconAuto.h new file mode 100644 index 0000000..538e705 --- /dev/null +++ b/components/truma_inetbox/TrumaiNetBoxAppAirconAuto.h @@ -0,0 +1,16 @@ +#pragma once + +#include "TrumaStausFrameResponseStorage.h" +#include "TrumaStructs.h" + +namespace esphome { +namespace truma_inetbox { + +class TrumaiNetBoxAppAirconAuto + : public TrumaStausFrameResponseStorage { + public: + StatusFrameAirconAutoResponse *update_prepare() override; +}; + +} // namespace truma_inetbox +} // namespace esphome \ No newline at end of file diff --git a/components/truma_inetbox/TrumaiNetBoxAppAirconManual.cpp b/components/truma_inetbox/TrumaiNetBoxAppAirconManual.cpp new file mode 100644 index 0000000..0bc8577 --- /dev/null +++ b/components/truma_inetbox/TrumaiNetBoxAppAirconManual.cpp @@ -0,0 +1,24 @@ +#include "TrumaiNetBoxAppAirconManual.h" + +namespace esphome { +namespace truma_inetbox { + +StatusFrameAirconManualResponse *TrumaiNetBoxAppAirconManual::update_prepare() { + // An update is currently going on. + if (this->update_status_prepared_ || this->update_status_stale_) { + return &this->update_status_; + } + + // prepare status response + this->update_status_ = {}; + this->update_status_.mode = this->data_.mode; + this->update_status_.operation = this->data_.operation; + this->update_status_.energy_mix = this->data_.energy_mix; + this->update_status_.target_temp_aircon = this->data_.target_temp_aircon; + + this->update_status_prepared_ = true; + return &this->update_status_; +} + +} // namespace truma_inetbox +} // namespace esphome \ No newline at end of file diff --git a/components/truma_inetbox/TrumaiNetBoxAppAirconManual.h b/components/truma_inetbox/TrumaiNetBoxAppAirconManual.h new file mode 100644 index 0000000..6cd0348 --- /dev/null +++ b/components/truma_inetbox/TrumaiNetBoxAppAirconManual.h @@ -0,0 +1,16 @@ +#pragma once + +#include "TrumaStausFrameResponseStorage.h" +#include "TrumaStructs.h" + +namespace esphome { +namespace truma_inetbox { + +class TrumaiNetBoxAppAirconManual + : public TrumaStausFrameResponseStorage { + public: + StatusFrameAirconManualResponse *update_prepare() override; +}; + +} // namespace truma_inetbox +} // namespace esphome \ No newline at end of file diff --git a/components/truma_inetbox/TrumaiNetBoxAppClock.h b/components/truma_inetbox/TrumaiNetBoxAppClock.h new file mode 100644 index 0000000..6f44a63 --- /dev/null +++ b/components/truma_inetbox/TrumaiNetBoxAppClock.h @@ -0,0 +1,12 @@ +#pragma once + +#include "TrumaStausFrameResponseStorage.h" +#include "TrumaStructs.h" + +namespace esphome { +namespace truma_inetbox { + +class TrumaiNetBoxAppClock : public TrumaStausFrameStorage {}; + +} // namespace truma_inetbox +} // namespace esphome \ No newline at end of file diff --git a/components/truma_inetbox/TrumaiNetBoxAppConfig.h b/components/truma_inetbox/TrumaiNetBoxAppConfig.h new file mode 100644 index 0000000..e697889 --- /dev/null +++ b/components/truma_inetbox/TrumaiNetBoxAppConfig.h @@ -0,0 +1,12 @@ +#pragma once + +#include "TrumaStausFrameResponseStorage.h" +#include "TrumaStructs.h" + +namespace esphome { +namespace truma_inetbox { + +class TrumaiNetBoxAppConfig : public TrumaStausFrameStorage {}; + +} // namespace truma_inetbox +} // namespace esphome \ No newline at end of file diff --git a/components/truma_inetbox/TrumaiNetBoxAppHeater.cpp b/components/truma_inetbox/TrumaiNetBoxAppHeater.cpp new file mode 100644 index 0000000..e028c13 --- /dev/null +++ b/components/truma_inetbox/TrumaiNetBoxAppHeater.cpp @@ -0,0 +1,27 @@ +#include "TrumaiNetBoxAppHeater.h" + +namespace esphome { +namespace truma_inetbox { + +StatusFrameHeaterResponse *TrumaiNetBoxAppHeater::update_prepare() { + // An update is currently going on. + if (this->update_status_prepared_ || this->update_status_stale_) { + return &this->update_status_; + } + + // prepare status heater response + this->update_status_ = {}; + this->update_status_.target_temp_room = this->data_.target_temp_room; + this->update_status_.heating_mode = this->data_.heating_mode; + this->update_status_.el_power_level_a = this->data_.el_power_level_a; + this->update_status_.target_temp_water = this->data_.target_temp_water; + this->update_status_.el_power_level_b = this->data_.el_power_level_b; + this->update_status_.energy_mix_a = this->data_.energy_mix_a; + this->update_status_.energy_mix_b = this->data_.energy_mix_b; + + this->update_status_prepared_ = true; + return &this->update_status_; +} + +} // namespace truma_inetbox +} // namespace esphome \ No newline at end of file diff --git a/components/truma_inetbox/TrumaiNetBoxAppHeater.h b/components/truma_inetbox/TrumaiNetBoxAppHeater.h new file mode 100644 index 0000000..4278546 --- /dev/null +++ b/components/truma_inetbox/TrumaiNetBoxAppHeater.h @@ -0,0 +1,15 @@ +#pragma once + +#include "TrumaStausFrameResponseStorage.h" +#include "TrumaStructs.h" + +namespace esphome { +namespace truma_inetbox { + +class TrumaiNetBoxAppHeater : public TrumaStausFrameResponseStorage { + public: + StatusFrameHeaterResponse* update_prepare() override; +}; + +} // namespace truma_inetbox +} // namespace esphome \ No newline at end of file diff --git a/components/truma_inetbox/TrumaiNetBoxAppTimer.cpp b/components/truma_inetbox/TrumaiNetBoxAppTimer.cpp new file mode 100644 index 0000000..7deb741 --- /dev/null +++ b/components/truma_inetbox/TrumaiNetBoxAppTimer.cpp @@ -0,0 +1,32 @@ +#include "TrumaiNetBoxAppTimer.h" + +namespace esphome { +namespace truma_inetbox { + +StatusFrameTimerResponse *TrumaiNetBoxAppTimer::update_prepare() { + // An update is currently going on. + if (this->update_status_prepared_ || this->update_status_stale_) { + return &this->update_status_; + } + + // prepare status heater response + this->update_status_ = {}; + this->update_status_.timer_target_temp_room = this->data_.timer_target_temp_room; + this->update_status_.timer_heating_mode = this->data_.timer_heating_mode; + this->update_status_.timer_el_power_level_a = this->data_.timer_el_power_level_a; + this->update_status_.timer_target_temp_water = this->data_.timer_target_temp_water; + this->update_status_.timer_el_power_level_b = this->data_.timer_el_power_level_b; + this->update_status_.timer_energy_mix_a = this->data_.timer_energy_mix_a; + this->update_status_.timer_energy_mix_b = this->data_.timer_energy_mix_b; + this->update_status_.timer_resp_active = this->data_.timer_active; + this->update_status_.timer_resp_start_minutes = this->data_.timer_start_minutes; + this->update_status_.timer_resp_start_hours = this->data_.timer_start_hours; + this->update_status_.timer_resp_stop_minutes = this->data_.timer_stop_minutes; + this->update_status_.timer_resp_stop_hours = this->data_.timer_stop_hours; + + this->update_status_prepared_ = true; + return &this->update_status_; +} + +} // namespace truma_inetbox +} // namespace esphome \ No newline at end of file diff --git a/components/truma_inetbox/TrumaiNetBoxAppTimer.h b/components/truma_inetbox/TrumaiNetBoxAppTimer.h new file mode 100644 index 0000000..75c23ab --- /dev/null +++ b/components/truma_inetbox/TrumaiNetBoxAppTimer.h @@ -0,0 +1,15 @@ +#pragma once + +#include "TrumaStausFrameResponseStorage.h" +#include "TrumaStructs.h" + +namespace esphome { +namespace truma_inetbox { + +class TrumaiNetBoxAppTimer : public TrumaStausFrameResponseStorage { + public: + StatusFrameTimerResponse *update_prepare() override; +}; + +} // namespace truma_inetbox +} // namespace esphome \ No newline at end of file diff --git a/components/truma_inetbox/TrumaiNetBoxApp_automation.cpp b/components/truma_inetbox/TrumaiNetBoxApp_automation.cpp index 42790af..7b7de9f 100644 --- a/components/truma_inetbox/TrumaiNetBoxApp_automation.cpp +++ b/components/truma_inetbox/TrumaiNetBoxApp_automation.cpp @@ -10,11 +10,11 @@ namespace truma_inetbox { static const char *const TAG = "truma_inetbox.TrumaiNetBoxApp"; bool TrumaiNetBoxApp::action_heater_room(u_int8_t temperature, HeatingMode mode) { - if (!this->truma_heater_can_update()) { + if (!this->heater_.can_update()) { ESP_LOGW(TAG, "Cannot update Truma."); return false; } - auto heater = this->update_heater_prepare(); + auto heater = this->heater_.update_prepare(); heater->target_temp_room = decimal_to_room_temp(temperature); @@ -45,16 +45,16 @@ bool TrumaiNetBoxApp::action_heater_room(u_int8_t temperature, HeatingMode mode) heater->energy_mix_a = EnergyMix::ENERGY_MIX_GAS; } - this->update_heater_submit(); + this->heater_.update_submit(); return true; } bool TrumaiNetBoxApp::action_heater_water(u_int8_t temperature) { - if (!this->truma_heater_can_update()) { + if (!this->heater_.can_update()) { ESP_LOGW(TAG, "Cannot update Truma."); return false; } - auto heater = this->update_heater_prepare(); + auto heater = this->heater_.update_prepare(); heater->target_temp_water = decimal_to_water_temp(temperature); @@ -63,16 +63,16 @@ bool TrumaiNetBoxApp::action_heater_water(u_int8_t temperature) { heater->energy_mix_a = EnergyMix::ENERGY_MIX_GAS; } - this->update_heater_submit(); + this->heater_.update_submit(); return true; } bool TrumaiNetBoxApp::action_heater_water(TargetTemp temperature) { - if (!this->truma_heater_can_update()) { + if (!this->heater_.can_update()) { ESP_LOGW(TAG, "Cannot update Truma."); return false; } - auto heater = this->update_heater_prepare(); + auto heater = this->heater_.update_prepare(); // If parameter `temperature` contains a valid mode use it or else use `OFF`. if (temperature == TargetTemp::TARGET_TEMP_WATER_ECO || temperature == TargetTemp::TARGET_TEMP_WATER_HIGH || @@ -87,16 +87,16 @@ bool TrumaiNetBoxApp::action_heater_water(TargetTemp temperature) { heater->energy_mix_a = EnergyMix::ENERGY_MIX_GAS; } - this->update_heater_submit(); + this->heater_.update_submit(); return true; } bool TrumaiNetBoxApp::action_heater_electric_power_level(u_int16_t value) { - if (!this->truma_heater_can_update()) { + if (!this->heater_.can_update()) { ESP_LOGW(TAG, "Cannot update Truma."); return false; } - auto heater = this->update_heater_prepare(); + auto heater = this->heater_.update_prepare(); heater->el_power_level_a = decimal_to_el_power_level(value); if (heater->el_power_level_a != ElectricPowerLevel::ELECTRIC_POWER_LEVEL_0) { @@ -108,16 +108,16 @@ bool TrumaiNetBoxApp::action_heater_electric_power_level(u_int16_t value) { heater->energy_mix_a = EnergyMix::ENERGY_MIX_GAS; } - this->update_heater_submit(); + this->heater_.update_submit(); return true; } bool TrumaiNetBoxApp::action_heater_energy_mix(EnergyMix energy_mix, ElectricPowerLevel el_power_level) { - if (!this->truma_heater_can_update()) { + if (!this->heater_.can_update()) { ESP_LOGW(TAG, "Cannot update Truma."); return false; } - auto heater = this->update_heater_prepare(); + auto heater = this->heater_.update_prepare(); // If parameter `el_power_level` contains a valid mode use it. if (el_power_level == ElectricPowerLevel::ELECTRIC_POWER_LEVEL_0 || @@ -147,27 +147,27 @@ bool TrumaiNetBoxApp::action_heater_energy_mix(EnergyMix energy_mix, ElectricPow heater->energy_mix_a = EnergyMix::ENERGY_MIX_GAS; } - this->update_heater_submit(); + this->heater_.update_submit(); return true; } bool TrumaiNetBoxApp::action_timer_disable() { - if (!this->truma_timer_can_update()) { + if (!this->timer_.can_update()) { ESP_LOGW(TAG, "Cannot update Truma."); return false; } - auto timer = this->update_timer_prepare(); + auto timer = this->timer_.update_prepare(); timer->timer_resp_active = TimerActive::TIMER_ACTIVE_OFF; - this->update_timer_submit(); + this->timer_.update_submit(); return true; } bool TrumaiNetBoxApp::action_timer_activate(u_int16_t start, u_int16_t stop, u_int8_t room_temperature, HeatingMode mode, u_int8_t water_temperature, EnergyMix energy_mix, ElectricPowerLevel el_power_level) { - if (!this->truma_timer_can_update()) { + if (!this->timer_.can_update()) { ESP_LOGW(TAG, "Cannot update Truma."); return false; } @@ -176,7 +176,7 @@ bool TrumaiNetBoxApp::action_timer_activate(u_int16_t start, u_int16_t stop, u_i return false; } - auto timer = this->update_timer_prepare(); + auto timer = this->timer_.update_prepare(); timer->timer_resp_active = TimerActive::TIMER_ACTIVE_ON; timer->timer_resp_start_hours = start / 60; @@ -235,7 +235,7 @@ bool TrumaiNetBoxApp::action_timer_activate(u_int16_t start, u_int16_t stop, u_i } } - this->update_timer_submit(); + this->timer_.update_submit(); return true; } diff --git a/components/truma_inetbox/automation.h b/components/truma_inetbox/automation.h index 29029d3..cb13633 100644 --- a/components/truma_inetbox/automation.h +++ b/components/truma_inetbox/automation.h @@ -85,7 +85,7 @@ template class WriteTimeAction : public Action, public Pa class TrumaiNetBoxAppHeaterMessageTrigger : public Trigger { public: explicit TrumaiNetBoxAppHeaterMessageTrigger(TrumaiNetBoxApp *parent) { - parent->add_on_heater_message_callback([this](const StatusFrameHeater *message) { this->trigger(message); }); + parent->get_heater()->add_on_message_callback([this](const StatusFrameHeater *message) { this->trigger(message); }); } }; diff --git a/components/truma_inetbox/binary_sensor/TrumaHeaterBinarySensor.cpp b/components/truma_inetbox/binary_sensor/TrumaHeaterBinarySensor.cpp index f768b5e..37f61b6 100644 --- a/components/truma_inetbox/binary_sensor/TrumaHeaterBinarySensor.cpp +++ b/components/truma_inetbox/binary_sensor/TrumaHeaterBinarySensor.cpp @@ -8,7 +8,7 @@ namespace truma_inetbox { static const char *const TAG = "truma_inetbox.heater_binary_sensor"; void TrumaHeaterBinarySensor::setup() { - this->parent_->add_on_heater_message_callback([this](const StatusFrameHeater *status_heater) { + this->parent_->get_heater()->add_on_message_callback([this](const StatusFrameHeater *status_heater) { switch (this->type_) { case TRUMA_BINARY_SENSOR_TYPE::HEATER_ROOM: this->publish_state(status_heater->target_temp_room != TargetTemp::TARGET_TEMP_OFF); diff --git a/components/truma_inetbox/binary_sensor/TrumaTimerBinarySensor.cpp b/components/truma_inetbox/binary_sensor/TrumaTimerBinarySensor.cpp index b816633..5308e22 100644 --- a/components/truma_inetbox/binary_sensor/TrumaTimerBinarySensor.cpp +++ b/components/truma_inetbox/binary_sensor/TrumaTimerBinarySensor.cpp @@ -8,7 +8,7 @@ namespace truma_inetbox { static const char *const TAG = "truma_inetbox.timer_binary_sensor"; void TrumaTimerBinarySensor::setup() { - this->parent_->add_on_timer_message_callback([this](const StatusFrameTimer *status_timer) { + this->parent_->get_timer()->add_on_message_callback([this](const StatusFrameTimer *status_timer) { switch (this->type_) { case TRUMA_BINARY_SENSOR_TYPE::TIMER_ACTIVE: this->publish_state(status_timer->timer_active == TimerActive::TIMER_ACTIVE_ON); diff --git a/components/truma_inetbox/climate/TrumaRoomClimate.cpp b/components/truma_inetbox/climate/TrumaRoomClimate.cpp index 7afdcae..03e9f2f 100644 --- a/components/truma_inetbox/climate/TrumaRoomClimate.cpp +++ b/components/truma_inetbox/climate/TrumaRoomClimate.cpp @@ -6,7 +6,7 @@ namespace truma_inetbox { static const char *const TAG = "truma_inetbox.room_climate"; void TrumaRoomClimate::setup() { - this->parent_->add_on_heater_message_callback([this](const StatusFrameHeater *status_heater) { + this->parent_->get_heater()->add_on_message_callback([this](const StatusFrameHeater *status_heater) { // Publish updated state this->target_temperature = temp_code_to_decimal(status_heater->target_temp_room); this->current_temperature = temp_code_to_decimal(status_heater->current_temp_room); @@ -43,7 +43,7 @@ void TrumaRoomClimate::control(const climate::ClimateCall &call) { if (call.get_mode().has_value()) { // User requested mode change climate::ClimateMode mode = *call.get_mode(); - auto status_heater = this->parent_->get_status_heater(); + auto status_heater = this->parent_->get_heater()->get_status(); switch (mode) { case climate::CLIMATE_MODE_HEAT: if (status_heater->target_temp_room == TargetTemp::TARGET_TEMP_OFF) { @@ -58,7 +58,7 @@ void TrumaRoomClimate::control(const climate::ClimateCall &call) { if (call.get_preset().has_value()) { climate::ClimatePreset pres = *call.get_preset(); - auto status_heater = this->parent_->get_status_heater(); + auto status_heater = this->parent_->get_heater()->get_status(); auto current_target_temp = temp_code_to_decimal(status_heater->target_temp_room); if (call.get_target_temperature().has_value()) { current_target_temp = *call.get_target_temperature(); diff --git a/components/truma_inetbox/climate/TrumaWaterClimate.cpp b/components/truma_inetbox/climate/TrumaWaterClimate.cpp index b9ca1fb..853752c 100644 --- a/components/truma_inetbox/climate/TrumaWaterClimate.cpp +++ b/components/truma_inetbox/climate/TrumaWaterClimate.cpp @@ -6,7 +6,7 @@ namespace truma_inetbox { static const char *const TAG = "truma_inetbox.water_climate"; void TrumaWaterClimate::setup() { - this->parent_->add_on_heater_message_callback([this](const StatusFrameHeater *status_heater) { + this->parent_->get_heater()->add_on_message_callback([this](const StatusFrameHeater *status_heater) { // Publish updated state this->target_temperature = temp_code_to_decimal(status_heater->target_temp_water); this->current_temperature = temp_code_to_decimal(status_heater->current_temp_water); @@ -26,7 +26,7 @@ void TrumaWaterClimate::control(const climate::ClimateCall &call) { if (call.get_mode().has_value()) { climate::ClimateMode mode = *call.get_mode(); - auto status_heater = this->parent_->get_status_heater(); + auto status_heater = this->parent_->get_heater()->get_status(); switch (mode) { case climate::CLIMATE_MODE_HEAT: if (status_heater->target_temp_water == TargetTemp::TARGET_TEMP_OFF) { diff --git a/components/truma_inetbox/number/TrumaHeaterNumber.cpp b/components/truma_inetbox/number/TrumaHeaterNumber.cpp index 880ff5b..8f02414 100644 --- a/components/truma_inetbox/number/TrumaHeaterNumber.cpp +++ b/components/truma_inetbox/number/TrumaHeaterNumber.cpp @@ -8,7 +8,7 @@ namespace truma_inetbox { static const char *const TAG = "truma_inetbox.heater_number"; void TrumaHeaterNumber::setup() { - this->parent_->add_on_heater_message_callback([this](const StatusFrameHeater *status_heater) { + this->parent_->get_heater()->add_on_message_callback([this](const StatusFrameHeater *status_heater) { switch (this->type_) { case TRUMA_NUMBER_TYPE::TARGET_ROOM_TEMPERATURE: this->publish_state(temp_code_to_decimal(status_heater->target_temp_room, 0)); diff --git a/components/truma_inetbox/sensor/TrumaSensor.cpp b/components/truma_inetbox/sensor/TrumaSensor.cpp index 0592406..4762151 100644 --- a/components/truma_inetbox/sensor/TrumaSensor.cpp +++ b/components/truma_inetbox/sensor/TrumaSensor.cpp @@ -8,7 +8,7 @@ namespace truma_inetbox { static const char *const TAG = "truma_inetbox.sensor"; void TrumaSensor::setup() { - this->parent_->add_on_heater_message_callback([this](const StatusFrameHeater *status_heater) { + this->parent_->get_heater()->add_on_message_callback([this](const StatusFrameHeater *status_heater) { switch (this->type_) { case TRUMA_SENSOR_TYPE::CURRENT_ROOM_TEMPERATURE: this->publish_state(temp_code_to_decimal(status_heater->current_temp_room)); diff --git a/components/truma_inetbox/time/TrumaTime.cpp b/components/truma_inetbox/time/TrumaTime.cpp index 20058c3..17019ec 100644 --- a/components/truma_inetbox/time/TrumaTime.cpp +++ b/components/truma_inetbox/time/TrumaTime.cpp @@ -8,7 +8,7 @@ namespace truma_inetbox { static const char *const TAG = "truma_inetbox.time"; void TrumaTime::setup() { - this->parent_->add_on_clock_message_callback([this](const StatusFrameClock *status_clock) { + this->parent_->get_clock()->add_on_message_callback([this](const StatusFrameClock *status_clock) { if (this->auto_disable_count_ > 0) { if (this->read_time() && this->auto_disable_) { this->auto_disable_count_--; @@ -22,10 +22,10 @@ void TrumaTime::update() {} void TrumaTime::dump_config() { ESP_LOGCONFIG(TAG, "Truma Time", this); } bool TrumaTime::read_time() { - if (!this->parent_->get_status_clock_valid()) { + if (!this->parent_->get_clock()->get_status_valid()) { return false; } - auto status_clock = this->parent_->get_status_clock(); + auto status_clock = this->parent_->get_clock()->get_status(); time::ESPTime rtc_time{.second = status_clock->clock_second, .minute = status_clock->clock_minute,