mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-12 01:24:29 +05:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1548e8c364 | ||
|
|
39c4ab0e3b | ||
|
|
a002e48e04 | ||
|
|
dc6bdfc8f4 | ||
|
|
e51b50797c |
@@ -59,7 +59,7 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity):
|
||||
"config_entries": [
|
||||
self.config_entry,
|
||||
],
|
||||
"name": f'port {self.port}',
|
||||
"name": f'{self._mega_id} port {self.port}',
|
||||
"manufacturer": 'ab-log.ru',
|
||||
# "model": self.light.productname,
|
||||
# "sw_version": self.light.swversion,
|
||||
|
||||
@@ -26,8 +26,7 @@ class MegaView(HomeAssistantView):
|
||||
def __init__(self, cfg: dict):
|
||||
self._try = 0
|
||||
self.allowed_hosts = {'::1'}
|
||||
self.callbacks: typing.DefaultDict[int, typing.List[typing.Callable[[dict], typing.Coroutine]]] \
|
||||
= defaultdict(list)
|
||||
self.callbacks = defaultdict(lambda: defaultdict(list))
|
||||
self.templates: typing.Dict[str, typing.Dict[str, Template]] = {
|
||||
mid: {
|
||||
pt: cfg[mid][pt][CONF_RESPONSE_TEMPLATE]
|
||||
@@ -64,7 +63,7 @@ class MegaView(HomeAssistantView):
|
||||
data = data.copy()
|
||||
ret = 'd'
|
||||
if port is not None:
|
||||
for cb in self.callbacks[port]:
|
||||
for cb in self.callbacks[hub.id][port]:
|
||||
cb(data)
|
||||
template: Template = self.templates.get(hub.id, {}).get(port)
|
||||
if hub.update_all:
|
||||
|
||||
@@ -60,8 +60,9 @@ class MegaD:
|
||||
):
|
||||
"""Initialize."""
|
||||
if mqtt_inputs is None or mqtt_inputs == 'None' or mqtt_inputs is False:
|
||||
self.http = hass.data[DOMAIN][CONF_HTTP]
|
||||
self.http.allowed_hosts |= {host}
|
||||
self.http = hass.data.get(DOMAIN, {}).get(CONF_HTTP)
|
||||
if not self.http is None:
|
||||
self.http.allowed_hosts |= {host}
|
||||
else:
|
||||
self.http = None
|
||||
self.update_all = update_all if update_all is not None else True
|
||||
@@ -306,7 +307,7 @@ class MegaD:
|
||||
if self.mqtt_inputs:
|
||||
self._callbacks[port].append(callback)
|
||||
else:
|
||||
self.http.callbacks[port].append(callback)
|
||||
self.http.callbacks[self.id][port].append(callback)
|
||||
|
||||
async def authenticate(self) -> bool:
|
||||
"""Test if we can authenticate with the host."""
|
||||
@@ -371,7 +372,7 @@ class MegaD:
|
||||
async for port, pty, m in self.scan_ports(nports):
|
||||
if pty == "0":
|
||||
ret['binary_sensor'][port].append({})
|
||||
elif pty == "1" and m in ['0', '1', '3']:
|
||||
elif pty == "1" and (m in ['0', '1', '3'] or m is None):
|
||||
ret['light'][port].append({'dimmer': m == '1'})
|
||||
elif pty == '3':
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user