Secure against resetting a non active modbus (#115364)

pull/115309/head^2
jan iversen 2024-04-10 22:09:10 +02:00 committed by GitHub
parent 8d6473061c
commit 220801bf1c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 0 deletions

View File

@ -463,6 +463,9 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
async def async_reset_platform(hass: HomeAssistant, integration_name: str) -> None: async def async_reset_platform(hass: HomeAssistant, integration_name: str) -> None:
"""Release modbus resources.""" """Release modbus resources."""
if DOMAIN not in hass.data:
_LOGGER.error("Modbus cannot reload, because it was never loaded")
return
_LOGGER.info("Modbus reloading") _LOGGER.info("Modbus reloading")
hubs = hass.data[DOMAIN] hubs = hass.data[DOMAIN]
for name in hubs: for name in hubs:

View File

@ -25,6 +25,7 @@ import voluptuous as vol
from homeassistant import config as hass_config from homeassistant import config as hass_config
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN 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 ( from homeassistant.components.modbus.const import (
ATTR_ADDRESS, ATTR_ADDRESS,
ATTR_HUB, ATTR_HUB,
@ -1781,3 +1782,9 @@ async def test_no_entities(hass: HomeAssistant) -> None:
] ]
} }
assert await async_setup_component(hass, DOMAIN, config) is False 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