mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-11 00:54:28 +05:00
edit readme
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user