From e930dad235e1f86ffdf97d892327af05a6b4b796 Mon Sep 17 00:00:00 2001 From: wrfz <77174685+wrfz@users.noreply.github.com> Date: Wed, 11 Sep 2024 16:20:22 +0200 Subject: [PATCH] Fix a crash in the calculation of thermal_power --- README.md | 2 +- components/daikin_rotex_can/__init__.py | 2 +- .../daikin_rotex_can/daikin_rotex_can.cpp | 32 ++++++++++--------- components/daikin_rotex_can/requests.cpp | 10 ++++++ components/daikin_rotex_can/requests.h | 5 --- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index 31e5992..f874225 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ Unterstützte Sensoren und Schalter: |**circulation_pump_min** |Umwälzpumpe Min |Minimale Betriebsstufe der Umwälzpumpe | |**circulation_pump_max** |Umwälzpumpe Max |Maximale Betriebsstufe der Umwälzpumpe | |**delta_temp_ch** |Spreizung MOD HZ |Temperaturdifferenz im Heizbetrieb | -|**delta_temp_ww** |Spreizung MOD WW |Temperaturdifferenz bei der Warmwasserbereitung | +|**delta_temp_dhw** |Spreizung MOD WW |Temperaturdifferenz bei der Warmwasserbereitung | |**dhw_mixer_position** |DHW Mischer Position |Position des Warmwassermischers | |**dhw_run** |Warmwasser bereiten |Steuerung zur Aktivierung der Warmwasserbereitung| |**ehs_for_ch** |EHS fuer CH |Externes Heizsystem für die Heizung | diff --git a/components/daikin_rotex_can/__init__.py b/components/daikin_rotex_can/__init__.py index 49616a3..f5e59e8 100644 --- a/components/daikin_rotex_can/__init__.py +++ b/components/daikin_rotex_can/__init__.py @@ -354,7 +354,7 @@ }, { "type": "sensor", - "name": "water_flow", + "name": "flow_rate", "device_class": DEVICE_CLASS_WATER, "unit_of_measurement": UNIT_LITER_PER_HOUR, "accuracy_decimals": 0, diff --git a/components/daikin_rotex_can/daikin_rotex_can.cpp b/components/daikin_rotex_can/daikin_rotex_can.cpp index 6c6c6fd..d2c30d1 100644 --- a/components/daikin_rotex_can/daikin_rotex_can.cpp +++ b/components/daikin_rotex_can/daikin_rotex_can.cpp @@ -68,11 +68,11 @@ void DaikinRotexCanComponent::setup() { }); } - call_later([entity_conf, this](){ - if (!entity_conf.update_entity.empty()) { + if (!entity_conf.update_entity.empty()) { + call_later([entity_conf, this](){ updateState(entity_conf.update_entity); - } - }); + }); + } if (entity_conf.id == "target_hot_water_temperature") { call_later([this](){ @@ -104,18 +104,20 @@ void DaikinRotexCanComponent::update_thermal_power() { sensor::Sensor* thermal_power = m_accessor.get_thermal_power(); if (mode_of_operating != nullptr && thermal_power != nullptr) { - sensor::Sensor* water_flow = m_data_requests.get_sensor("water_flow"); - sensor::Sensor* tvbh = m_data_requests.get_sensor("tvbh"); - sensor::Sensor* tv = m_data_requests.get_sensor("tv"); - sensor::Sensor* tr = m_data_requests.get_sensor("tr"); - - float value = 0; - if (mode_of_operating->state == "Warmwasserbereitung" && tv != nullptr && tr != nullptr && water_flow != nullptr) { - value = (tv->state - tr->state) * (4.19 * water_flow->state) / 3600.0f; - } else if ((mode_of_operating->state == "Heizen" || mode_of_operating->state == "Kühlen") && tvbh != nullptr && tr != nullptr && water_flow != nullptr) { - value = (tvbh->state - tr->state) * (4.19 * water_flow->state) / 3600.0f; + sensor::Sensor* flow_rate = m_data_requests.get_sensor("flow_rate"); + if (flow_rate != nullptr) { + sensor::Sensor* tvbh = m_data_requests.get_sensor("tvbh"); + sensor::Sensor* tv = m_data_requests.get_sensor("tv"); + sensor::Sensor* tr = m_data_requests.get_sensor("tr"); + + float value = 0; + if (mode_of_operating->state == "Warmwasserbereitung" && tv != nullptr && tr != nullptr) { + value = (tv->state - tr->state) * (4.19 * flow_rate->state) / 3600.0f; + } else if ((mode_of_operating->state == "Heizen" || mode_of_operating->state == "Kühlen") && tvbh != nullptr && tr != nullptr) { + value = (tvbh->state - tr->state) * (4.19 * flow_rate->state) / 3600.0f; + } + thermal_power->publish_state(value); } - thermal_power->publish_state(value); } } diff --git a/components/daikin_rotex_can/requests.cpp b/components/daikin_rotex_can/requests.cpp index 52a3252..c7436dd 100644 --- a/components/daikin_rotex_can/requests.cpp +++ b/components/daikin_rotex_can/requests.cpp @@ -25,6 +25,16 @@ void TRequests::removeInvalidRequests() { ); } +EntityBase* TRequests::get_entity(std::string const& id) { + TRequest const* pRequest = get(id); + if (pRequest != nullptr) { + return pRequest->getEntity(); + } else { + ESP_LOGE("get_entity", "Entity not found: %s", id.c_str()); + } + return nullptr; +} + bool TRequests::sendNextPendingGet() { TRequest* pRequest = getNextRequestToSend(); if (pRequest != nullptr) { diff --git a/components/daikin_rotex_can/requests.h b/components/daikin_rotex_can/requests.h index 68861eb..357fe8b 100644 --- a/components/daikin_rotex_can/requests.h +++ b/components/daikin_rotex_can/requests.h @@ -61,11 +61,6 @@ inline TRequest const* TRequests::get(std::string const& id) const { return nullptr; } -inline EntityBase* TRequests::get_entity(std::string const& id) { - TRequest const* pRequest = get(id); - return pRequest != nullptr ? pRequest->getEntity() : nullptr; -} - inline sensor::Sensor* TRequests::get_sensor(std::string const& id) { return Utils::toSensor(get_entity(id)); }