From b609bae49384f14a7dfd41ea1c00bf493b110d24 Mon Sep 17 00:00:00 2001 From: Philipp Grimm Date: Tue, 13 Feb 2024 22:46:12 +0100 Subject: [PATCH] debug last message received --- custom_components/eltako/binary_sensor.py | 14 -------------- custom_components/eltako/device.py | 9 +++++---- tests/test_device_entity.py | 2 +- 3 files changed, 6 insertions(+), 19 deletions(-) diff --git a/custom_components/eltako/binary_sensor.py b/custom_components/eltako/binary_sensor.py index 3fb883da..cb8e03d3 100644 --- a/custom_components/eltako/binary_sensor.py +++ b/custom_components/eltako/binary_sensor.py @@ -70,16 +70,6 @@ def __init__(self, platform: str, gateway: EnOceanGateway, dev_id: AddressExpres self.invert_signal = invert_signal self._attr_device_class = device_class - @property - def last_received_signal(self): - """Return timestamp of last received signal.""" - return self._attr_last_received_signal - - @property - def data(self): - """Return telegram data for rocker switch.""" - return self._attr_data - def value_changed(self, msg: ESP2Message): """Fire an event with the data that have changed. @@ -241,10 +231,6 @@ def __init__(self, platform: str, gateway: EnOceanGateway): super().__init__(platform, gateway, gateway.base_id, "Connected") self.gateway.set_connection_state_changed_handler(self.async_value_changed) - def load_value_initially(self, state: str): - self.value_changed( state.lower() == "true" ) - self.schedule_update_ha_state() - @property def device_info(self) -> DeviceInfo: """Return the device info.""" diff --git a/custom_components/eltako/device.py b/custom_components/eltako/device.py index a5c01003..014192d3 100644 --- a/custom_components/eltako/device.py +++ b/custom_components/eltako/device.py @@ -22,7 +22,7 @@ class EltakoEntity(Entity): """Parent class for all entities associated with the Eltako component.""" _attr_has_entity_name = True - _attr_should_poll = True + _attr_should_poll = False def __init__(self, platform: str, gateway: EnOceanGateway, dev_id: AddressExpression, dev_name: str="Device", dev_eep: EEP=None): """Initialize the device.""" @@ -100,10 +100,10 @@ async def async_added_to_hass(self) -> None: if is_value_available is None: latest_state:State = await self.async_get_last_state() if latest_state is not None: - self.load_value_initially(latest_state) + await self.async_load_value_initially(latest_state) - def load_value_initially(self, latest_state:State): + async def async_load_value_initially(self, latest_state:State): # cast state:str to actual value attributs = latest_state.attributes LOGGER.debug(f"[device] eneity unique_id: {self.unique_id}") @@ -144,7 +144,8 @@ def load_value_initially(self, latest_state:State): elif hasattr(self, '_attr_native_value'): LOGGER.debug(f"[device] latest state - set {self._attr_native_value}") - self.schedule_update_ha_state(force_refresh=True) + # await self.async_schedule_update_ha_state(force_refresh=True) + self.async_write_ha_state() def validate_dev_id(self) -> bool: diff --git a/tests/test_device_entity.py b/tests/test_device_entity.py index 6c7750bd..441e08b5 100644 --- a/tests/test_device_entity.py +++ b/tests/test_device_entity.py @@ -43,6 +43,6 @@ def test_load_initial_values(self): ee = EltakoEntity(pl, gw, address, name, F6_02_01) ee._attr_is_on = None - ee.load_value_initially(LatestStateMock("true", {})) + ee.async_load_value_initially(LatestStateMock("true", {})) # self.assertTrue(ee._attr_is_on) \ No newline at end of file