Skip to content

Commit

Permalink
Back to basics, remove the async_track_state_change_event
Browse files Browse the repository at this point in the history
  • Loading branch information
dala318 committed Sep 4, 2024
1 parent ca39195 commit 7d408df
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
22 changes: 14 additions & 8 deletions custom_components/nordpool_planner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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"]

Expand Down
32 changes: 16 additions & 16 deletions tests/test_planner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 7d408df

Please sign in to comment.