mirror of
https://github.com/andvikt/mega_hacs.git
synced 2025-12-11 17:14:28 +05:00
add hex_to_float option
add auto config reload on megad restart fix reloading issues
This commit is contained in:
@@ -174,10 +174,9 @@ async def updater(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
:param entry:
|
:param entry:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
hub: MegaD = hass.data[DOMAIN][entry.data[CONF_ID]]
|
# hub: MegaD = hass.data[DOMAIN][entry.data[CONF_ID]]
|
||||||
hub.poll_interval = entry.options[CONF_SCAN_INTERVAL]
|
# hub.poll_interval = entry.options[CONF_SCAN_INTERVAL]
|
||||||
hub.port_to_scan = entry.options.get(CONF_PORT_TO_SCAN, 0)
|
# hub.port_to_scan = entry.options.get(CONF_PORT_TO_SCAN, 0)
|
||||||
entry.data = entry.options
|
|
||||||
await hass.config_entries.async_reload(entry.entry_id)
|
await hass.config_entries.async_reload(entry.entry_id)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
@@ -117,24 +117,19 @@ class OptionsFlowHandler(config_entries.OptionsFlow):
|
|||||||
async def async_step_init(self, user_input=None):
|
async def async_step_init(self, user_input=None):
|
||||||
"""Manage the options."""
|
"""Manage the options."""
|
||||||
new_naming = self.config_entry.data.get('new_naming', False)
|
new_naming = self.config_entry.data.get('new_naming', False)
|
||||||
hub = await get_hub(self.hass, self.config_entry.data)
|
|
||||||
if user_input is not None:
|
if user_input is not None:
|
||||||
reload = user_input.pop(CONF_RELOAD)
|
reload = user_input.pop(CONF_RELOAD)
|
||||||
cfg = dict(self.config_entry.data)
|
cfg = dict(self.config_entry.data)
|
||||||
cfg.update(user_input)
|
cfg.update(user_input)
|
||||||
hub = await get_hub(self.hass, cfg)
|
|
||||||
if reload:
|
|
||||||
await hub.start()
|
|
||||||
new = await hub.get_config(nports=user_input.get(CONF_NPORTS, 37))
|
|
||||||
await hub.stop()
|
|
||||||
|
|
||||||
_LOGGER.debug(f'new config: %s', new)
|
|
||||||
cfg = dict(self.config_entry.data)
|
|
||||||
for x in REMOVE_CONFIG:
|
|
||||||
cfg.pop(x, None)
|
|
||||||
cfg.update(new)
|
|
||||||
|
|
||||||
cfg['new_naming'] = new_naming
|
cfg['new_naming'] = new_naming
|
||||||
|
self.config_entry.data = cfg
|
||||||
|
await get_hub(self.hass, cfg)
|
||||||
|
|
||||||
|
if reload:
|
||||||
|
id = self.config_entry.data.get('id', self.config_entry.entry_id)
|
||||||
|
hub: MegaD = self.hass.data[DOMAIN].get(id)
|
||||||
|
await hub.reload(reload_entry=False)
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title='',
|
title='',
|
||||||
data=cfg,
|
data=cfg,
|
||||||
|
|||||||
@@ -65,13 +65,13 @@ class MegaD:
|
|||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
config: ConfigEntry,
|
|
||||||
loop: asyncio.AbstractEventLoop,
|
loop: asyncio.AbstractEventLoop,
|
||||||
host: str,
|
host: str,
|
||||||
password: str,
|
password: str,
|
||||||
mqtt: mqtt.MQTT,
|
mqtt: mqtt.MQTT,
|
||||||
lg: logging.Logger,
|
lg: logging.Logger,
|
||||||
id: str,
|
id: str,
|
||||||
|
config: ConfigEntry = None,
|
||||||
mqtt_inputs: bool = True,
|
mqtt_inputs: bool = True,
|
||||||
mqtt_id: str = None,
|
mqtt_id: str = None,
|
||||||
scan_interval=60,
|
scan_interval=60,
|
||||||
@@ -625,7 +625,7 @@ class MegaD:
|
|||||||
stime=datetime.now().strftime('%H:%M:%S')
|
stime=datetime.now().strftime('%H:%M:%S')
|
||||||
)
|
)
|
||||||
|
|
||||||
async def reload(self):
|
async def reload(self, reload_entry=True):
|
||||||
new = await self.get_config(nports=self.nports)
|
new = await self.get_config(nports=self.nports)
|
||||||
self.lg.debug(f'new config: %s', new)
|
self.lg.debug(f'new config: %s', new)
|
||||||
cfg = dict(self.config.data)
|
cfg = dict(self.config.data)
|
||||||
@@ -633,4 +633,5 @@ class MegaD:
|
|||||||
cfg.pop(x, None)
|
cfg.pop(x, None)
|
||||||
cfg.update(new)
|
cfg.update(new)
|
||||||
self.config.data = cfg
|
self.config.data = cfg
|
||||||
await self.hass.config_entries.async_reload(self.config.entry_id)
|
if reload_entry:
|
||||||
|
await self.hass.config_entries.async_reload(self.config.entry_id)
|
||||||
|
|||||||
Reference in New Issue
Block a user