mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-10 16:44:28 +05:00
find mega by mdid
This commit is contained in:
@@ -128,8 +128,7 @@ async def get_hub(hass, entry):
|
||||
async def _add_mega(hass: HomeAssistant, entry: ConfigEntry):
|
||||
id = entry.data.get('id', entry.entry_id)
|
||||
hub = await get_hub(hass, entry)
|
||||
hass.data[DOMAIN][id] = hass.data[DOMAIN]['__def'] = hub
|
||||
hass.data[DOMAIN][entry.data.get(CONF_HOST)] = hub
|
||||
hass.data[DOMAIN][id] = hub
|
||||
hass.data[DOMAIN][CONF_ALL][id] = hub
|
||||
if not await hub.authenticate():
|
||||
raise Exception("not authentificated")
|
||||
|
||||
@@ -62,7 +62,7 @@ async def validate_input(hass: core.HomeAssistant, data):
|
||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow for mega."""
|
||||
|
||||
VERSION = 10
|
||||
VERSION = 11
|
||||
CONNECTION_CLASS = config_entries.CONN_CLASS_ASSUMED
|
||||
|
||||
async def async_step_user(self, user_input=None):
|
||||
|
||||
@@ -36,9 +36,10 @@ class MegaView(HomeAssistantView):
|
||||
} for mid in cfg if isinstance(cfg[mid], dict)
|
||||
}
|
||||
_LOGGER.debug('templates: %s', self.templates)
|
||||
self.hubs = {}
|
||||
|
||||
async def get(self, request: Request) -> Response:
|
||||
|
||||
_LOGGER.debug('request from %s %s', request.remote, request.headers)
|
||||
hass: HomeAssistant = request.app['hass']
|
||||
if self.protected:
|
||||
auth = False
|
||||
@@ -63,10 +64,14 @@ class MegaView(HomeAssistantView):
|
||||
_LOGGER.warning(msg)
|
||||
return Response(status=401)
|
||||
|
||||
hub: 'h.MegaD' = hass.data.get(DOMAIN).get(request.remote) # TODO: проверить какой remote
|
||||
if hub is None and request.remote == '::1':
|
||||
hub = hass.data.get(DOMAIN).get('__def')
|
||||
if hub is None:
|
||||
hub: 'h.MegaD' = self.hubs.get(request.remote)
|
||||
if hub is None and 'mdid' in request.query:
|
||||
hub = self.hubs.get(request.query['mdid'])
|
||||
if hub is None:
|
||||
_LOGGER.warning(f'can not find mdid={request.query["mdid"]} in {list(self.hubs)}')
|
||||
if hub is None and request.remote in ['::1', '127.0.0.1']:
|
||||
hub = self.hubs.get('__def')
|
||||
elif hub is None:
|
||||
return Response(status=400)
|
||||
data = dict(request.query)
|
||||
hass.bus.async_fire(
|
||||
|
||||
@@ -85,6 +85,11 @@ class MegaD:
|
||||
self.http = hass.data.get(DOMAIN, {}).get(CONF_HTTP)
|
||||
if not self.http is None:
|
||||
self.http.allowed_hosts |= {host}
|
||||
self.http.hubs[host] = self
|
||||
if len(self.http.hubs) == 1:
|
||||
self.http.hubs['__def'] = self
|
||||
if mqtt_id:
|
||||
self.http.hubs[mqtt_id] = self
|
||||
else:
|
||||
self.http = None
|
||||
self.poll_outs = poll_outs
|
||||
@@ -475,6 +480,7 @@ class MegaD:
|
||||
|
||||
async def get_config(self, nports=37):
|
||||
ret = defaultdict(lambda: defaultdict(list))
|
||||
ret['mqtt_id'] = await self.get_mqtt_id()
|
||||
async for port, pty, m in self.scan_ports(nports):
|
||||
if pty == "0":
|
||||
ret['binary_sensor'][port].append({})
|
||||
|
||||
@@ -58,6 +58,10 @@ wget -q -O - https://raw.githubusercontent.com/andvikt/mega_hacs/master/install.
|
||||
srv: "192.168.1.4:8123" # ip:port вашего HA
|
||||
script: "mega" # это api интеграции, к которому будет обращаться контроллер
|
||||
```
|
||||
Так же необходимо настроить Mega-ID в настройках контроллера, для каждой меги id должен быть разным.
|
||||
|
||||
При любых изменениях настроек контроллера (типы входов, id и тд) необходимо в настройках интеграции нажать `Обновить
|
||||
объекты`
|
||||
|
||||
## Зависимости
|
||||
Для максимальной скорости реакции на команды сервера, рекомендуется выключить `имитацию http-ответа` в
|
||||
|
||||
Reference in New Issue
Block a user