Clean up mysensors hass.data gateway access (#67233)
parent
0bd25a192d
commit
a0214d695a
|
@ -43,7 +43,7 @@ from .const import (
|
||||||
SensorType,
|
SensorType,
|
||||||
)
|
)
|
||||||
from .device import MySensorsDevice, get_mysensors_devices
|
from .device import MySensorsDevice, get_mysensors_devices
|
||||||
from .gateway import finish_setup, get_mysensors_gateway, gw_stop, setup_gateway
|
from .gateway import finish_setup, gw_stop, setup_gateway
|
||||||
from .helpers import on_unload
|
from .helpers import on_unload
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -244,7 +244,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Remove an instance of the MySensors integration."""
|
"""Remove an instance of the MySensors integration."""
|
||||||
|
|
||||||
gateway = get_mysensors_gateway(hass, entry.entry_id)
|
gateway: BaseAsyncGateway = hass.data[DOMAIN][MYSENSORS_GATEWAYS][entry.entry_id]
|
||||||
|
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(
|
unload_ok = await hass.config_entries.async_unload_platforms(
|
||||||
entry, PLATFORMS_WITH_ENTRY_SUPPORT
|
entry, PLATFORMS_WITH_ENTRY_SUPPORT
|
||||||
|
@ -314,10 +314,7 @@ def setup_mysensors_platform(
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
gateway_id, node_id, child_id, value_type = dev_id
|
gateway_id, node_id, child_id, value_type = dev_id
|
||||||
gateway: BaseAsyncGateway | None = get_mysensors_gateway(hass, gateway_id)
|
gateway: BaseAsyncGateway = hass.data[DOMAIN][MYSENSORS_GATEWAYS][gateway_id]
|
||||||
if not gateway:
|
|
||||||
_LOGGER.warning("Skipping setup of %s, no gateway found", dev_id)
|
|
||||||
continue
|
|
||||||
|
|
||||||
if isinstance(device_class, dict):
|
if isinstance(device_class, dict):
|
||||||
child = gateway.sensors[node_id].children[child_id]
|
child = gateway.sensors[node_id].children[child_id]
|
||||||
|
|
|
@ -62,8 +62,6 @@ ValueType = str
|
||||||
|
|
||||||
GatewayId = str
|
GatewayId = str
|
||||||
# a unique id generated by config_flow.py and stored in the ConfigEntry as the entry id.
|
# a unique id generated by config_flow.py and stored in the ConfigEntry as the entry id.
|
||||||
#
|
|
||||||
# Gateway may be fetched by giving the gateway id to get_mysensors_gateway()
|
|
||||||
|
|
||||||
DevId = tuple[GatewayId, int, int, int]
|
DevId = tuple[GatewayId, int, int, int]
|
||||||
# describes the backend of a hass entity. Contents are: GatewayId, node_id, child_id, v_type as int
|
# describes the backend of a hass entity. Contents are: GatewayId, node_id, child_id, v_type as int
|
||||||
|
|
|
@ -37,7 +37,6 @@ from .const import (
|
||||||
CONF_VERSION,
|
CONF_VERSION,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
MYSENSORS_GATEWAY_START_TASK,
|
MYSENSORS_GATEWAY_START_TASK,
|
||||||
MYSENSORS_GATEWAYS,
|
|
||||||
ConfGatewayType,
|
ConfGatewayType,
|
||||||
GatewayId,
|
GatewayId,
|
||||||
)
|
)
|
||||||
|
@ -122,16 +121,6 @@ async def try_connect(
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def get_mysensors_gateway(
|
|
||||||
hass: HomeAssistant, gateway_id: GatewayId
|
|
||||||
) -> BaseAsyncGateway | None:
|
|
||||||
"""Return the Gateway for a given GatewayId."""
|
|
||||||
if MYSENSORS_GATEWAYS not in hass.data[DOMAIN]:
|
|
||||||
hass.data[DOMAIN][MYSENSORS_GATEWAYS] = {}
|
|
||||||
gateways = hass.data[DOMAIN].get(MYSENSORS_GATEWAYS)
|
|
||||||
return gateways.get(gateway_id)
|
|
||||||
|
|
||||||
|
|
||||||
async def setup_gateway(
|
async def setup_gateway(
|
||||||
hass: HomeAssistant, entry: ConfigEntry
|
hass: HomeAssistant, entry: ConfigEntry
|
||||||
) -> BaseAsyncGateway | None:
|
) -> BaseAsyncGateway | None:
|
||||||
|
|
Loading…
Reference in New Issue