mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Allow reload of modbus (#67390)
* Allow reload of modbus. Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This commit is contained in:
parent
ad87d06d1f
commit
85c863a766
@ -35,6 +35,7 @@ import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.discovery import async_load_platform
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from homeassistant.helpers.event import async_call_later
|
||||
from homeassistant.helpers.reload import async_setup_reload_service
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .const import (
|
||||
@ -129,6 +130,11 @@ async def async_modbus_setup(
|
||||
) -> bool:
|
||||
"""Set up Modbus component."""
|
||||
|
||||
platform_names = []
|
||||
for entry in PLATFORMS:
|
||||
platform_names.append(entry[1])
|
||||
await async_setup_reload_service(hass, DOMAIN, platform_names)
|
||||
|
||||
hass.data[DOMAIN] = hub_collect = {}
|
||||
for conf_hub in config[DOMAIN]:
|
||||
my_hub = ModbusHub(hass, conf_hub)
|
||||
@ -239,6 +245,14 @@ async def async_modbus_setup(
|
||||
return True
|
||||
|
||||
|
||||
async def async_reset_platform(hass: HomeAssistant, integration_name: str) -> None:
|
||||
"""Release modbus resources."""
|
||||
_LOGGER.info("Modbus reloading")
|
||||
for hub in hass.data[DOMAIN]:
|
||||
await hub.async_close()
|
||||
del hass.data[DOMAIN]
|
||||
|
||||
|
||||
class ModbusHub:
|
||||
"""Thread safe wrapper class for pymodbus."""
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
reload:
|
||||
name: Reload
|
||||
description: Reload all modbus entities.
|
||||
write_coil:
|
||||
name: Write coil
|
||||
description: Write to a modbus coil.
|
||||
|
Loading…
x
Reference in New Issue
Block a user