edit readme

This commit is contained in:
Andrey
2021-01-22 10:48:00 +03:00
parent 9755a9c654
commit fa1c3330ba
3 changed files with 52 additions and 6 deletions

View File

@@ -65,6 +65,11 @@ class MegaBinarySensor(BinarySensorEntity, MegaPushEntity):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._is_on = None
self._attrs = None
@property
def state_attributes(self):
return self._attrs
@property
def is_on(self) -> bool:
@@ -77,9 +82,11 @@ class MegaBinarySensor(BinarySensorEntity, MegaPushEntity):
payload = payload.copy()
payload.pop(CONF_PORT)
data.update(payload)
self.hass.bus.async_fire(
EVENT_BINARY_SENSOR,
data,
)
if not self.is_first_update:
self.hass.bus.async_fire(
EVENT_BINARY_SENSOR,
data,
)
val = payload.get("value")
self._is_on = val == 'ON'
self._is_on = val == 'ON'
self._attrs = data

View File

@@ -93,11 +93,13 @@ class MegaPushEntity(BaseMegaEntity):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.mega.subscribe(self.port, callback=self.__update)
self.is_first_update = True
def __update(self, value: dict):
self._update(value)
self.async_write_ha_state()
self.lg.debug(f'state after update %s', self.state)
self.is_first_update = False
return
def _update(self, payload: dict):