Skip to content

Commit

Permalink
increasing only
Browse files Browse the repository at this point in the history
  • Loading branch information
pail23 committed Apr 1, 2024
1 parent f7f6b09 commit c93ebf3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
13 changes: 13 additions & 0 deletions custom_components/stiebel_eltron_isg/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,16 @@ def read_modbus_sg_ready(self) -> dict:

async def async_reset_heatpump(self) -> None:
"""Reset the heat pump."""
pass

def assign_if_increased(self, value: float | int, key: str) -> float:
"""Assign the value as new value or keep the old value from the internal cache in case the old value is larger than value."""
if value == 0:
return 0
if self.data and self.data.get(key) is not None:
old_value = float(self.data.get(key))
_LOGGER.debug(f"old value for {key} is {old_value} new value is {value}")
if old_value > value:
_LOGGER.info(f"Value for {key} is not strictly increasing existing value is {old_value} and new value is {value}")
return old_value
return value
27 changes: 15 additions & 12 deletions custom_components/stiebel_eltron_isg/wpm_coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -680,6 +680,8 @@ def read_modbus_system_paramter(self) -> dict:
result["system_paramaters"] = list(inverter_data.registers)
return result



def read_modbus_energy(self) -> dict:
"""Read the energy consumption related values from the ISG."""
result = {}
Expand All @@ -695,45 +697,46 @@ def read_modbus_energy(self) -> dict:
produced_water_total_low = decoder.decode_16bit_uint()
produced_water_total_high = decoder.decode_16bit_uint()
decoder.skip_bytes(8) # Skip NHZ
consumed_heating_today = decoder.decode_16bit_uint()
consumed_heating_today = self.assign_if_increased(decoder.decode_16bit_uint(), CONSUMED_HEATING_TODAY)

consumed_heating_total_low = decoder.decode_16bit_uint()
consumed_heating_total_high = decoder.decode_16bit_uint()
consumed_water_today = decoder.decode_16bit_uint()
consumed_water_today = self.assign_if_increased(decoder.decode_16bit_uint(), CONSUMED_WATER_HEATING_TODAY)
consumed_water_total_low = decoder.decode_16bit_uint()
consumed_water_total_high = decoder.decode_16bit_uint()

result[PRODUCED_HEATING_TODAY] = produced_heating_today
result[PRODUCED_HEATING_TOTAL] = (
produced_heating_total_high * 1000 + produced_heating_total_low
)
result[PRODUCED_HEATING] = (
result[PRODUCED_HEATING_TOTAL] + result[PRODUCED_HEATING_TODAY]
result[PRODUCED_HEATING] = self.assign_if_increased(
result[PRODUCED_HEATING_TOTAL] + result[PRODUCED_HEATING_TODAY], PRODUCED_HEATING
)

result[PRODUCED_WATER_HEATING_TODAY] = produced_water_today
result[PRODUCED_WATER_HEATING_TOTAL] = (
produced_water_total_high * 1000 + produced_water_total_low
)
result[PRODUCED_WATER_HEATING] = (
result[PRODUCED_WATER_HEATING] = self.assign_if_increased(
result[PRODUCED_WATER_HEATING_TOTAL]
+ result[PRODUCED_WATER_HEATING_TODAY]
+ result[PRODUCED_WATER_HEATING_TODAY], PRODUCED_WATER_HEATING
)

result[CONSUMED_HEATING_TODAY] = consumed_heating_today
result[CONSUMED_HEATING_TOTAL] = (
consumed_heating_total_high * 1000 + consumed_heating_total_low
)
result[CONSUMED_HEATING] = (
result[CONSUMED_HEATING_TOTAL] + result[CONSUMED_HEATING_TODAY]
result[CONSUMED_HEATING] = self.assign_if_increased(
result[CONSUMED_HEATING_TOTAL] + result[CONSUMED_HEATING_TODAY], CONSUMED_HEATING
)

result[CONSUMED_WATER_HEATING_TODAY] = consumed_water_today
result[CONSUMED_WATER_HEATING_TOTAL] = (
consumed_water_total_high * 1000 + consumed_water_total_low
result[CONSUMED_WATER_HEATING_TOTAL] = self.assign_if_increased(
consumed_water_total_high * 1000 + consumed_water_total_low, CONSUMED_WATER_HEATING_TOTAL
)
result[CONSUMED_WATER_HEATING] = (
result[CONSUMED_WATER_HEATING] = self.assign_if_increased(
result[CONSUMED_WATER_HEATING_TOTAL]
+ result[CONSUMED_WATER_HEATING_TODAY]
+ result[CONSUMED_WATER_HEATING_TODAY], CONSUMED_WATER_HEATING
)
return result

Expand Down

0 comments on commit c93ebf3

Please sign in to comment.