Secure against resetting a non active modbus (#115364)
parent
8d6473061c
commit
220801bf1c
|
@ -463,6 +463,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
async def async_reset_platform(hass: HomeAssistant, integration_name: str) -> None:
|
||||
"""Release modbus resources."""
|
||||
if DOMAIN not in hass.data:
|
||||
_LOGGER.error("Modbus cannot reload, because it was never loaded")
|
||||
return
|
||||
_LOGGER.info("Modbus reloading")
|
||||
hubs = hass.data[DOMAIN]
|
||||
for name in hubs:
|
||||
|
|
|
@ -25,6 +25,7 @@ import voluptuous as vol
|
|||
|
||||
from homeassistant import config as hass_config
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||
from homeassistant.components.modbus import async_reset_platform
|
||||
from homeassistant.components.modbus.const import (
|
||||
ATTR_ADDRESS,
|
||||
ATTR_HUB,
|
||||
|
@ -1781,3 +1782,9 @@ async def test_no_entities(hass: HomeAssistant) -> None:
|
|||
]
|
||||
}
|
||||
assert await async_setup_component(hass, DOMAIN, config) is False
|
||||
|
||||
|
||||
async def test_reset_platform(hass: HomeAssistant) -> None:
|
||||
"""Run test for async_reset_platform."""
|
||||
await async_reset_platform(hass, "modbus")
|
||||
assert DOMAIN not in hass.data
|
||||
|
|
Loading…
Reference in New Issue