Skip to content

Commit

Permalink
debug last message received
Browse files Browse the repository at this point in the history
  • Loading branch information
grimmpp committed Feb 13, 2024
1 parent 78c4cd1 commit b609bae
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 19 deletions.
14 changes: 0 additions & 14 deletions custom_components/eltako/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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."""
Expand Down
9 changes: 5 additions & 4 deletions custom_components/eltako/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_device_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit b609bae

Please sign in to comment.