mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-12 01:24:29 +05:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
75a41c9667 | ||
|
|
4f8f38fde6 | ||
|
|
7e02797be8 | ||
|
|
035bdebf64 | ||
|
|
8d92bbdfb3 | ||
|
|
0c43e61c59 | ||
|
|
0a71be693e |
@@ -57,7 +57,7 @@ async def validate_input(hass: core.HomeAssistant, data):
|
|||||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
"""Handle a config flow for mega."""
|
"""Handle a config flow for mega."""
|
||||||
|
|
||||||
VERSION = 6
|
VERSION = 7
|
||||||
CONNECTION_CLASS = config_entries.CONN_CLASS_ASSUMED
|
CONNECTION_CLASS = config_entries.CONN_CLASS_ASSUMED
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
|
|||||||
@@ -253,24 +253,25 @@ class MegaOutPort(MegaPushEntity):
|
|||||||
return self._state == 'ON'
|
return self._state == 'ON'
|
||||||
elif val is not None:
|
elif val is not None:
|
||||||
val = val.get("value")
|
val = val.get("value")
|
||||||
if self.index and self.addr:
|
if not isinstance(val, str) and self.index is not None and self.addr is not None:
|
||||||
if not isinstance(val, dict):
|
if not isinstance(val, dict):
|
||||||
self.mega.lg.warning(f'{self.entity_id}: {val} is not a dict')
|
self.mega.lg.warning(f'{self.entity_id}: {val} is not a dict')
|
||||||
return
|
return
|
||||||
_val = val.get(self.addr, val.get(self.addr.lower(), val.get(self.addr.upper())))
|
_val = val.get(self.addr, val.get(self.addr.lower(), val.get(self.addr.upper())))
|
||||||
if not isinstance(val, str):
|
if not isinstance(_val, str):
|
||||||
self.mega.lg.warning(f'{self.entity_id}: can not get {self.addr} from {val}, recieved {_val}')
|
self.mega.lg.warning(f'{self.entity_id}: can not get {self.addr} from {val}, recieved {_val}')
|
||||||
return
|
return
|
||||||
_val = _val.split('/')
|
_val = _val.split('/')
|
||||||
if len(_val) >= 2:
|
if len(_val) >= 2:
|
||||||
|
self.mega.lg.debug('%s parsed values: %s[%s]="%s"', self.entity_id, _val, self.index, _val)
|
||||||
val = _val[self.index]
|
val = _val[self.index]
|
||||||
else:
|
else:
|
||||||
self.mega.lg.warning(f'{self.entity_id}: {_val} has wrong length')
|
self.mega.lg.warning(f'{self.entity_id}: {_val} has wrong length')
|
||||||
return
|
return
|
||||||
elif self.index and self.addr is None:
|
elif self.index is not None and self.addr is None:
|
||||||
self.mega.lg.warning(f'{self.entity_id} does not has addr')
|
self.mega.lg.warning(f'{self.entity_id} does not has addr')
|
||||||
return
|
return
|
||||||
|
self.mega.lg.debug('%s.state = %s', self.entity_id, val)
|
||||||
if not self.invert:
|
if not self.invert:
|
||||||
return val == 'ON' or str(val) == '1' or (safe_int(val) is not None and safe_int(val) > 0)
|
return val == 'ON' or str(val) == '1' or (safe_int(val) is not None and safe_int(val) > 0)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class MegaView(HomeAssistantView):
|
|||||||
update_all = False
|
update_all = False
|
||||||
data['value'] = data.pop('v')
|
data['value'] = data.pop('v')
|
||||||
data['mega_id'] = hub.id
|
data['mega_id'] = hub.id
|
||||||
ret = 'd'
|
ret = 'd' if hub.force_d else ''
|
||||||
if port is not None:
|
if port is not None:
|
||||||
hub.values[port] = data
|
hub.values[port] = data
|
||||||
for cb in self.callbacks[hub.id][port]:
|
for cb in self.callbacks[hub.id][port]:
|
||||||
@@ -78,11 +78,13 @@ class MegaView(HomeAssistantView):
|
|||||||
template.hass = hass
|
template.hass = hass
|
||||||
ret = template.async_render(data)
|
ret = template.async_render(data)
|
||||||
_LOGGER.debug('response %s', ret)
|
_LOGGER.debug('response %s', ret)
|
||||||
ret = Response(body=ret or 'd', content_type='text/plain', headers={'Server': 's', 'Date': 'n'})
|
Response(body='', content_type='text/plain', headers={'Server': 's', 'Date': 'n'})
|
||||||
|
if ret:
|
||||||
|
await hub.request(cmd=ret)
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
async def later_update(self, hub):
|
async def later_update(self, hub):
|
||||||
_LOGGER.debug('force update')
|
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
_LOGGER.debug('force update')
|
||||||
await hub.updater.async_refresh()
|
await hub.updater.async_refresh()
|
||||||
|
|
||||||
|
|||||||
@@ -260,7 +260,10 @@ class MegaD:
|
|||||||
if 'busy' in ret:
|
if 'busy' in ret:
|
||||||
return None
|
return None
|
||||||
if ':' in ret:
|
if ':' in ret:
|
||||||
ret = ret.split(';')
|
if ';' in ret:
|
||||||
|
ret = ret.split(';')
|
||||||
|
elif '/' in ret:
|
||||||
|
ret = ret.split('/')
|
||||||
ret = {'value': dict([
|
ret = {'value': dict([
|
||||||
x.split(':') for x in ret if x.count(':') == 1
|
x.split(':') for x in ret if x.count(':') == 1
|
||||||
])}
|
])}
|
||||||
|
|||||||
Reference in New Issue
Block a user