Skip to content

Commit

Permalink
rainy sunday
Browse files Browse the repository at this point in the history
  • Loading branch information
marq24 committed Jun 30, 2024
1 parent a5c552c commit 6d60309
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion custom_components/evcc_intg/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"iot_class": "local_polling",
"issue_tracker": "https://github.com/marq24/ha-evcc/issues",
"requirements": [],
"version": "2024.6.4"
"version": "2024.6.5"
}
16 changes: 16 additions & 0 deletions custom_components/evcc_intg/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.restore_state import RestoreEntity

from custom_components.evcc_intg.pyevcc_ha.keys import Tag
from . import EvccDataUpdateCoordinator, EvccBaseEntity
from .const import DOMAIN, SENSOR_SENSORS, SENSOR_SENSORS_PER_LOADPOINT, ExtSensorEntityDescription

Expand Down Expand Up @@ -65,6 +66,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, add_
class EvccSensor(EvccBaseEntity, SensorEntity, RestoreEntity):
def __init__(self, coordinator: EvccDataUpdateCoordinator, description: ExtSensorEntityDescription):
super().__init__(coordinator=coordinator, description=description)
self._previous_float_value: float | None = None

@property
def state(self):
Expand Down Expand Up @@ -105,5 +107,19 @@ def state(self):
elif value is False:
value = "off"

# make sure that we do not return unknown or smaller values
# [see https://github.com/marq24/ha-evcc/discussions/7]
if self.tag == Tag.CHARGETOTALIMPORT:
if value == "unknown":
if self._previous_float_value is not None:
return self._previous_float_value
else:
a_float_value = float(value)
if self._previous_float_value is not None and a_float_value < self._previous_float_value:
_LOGGER.debug(f"prev>new for key {self._attr_translation_key} [prev: '{self._previous_float_value}' new: '{a_float_value}']")
return self._previous_float_value
else:
self._previous_float_value = a_float_value

# sensor state must be string?!
return value

0 comments on commit 6d60309

Please sign in to comment.