Clean up mysensors hass.data gateway access (#67233)

pull/67287/head
Martin Hjelmare 2022-02-25 14:54:25 +01:00 committed by GitHub
parent 0bd25a192d
commit a0214d695a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 19 deletions

View File

@ -43,7 +43,7 @@ from .const import (
SensorType,
)
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
_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:
"""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(
entry, PLATFORMS_WITH_ENTRY_SUPPORT
@ -314,10 +314,7 @@ def setup_mysensors_platform(
)
continue
gateway_id, node_id, child_id, value_type = dev_id
gateway: BaseAsyncGateway | None = get_mysensors_gateway(hass, gateway_id)
if not gateway:
_LOGGER.warning("Skipping setup of %s, no gateway found", dev_id)
continue
gateway: BaseAsyncGateway = hass.data[DOMAIN][MYSENSORS_GATEWAYS][gateway_id]
if isinstance(device_class, dict):
child = gateway.sensors[node_id].children[child_id]

View File

@ -62,8 +62,6 @@ ValueType = str
GatewayId = str
# 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]
# describes the backend of a hass entity. Contents are: GatewayId, node_id, child_id, v_type as int

View File

@ -37,7 +37,6 @@ from .const import (
CONF_VERSION,
DOMAIN,
MYSENSORS_GATEWAY_START_TASK,
MYSENSORS_GATEWAYS,
ConfGatewayType,
GatewayId,
)
@ -122,16 +121,6 @@ async def try_connect(
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(
hass: HomeAssistant, entry: ConfigEntry
) -> BaseAsyncGateway | None: