mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-11 09:04:27 +05:00
add hex_to_float option
add auto config reload on megad restart fix reloading issues
This commit is contained in:
@@ -16,7 +16,7 @@ from homeassistant.components import mqtt
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from .const import DOMAIN, CONF_INVERT, CONF_RELOAD, PLATFORMS, CONF_PORTS, CONF_CUSTOM, CONF_SKIP, CONF_PORT_TO_SCAN, \
|
||||
CONF_MQTT_INPUTS, CONF_HTTP, CONF_RESPONSE_TEMPLATE, CONF_ACTION, CONF_GET_VALUE, CONF_ALLOW_HOSTS, \
|
||||
CONF_CONV_TEMPLATE, CONF_ALL, CONF_FORCE_D, CONF_DEF_RESPONSE, CONF_FORCE_I2C_SCAN
|
||||
CONF_CONV_TEMPLATE, CONF_ALL, CONF_FORCE_D, CONF_DEF_RESPONSE, CONF_FORCE_I2C_SCAN, CONF_HEX_TO_FLOAT
|
||||
from .hub import MegaD
|
||||
from .config_flow import ConfigFlow
|
||||
from .http import MegaView
|
||||
@@ -47,6 +47,7 @@ CUSTOMIZE_PORT = {
|
||||
vol.Optional(CONF_CONV_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_FORCE_I2C_SCAN): bool,
|
||||
vol.Optional(CONF_HEX_TO_FLOAT): bool,
|
||||
}
|
||||
CUSTOMIZE_DS2413 = {
|
||||
vol.Optional(str.lower, description='адрес и индекс устройства'): CUSTOMIZE_PORT
|
||||
@@ -133,7 +134,7 @@ async def get_hub(hass, entry):
|
||||
break
|
||||
if _mqtt is None:
|
||||
raise Exception('mqtt not configured, please configure mqtt first')
|
||||
hub = MegaD(hass, **data, mqtt=_mqtt, lg=_LOGGER, loop=asyncio.get_event_loop())
|
||||
hub = MegaD(hass, config=entry, **data, mqtt=_mqtt, lg=_LOGGER, loop=asyncio.get_event_loop())
|
||||
hub.mqtt_id = await hub.get_mqtt_id()
|
||||
return hub
|
||||
|
||||
@@ -177,14 +178,11 @@ async def updater(hass: HomeAssistant, entry: ConfigEntry):
|
||||
hub.poll_interval = entry.options[CONF_SCAN_INTERVAL]
|
||||
hub.port_to_scan = entry.options.get(CONF_PORT_TO_SCAN, 0)
|
||||
entry.data = entry.options
|
||||
for platform in PLATFORMS:
|
||||
await hass.config_entries.async_forward_entry_unload(entry, platform)
|
||||
await async_remove_entry(hass, entry)
|
||||
await async_setup_entry(hass, entry)
|
||||
await hass.config_entries.async_reload(entry.entry_id)
|
||||
return True
|
||||
|
||||
|
||||
async def async_remove_entry(hass, entry) -> None:
|
||||
async def async_remove_entry(hass: HomeAssistant, entry: ConfigEntry) -> None:
|
||||
"""Handle removal of an entry."""
|
||||
id = entry.data.get('id', entry.entry_id)
|
||||
hub: MegaD = hass.data[DOMAIN].get(id)
|
||||
@@ -194,12 +192,17 @@ async def async_remove_entry(hass, entry) -> None:
|
||||
_hubs.pop(id, None)
|
||||
hass.data[DOMAIN].pop(id, None)
|
||||
hass.data[DOMAIN][CONF_ALL].pop(id, None)
|
||||
for platform in PLATFORMS:
|
||||
await hass.config_entries.async_forward_entry_unload(entry, platform)
|
||||
task: asyncio.Task = _POLL_TASKS.pop(id, None)
|
||||
if task is not None:
|
||||
task.cancel()
|
||||
if hub is None:
|
||||
return
|
||||
await hub.stop()
|
||||
return True
|
||||
|
||||
async_unload_entry = async_remove_entry
|
||||
|
||||
|
||||
async def async_migrate_entry(hass, config_entry: ConfigEntry):
|
||||
|
||||
Reference in New Issue
Block a user