From 70d4ee93f52094b16bbdcba1c68a2f234e214ca0 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Mon, 30 Sep 2024 11:45:02 +0200 Subject: [PATCH] Use HassKey in azure_event_hub (#127086) --- .../components/azure_event_hub/__init__.py | 14 +++++++------- homeassistant/components/azure_event_hub/const.py | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/azure_event_hub/__init__.py b/homeassistant/components/azure_event_hub/__init__.py index 3cd41967c00..bc9d34e728e 100644 --- a/homeassistant/components/azure_event_hub/__init__.py +++ b/homeassistant/components/azure_event_hub/__init__.py @@ -20,11 +20,12 @@ from homeassistant.const import MATCH_ALL from homeassistant.core import Event, HomeAssistant, State from homeassistant.exceptions import ConfigEntryNotReady import homeassistant.helpers.config_validation as cv -from homeassistant.helpers.entityfilter import FILTER_SCHEMA +from homeassistant.helpers.entityfilter import FILTER_SCHEMA, EntityFilter from homeassistant.helpers.event import async_call_later from homeassistant.helpers.json import JSONEncoder from homeassistant.helpers.typing import ConfigType from homeassistant.util.dt import utcnow +from homeassistant.util.hass_dict import HassKey from .client import AzureEventHubClient from .const import ( @@ -36,7 +37,6 @@ from .const import ( CONF_FILTER, CONF_MAX_DELAY, CONF_SEND_INTERVAL, - DATA_FILTER, DEFAULT_MAX_DELAY, DOMAIN, FILTER_STATES, @@ -63,6 +63,7 @@ CONFIG_SCHEMA = vol.Schema( }, extra=vol.ALLOW_EXTRA, ) +DATA_COMPONENT: HassKey[EntityFilter] = HassKey(DOMAIN) async def async_setup(hass: HomeAssistant, yaml_config: ConfigType) -> bool: @@ -73,10 +74,10 @@ async def async_setup(hass: HomeAssistant, yaml_config: ConfigType) -> bool: If config is empty after getting the filter, return, otherwise emit deprecated warning and pass the rest to the config flow. """ - hass.data.setdefault(DOMAIN, {DATA_FILTER: FILTER_SCHEMA({})}) if DOMAIN not in yaml_config: + hass.data[DATA_COMPONENT] = FILTER_SCHEMA({}) return True - hass.data[DOMAIN][DATA_FILTER] = yaml_config[DOMAIN].pop(CONF_FILTER) + hass.data[DATA_COMPONENT] = yaml_config[DOMAIN].pop(CONF_FILTER) if not yaml_config[DOMAIN]: return True @@ -98,11 +99,10 @@ async def async_setup_entry( hass: HomeAssistant, entry: AzureEventHubConfigEntry ) -> bool: """Do the setup based on the config entry and the filter from yaml.""" - hass.data.setdefault(DOMAIN, {DATA_FILTER: FILTER_SCHEMA({})}) hub = AzureEventHub( hass, entry, - hass.data[DOMAIN][DATA_FILTER], + hass.data[DATA_COMPONENT], ) try: await hub.async_test_connection() @@ -136,7 +136,7 @@ class AzureEventHub: self, hass: HomeAssistant, entry: ConfigEntry, - entities_filter: vol.Schema, + entities_filter: EntityFilter, ) -> None: """Initialize the listener.""" self.hass = hass diff --git a/homeassistant/components/azure_event_hub/const.py b/homeassistant/components/azure_event_hub/const.py index 2911470b2bd..59a287ac6ca 100644 --- a/homeassistant/components/azure_event_hub/const.py +++ b/homeassistant/components/azure_event_hub/const.py @@ -16,7 +16,7 @@ CONF_EVENT_HUB_SAS_KEY = "event_hub_sas_key" CONF_EVENT_HUB_CON_STRING = "event_hub_connection_string" CONF_SEND_INTERVAL = "send_interval" CONF_MAX_DELAY = "max_delay" -CONF_FILTER = DATA_FILTER = "filter" +CONF_FILTER = "filter" STEP_USER = "user" STEP_SAS = "sas"