mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-12 01:24:29 +05:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bd8b07dd90 | ||
|
|
d9b6ba3a50 | ||
|
|
1042592a31 | ||
|
|
137eb8b6ba |
@@ -67,6 +67,10 @@ class MegaBinarySensor(BinarySensorEntity, MegaPushEntity):
|
|||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self._is_on = None
|
self._is_on = None
|
||||||
self._attrs = None
|
self._attrs = None
|
||||||
|
self._click_task = None
|
||||||
|
|
||||||
|
async def _click(self):
|
||||||
|
await self.customize.get
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state_attributes(self):
|
def state_attributes(self):
|
||||||
|
|||||||
@@ -63,7 +63,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 = 16
|
VERSION = 17
|
||||||
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):
|
||||||
@@ -118,7 +118,7 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
|||||||
reload = user_input.pop(CONF_RELOAD)
|
reload = user_input.pop(CONF_RELOAD)
|
||||||
cfg = dict(self.config_entry.data)
|
cfg = dict(self.config_entry.data)
|
||||||
cfg.update(user_input)
|
cfg.update(user_input)
|
||||||
hub = await get_hub(self.hass, self.config_entry.data)
|
hub = await get_hub(self.hass, cfg)
|
||||||
if reload:
|
if reload:
|
||||||
await hub.start()
|
await hub.start()
|
||||||
new = await hub.get_config(nports=user_input.get(CONF_NPORTS, 37))
|
new = await hub.get_config(nports=user_input.get(CONF_NPORTS, 37))
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ CONF_POLL_OUTS = 'poll_outs'
|
|||||||
CONF_FORCE_D = 'force_d'
|
CONF_FORCE_D = 'force_d'
|
||||||
CONF_DEF_RESPONSE = 'def_response'
|
CONF_DEF_RESPONSE = 'def_response'
|
||||||
CONF_RESTORE_ON_RESTART = 'restore_on_restart'
|
CONF_RESTORE_ON_RESTART = 'restore_on_restart'
|
||||||
|
CONF_CLICK_TIME = 'click_time'
|
||||||
|
CONF_LONG_TIME = 'long_time'
|
||||||
PLATFORMS = [
|
PLATFORMS = [
|
||||||
"light",
|
"light",
|
||||||
"switch",
|
"switch",
|
||||||
|
|||||||
@@ -104,26 +104,28 @@ class MegaView(HomeAssistantView):
|
|||||||
if port in hub.extenders:
|
if port in hub.extenders:
|
||||||
pt_orig = port
|
pt_orig = port
|
||||||
else:
|
else:
|
||||||
pt_orig = hub.ext_in.get(port)
|
pt_orig = hub.ext_in.get(port, hub.ext_in.get(str(port)))
|
||||||
if pt_orig is None:
|
if pt_orig is None:
|
||||||
hub.lg.warning(f'can not find extender for int port {port}, '
|
hub.lg.warning(f'can not find extender for int port {port}, '
|
||||||
f'have ext_int: {hub.ext_in}, ext: {hub.extenders}')
|
f'have ext_int: {hub.ext_in}, ext: {hub.extenders}')
|
||||||
return Response(status=200)
|
return Response(status=200)
|
||||||
for e, v in data.items():
|
for e, v in data.items():
|
||||||
|
_data = data.copy()
|
||||||
if e.startswith('ext'):
|
if e.startswith('ext'):
|
||||||
idx = e[3:]
|
idx = e[3:]
|
||||||
pt = f'{pt_orig}e{idx}'
|
pt = f'{pt_orig}e{idx}'
|
||||||
data['pt_orig'] = pt_orig
|
_data['pt_orig'] = pt_orig
|
||||||
data['value'] = 'ON' if v == '1' else 'OFF'
|
_data['value'] = 'ON' if v == '1' else 'OFF'
|
||||||
data['m'] = 1 if data[e] == '0' else 0 # имитация поведения обычного входа, чтобы события обрабатывались аналогично
|
_data['m'] = 1 if _data[e] == '0' else 0 # имитация поведения обычного входа, чтобы события обрабатывались аналогично
|
||||||
hub.values[pt] = data
|
hub.values[pt] = _data
|
||||||
for cb in self.callbacks[hub.id][pt]:
|
for cb in self.callbacks[hub.id][pt]:
|
||||||
cb(data)
|
cb(_data)
|
||||||
act = hub.ext_act.get(pt)
|
act = hub.ext_act.get(pt)
|
||||||
|
hub.lg.debug(f'act on port {pt}: {act}, all acts are: {hub.ext_act}')
|
||||||
template: Template = self.templates.get(hub.id, {}).get(port, hub.def_response)
|
template: Template = self.templates.get(hub.id, {}).get(port, hub.def_response)
|
||||||
if template is not None:
|
if template is not None:
|
||||||
template.hass = hass
|
template.hass = hass
|
||||||
ret = template.async_render(data)
|
ret = template.async_render(_data)
|
||||||
if ret == 'd' and act:
|
if ret == 'd' and act:
|
||||||
await hub.request(cmd=act)
|
await hub.request(cmd=act)
|
||||||
ret = 'd' if hub.force_d else ''
|
ret = 'd' if hub.force_d else ''
|
||||||
|
|||||||
Reference in New Issue
Block a user