only bin sensors can update state in http mode

This commit is contained in:
Викторов Андрей Германович
2021-10-28 15:57:55 +03:00
parent 4145eebbdd
commit 76b8988b83
3 changed files with 4 additions and 2 deletions

View File

@@ -67,6 +67,7 @@ class MegaBinarySensor(BinarySensorEntity, MegaPushEntity):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.mega.binary_sensors.append(self.port)
self._is_on = None
self._attrs = None
self._click_task = None

View File

@@ -134,7 +134,7 @@ class MegaView(HomeAssistantView):
if ret == 'd' and act:
await hub.request(cmd=act.replace(':3', f':{v}'))
ret = 'd' if hub.force_d else ''
else:
elif port in hub.binary_sensors:
hub.values[port] = data
for cb in self.callbacks[hub.id][port]:
cb(data)
@@ -147,7 +147,7 @@ class MegaView(HomeAssistantView):
_LOGGER.debug('response %s', ret)
Response(body='' if hub.fake_response else ret, content_type='text/plain')
if hub.fake_response and 'value' not in data and 'pt' in data:
if hub.fake_response and 'value' not in data and 'pt' in data and port in hub.binary_sensors:
if 'd' in ret:
await hub.request(pt=port, cmd=ret)
else:

View File

@@ -164,6 +164,7 @@ class MegaD:
hass.data[DOMAIN][CONF_HTTP].protected = protected
except Exception:
self.lg.exception('while setting allowed hosts')
self.binary_sensors = []
async def start(self):
pass