From 7d408dfba578a27d6ec237e004d4141fc548973c Mon Sep 17 00:00:00 2001 From: dala318 Date: Wed, 4 Sep 2024 13:16:53 +0000 Subject: [PATCH] Back to basics, remove the async_track_state_change_event --- .../nordpool_planner/__init__.py | 22 ++++++++----- tests/test_planner.py | 32 +++++++++---------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/custom_components/nordpool_planner/__init__.py b/custom_components/nordpool_planner/__init__.py index d4a8b48..247353e 100644 --- a/custom_components/nordpool_planner/__init__.py +++ b/custom_components/nordpool_planner/__init__.py @@ -106,12 +106,12 @@ def __init__(self, hass: HomeAssistant, config_entry: ConfigEntry) -> None: # Internal states self._np_entity = NordpoolEntity(self._config.data[CONF_NP_ENTITY]) - # TODO: Dont seem to work as expected! - async_track_state_change_event( - self._hass, - [self._np_entity.unique_id], - self._async_input_changed, - ) + # # TODO: Dont seem to work as expected! + # async_track_state_change_event( + # self._hass, + # [self._np_entity.unique_id], + # self._async_input_changed, + # ) # Configuration entities self._duration_number_entity = "" @@ -501,14 +501,20 @@ def valid(self) -> bool: @property def average(self) -> float: """The average price of the price group.""" - if not self.valid: - return 1 + # if not self.valid: + # _LOGGER.warning( + # "Average set to 1 for invalid price group, should not happen" + # ) + # return 1 return sum([p["value"] for p in self._prices]) / len(self._prices) @property def start_time(self) -> dt.datetime: """The start time of first price in group.""" # if not self.valid: + # _LOGGER.warning( + # "Start time set to None for invalid price group, should not happen" + # ) # return None return self._prices[0]["start"] diff --git a/tests/test_planner.py b/tests/test_planner.py index 3835faa..6b05270 100644 --- a/tests/test_planner.py +++ b/tests/test_planner.py @@ -65,24 +65,24 @@ async def async_setup_entry_init( unique_id="123456", ) - # Unnamed binary sensor with device class but has_entity_name False -> no name - np_sensor = sensor.SensorEntity() - np_sensor.entity_id = NP_ENT - np_sensor._attr_device_class = sensor.SensorDeviceClass.MONETARY + # # Fake nordpool sensor + # np_sensor = sensor.SensorEntity() + # np_sensor.entity_id = NP_ENT + # np_sensor._attr_device_class = sensor.SensorDeviceClass.MONETARY - async def async_setup_entry_platform( - hass: HomeAssistant, - config_entry: config_entries.ConfigEntry, - async_add_entities: AddEntitiesCallback, - ) -> None: - """Set up test sensor platform via config entry.""" - async_add_entities([np_sensor]) + # async def async_setup_entry_platform( + # hass: HomeAssistant, + # config_entry: config_entries.ConfigEntry, + # async_add_entities: AddEntitiesCallback, + # ) -> None: + # """Set up test sensor platform via config entry.""" + # async_add_entities([np_sensor]) - mock_platform( - hass, - f"{"nordpool"}.{sensor.DOMAIN}", - MockPlatform(async_setup_entry=async_setup_entry_platform), - ) + # mock_platform( + # hass, + # f"{"nordpool"}.{sensor.DOMAIN}", + # MockPlatform(async_setup_entry=async_setup_entry_platform), + # ) planner = NordpoolPlanner(hass, config_entry)