Skip to content

Commit

Permalink
Fix a crash in the calculation of thermal_power
Browse files Browse the repository at this point in the history
  • Loading branch information
wrfz committed Sep 11, 2024
1 parent 801f506 commit e930dad
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
2 changes: 1 addition & 1 deletion components/daikin_rotex_can/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 17 additions & 15 deletions components/daikin_rotex_can/daikin_rotex_can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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](){
Expand Down Expand Up @@ -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);
}
}

Expand Down
10 changes: 10 additions & 0 deletions components/daikin_rotex_can/requests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 0 additions & 5 deletions components/daikin_rotex_can/requests.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down

0 comments on commit e930dad

Please sign in to comment.