mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-12 09:34:28 +05:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8dfa5926ad | ||
|
|
3978ce2203 | ||
|
|
72cf516353 | ||
|
|
3b6459468b | ||
|
|
2e025eb0c2 | ||
|
|
20d5b8ff40 |
@@ -160,7 +160,8 @@ async def async_remove_entry(hass, entry) -> None:
|
|||||||
if hub is None:
|
if hub is None:
|
||||||
return
|
return
|
||||||
_LOGGER.debug(f'remove {id}')
|
_LOGGER.debug(f'remove {id}')
|
||||||
_hubs.pop(entry.entry_id)
|
_hubs.pop(id, None)
|
||||||
|
hass.data[DOMAIN].pop(id, None)
|
||||||
task: asyncio.Task = _POLL_TASKS.pop(id, None)
|
task: asyncio.Task = _POLL_TASKS.pop(id, None)
|
||||||
if task is not None:
|
if task is not None:
|
||||||
task.cancel()
|
task.cancel()
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from homeassistant.const import CONF_NAME
|
|||||||
from homeassistant.core import State
|
from homeassistant.core import State
|
||||||
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
from .hub import MegaD
|
from . import hub as h
|
||||||
from .const import DOMAIN, CONF_CUSTOM, CONF_INVERT, EVENT_BINARY_SENSOR, LONG, \
|
from .const import DOMAIN, CONF_CUSTOM, CONF_INVERT, EVENT_BINARY_SENSOR, LONG, \
|
||||||
LONG_RELEASE, RELEASE, PRESS, SINGLE_CLICK, DOUBLE_CLICK, EVENT_BINARY
|
LONG_RELEASE, RELEASE, PRESS, SINGLE_CLICK, DOUBLE_CLICK, EVENT_BINARY
|
||||||
|
|
||||||
@@ -19,6 +19,11 @@ async def _set_events_on():
|
|||||||
_LOGGER.debug('events on')
|
_LOGGER.debug('events on')
|
||||||
_events_on = True
|
_events_on = True
|
||||||
|
|
||||||
|
|
||||||
|
def set_events_off():
|
||||||
|
global _events_on
|
||||||
|
_events_on = False
|
||||||
|
|
||||||
_task_set_ev_on = None
|
_task_set_ev_on = None
|
||||||
|
|
||||||
|
|
||||||
@@ -30,7 +35,7 @@ class BaseMegaEntity(CoordinatorEntity, RestoreEntity):
|
|||||||
"""
|
"""
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
mega: MegaD,
|
mega: 'h.MegaD',
|
||||||
port: int,
|
port: int,
|
||||||
config_entry: ConfigEntry = None,
|
config_entry: ConfigEntry = None,
|
||||||
id_suffix=None,
|
id_suffix=None,
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ from homeassistant.core import HomeAssistant
|
|||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
from homeassistant.helpers.update_coordinator import DataUpdateCoordinator
|
||||||
from .const import TEMP, HUM, PATT_SPLIT, DOMAIN, CONF_HTTP, EVENT_BINARY_SENSOR
|
from .const import TEMP, HUM, PATT_SPLIT, DOMAIN, CONF_HTTP, EVENT_BINARY_SENSOR
|
||||||
|
from .entities import set_events_off
|
||||||
from .exceptions import CannotConnect
|
from .exceptions import CannotConnect
|
||||||
from .tools import make_ints
|
from .tools import make_ints
|
||||||
|
|
||||||
@@ -109,6 +110,7 @@ class MegaD:
|
|||||||
async def start(self):
|
async def start(self):
|
||||||
self.loop = asyncio.get_event_loop()
|
self.loop = asyncio.get_event_loop()
|
||||||
if self.mqtt is not None:
|
if self.mqtt is not None:
|
||||||
|
set_events_off()
|
||||||
self.subs = await self.mqtt.async_subscribe(
|
self.subs = await self.mqtt.async_subscribe(
|
||||||
topic=f"{self.mqtt_id}/+",
|
topic=f"{self.mqtt_id}/+",
|
||||||
msg_callback=self._process_msg,
|
msg_callback=self._process_msg,
|
||||||
@@ -207,11 +209,13 @@ class MegaD:
|
|||||||
def parse_response(self, ret):
|
def parse_response(self, ret):
|
||||||
if ret is None:
|
if ret is None:
|
||||||
raise NoPort()
|
raise NoPort()
|
||||||
|
if 'busy' in ret:
|
||||||
|
return None
|
||||||
if ':' in ret:
|
if ':' in ret:
|
||||||
ret = PATT_SPLIT.split(ret)
|
ret = PATT_SPLIT.split(ret)
|
||||||
ret = dict([
|
ret = {'value': dict([
|
||||||
x.split(':') for x in ret if x.count(':') == 1
|
x.split(':') for x in ret if x.count(':') == 1
|
||||||
])
|
])}
|
||||||
elif 'ON' in ret:
|
elif 'ON' in ret:
|
||||||
ret = {'value': 'ON'}
|
ret = {'value': 'ON'}
|
||||||
elif 'OFF' in ret:
|
elif 'OFF' in ret:
|
||||||
@@ -227,13 +231,16 @@ class MegaD:
|
|||||||
"""
|
"""
|
||||||
self.lg.debug(f'get port %s', port)
|
self.lg.debug(f'get port %s', port)
|
||||||
if self.mqtt is None or force_http:
|
if self.mqtt is None or force_http:
|
||||||
ret = await self.request(pt=port, cmd=http_cmd)
|
if http_cmd == 'list':
|
||||||
ret = self.parse_response(ret)
|
await self.request(pt=port, cmd='conv')
|
||||||
self.lg.debug('parsed: %s', ret)
|
|
||||||
if http_cmd == 'list' and isinstance(ret, dict) and 'value' in ret:
|
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
ret = await self.request(pt=port, http_cmd=http_cmd)
|
ret = self.parse_response(await self.request(pt=port, cmd=http_cmd))
|
||||||
ret = self.parse_response(ret)
|
ntry = 0
|
||||||
|
while http_cmd == 'list' and ret is None and ntry < 3:
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
ret = self.parse_response(await self.request(pt=port, cmd=http_cmd))
|
||||||
|
ntry += 1
|
||||||
|
self.lg.debug('parsed: %s', ret)
|
||||||
self.values[port] = ret
|
self.values[port] = ret
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ from homeassistant.const import (
|
|||||||
CONF_DOMAIN,
|
CONF_DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from .entities import MegaD
|
from . import hub as h
|
||||||
from .entities import MegaOutPort
|
from .entities import MegaOutPort
|
||||||
from .const import CONF_DIMMER, CONF_SWITCH, DOMAIN, CONF_CUSTOM, CONF_SKIP
|
from .const import CONF_DIMMER, CONF_SWITCH, DOMAIN, CONF_CUSTOM, CONF_SKIP
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ async def async_setup_platform(hass, config, add_entities, discovery_info=None):
|
|||||||
|
|
||||||
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_devices):
|
async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, async_add_devices):
|
||||||
mid = config_entry.data[CONF_ID]
|
mid = config_entry.data[CONF_ID]
|
||||||
hub: MegaD = hass.data['mega'][mid]
|
hub: 'h.MegaD' = hass.data['mega'][mid]
|
||||||
devices = []
|
devices = []
|
||||||
|
|
||||||
customize = hass.data.get(DOMAIN, {}).get(CONF_CUSTOM, {})
|
customize = hass.data.get(DOMAIN, {}).get(CONF_CUSTOM, {})
|
||||||
|
|||||||
@@ -17,8 +17,11 @@
|
|||||||
"username": "Користувач",
|
"username": "Користувач",
|
||||||
"id": "ID",
|
"id": "ID",
|
||||||
"mqtt_id": "MQTT id",
|
"mqtt_id": "MQTT id",
|
||||||
"scan_interval": "Період оновлення (сек.)",
|
"scan_interval": "Період оновлення (сек.), 0 - не оновлювати",
|
||||||
"port_to_scan": "Порт для сканування при відсутності датчиків"
|
"port_to_scan": "Порт для сканування при відсутності датчиків",
|
||||||
|
"mqtt_inputs": "Використовувати MQTT",
|
||||||
|
"nports": "Кількість портів",
|
||||||
|
"update_all": "Оновити всі виходи коли спрацьовує вхід"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,7 +33,10 @@
|
|||||||
"scan_interval": "Період оновлення (сек.)",
|
"scan_interval": "Період оновлення (сек.)",
|
||||||
"port_to_scan": "Порт для сканування при відсутності датчиків",
|
"port_to_scan": "Порт для сканування при відсутності датчиків",
|
||||||
"reload": "Оновити об'єкти",
|
"reload": "Оновити об'єкти",
|
||||||
"invert": "Список портів з інвертованою логікою (через ,)"
|
"invert": "Список портів з інвертованою логікою (через ,)",
|
||||||
|
"mqtt_inputs": "Використовувати MQTT",
|
||||||
|
"nports": "Кількість портів",
|
||||||
|
"update_all": "Оновити всі виходи коли спрацьовує вхід"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user