башфикс сервисов, ускорение загрузки

This commit is contained in:
Andrey
2021-01-14 20:46:05 +03:00
parent d6191ba46a
commit 6a02a7e98c
5 changed files with 91 additions and 68 deletions

View File

@@ -1,4 +1,5 @@
"""Platform for light integration."""
import asyncio
import logging
import voluptuous as vol
@@ -77,11 +78,15 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry, asyn
mid = config_entry.data[CONF_ID]
hub: MegaD = hass.data['mega'][mid]
devices = []
async for port, pty, m in hub.scan_ports():
if pty == "1" and m in ['0', '1']:
light = MegaLight(mega_id=mid, port=port, dimmer=m == '1')
devices.append(light)
async_add_devices(devices)
async def scan_ports():
async for port, pty, m in hub.scan_ports():
if pty == "1" and m in ['0', '1']:
light = MegaLight(mega_id=mid, port=port, dimmer=m == '1')
devices.append(light)
async_add_devices(devices)
asyncio.create_task(scan_ports())
class MegaLight(LightEntity, BaseMegaEntity):