mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Use HassKey in azure_event_hub (#127086)
This commit is contained in:
parent
34a4372190
commit
70d4ee93f5
@ -20,11 +20,12 @@ from homeassistant.const import MATCH_ALL
|
|||||||
from homeassistant.core import Event, HomeAssistant, State
|
from homeassistant.core import Event, HomeAssistant, State
|
||||||
from homeassistant.exceptions import ConfigEntryNotReady
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
import homeassistant.helpers.config_validation as cv
|
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.event import async_call_later
|
||||||
from homeassistant.helpers.json import JSONEncoder
|
from homeassistant.helpers.json import JSONEncoder
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
from homeassistant.util.hass_dict import HassKey
|
||||||
|
|
||||||
from .client import AzureEventHubClient
|
from .client import AzureEventHubClient
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -36,7 +37,6 @@ from .const import (
|
|||||||
CONF_FILTER,
|
CONF_FILTER,
|
||||||
CONF_MAX_DELAY,
|
CONF_MAX_DELAY,
|
||||||
CONF_SEND_INTERVAL,
|
CONF_SEND_INTERVAL,
|
||||||
DATA_FILTER,
|
|
||||||
DEFAULT_MAX_DELAY,
|
DEFAULT_MAX_DELAY,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
FILTER_STATES,
|
FILTER_STATES,
|
||||||
@ -63,6 +63,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
},
|
},
|
||||||
extra=vol.ALLOW_EXTRA,
|
extra=vol.ALLOW_EXTRA,
|
||||||
)
|
)
|
||||||
|
DATA_COMPONENT: HassKey[EntityFilter] = HassKey(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup(hass: HomeAssistant, yaml_config: ConfigType) -> bool:
|
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
|
If config is empty after getting the filter, return, otherwise emit
|
||||||
deprecated warning and pass the rest to the config flow.
|
deprecated warning and pass the rest to the config flow.
|
||||||
"""
|
"""
|
||||||
hass.data.setdefault(DOMAIN, {DATA_FILTER: FILTER_SCHEMA({})})
|
|
||||||
if DOMAIN not in yaml_config:
|
if DOMAIN not in yaml_config:
|
||||||
|
hass.data[DATA_COMPONENT] = FILTER_SCHEMA({})
|
||||||
return True
|
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]:
|
if not yaml_config[DOMAIN]:
|
||||||
return True
|
return True
|
||||||
@ -98,11 +99,10 @@ async def async_setup_entry(
|
|||||||
hass: HomeAssistant, entry: AzureEventHubConfigEntry
|
hass: HomeAssistant, entry: AzureEventHubConfigEntry
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Do the setup based on the config entry and the filter from yaml."""
|
"""Do the setup based on the config entry and the filter from yaml."""
|
||||||
hass.data.setdefault(DOMAIN, {DATA_FILTER: FILTER_SCHEMA({})})
|
|
||||||
hub = AzureEventHub(
|
hub = AzureEventHub(
|
||||||
hass,
|
hass,
|
||||||
entry,
|
entry,
|
||||||
hass.data[DOMAIN][DATA_FILTER],
|
hass.data[DATA_COMPONENT],
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
await hub.async_test_connection()
|
await hub.async_test_connection()
|
||||||
@ -136,7 +136,7 @@ class AzureEventHub:
|
|||||||
self,
|
self,
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry: ConfigEntry,
|
entry: ConfigEntry,
|
||||||
entities_filter: vol.Schema,
|
entities_filter: EntityFilter,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize the listener."""
|
"""Initialize the listener."""
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
|
@ -16,7 +16,7 @@ CONF_EVENT_HUB_SAS_KEY = "event_hub_sas_key"
|
|||||||
CONF_EVENT_HUB_CON_STRING = "event_hub_connection_string"
|
CONF_EVENT_HUB_CON_STRING = "event_hub_connection_string"
|
||||||
CONF_SEND_INTERVAL = "send_interval"
|
CONF_SEND_INTERVAL = "send_interval"
|
||||||
CONF_MAX_DELAY = "max_delay"
|
CONF_MAX_DELAY = "max_delay"
|
||||||
CONF_FILTER = DATA_FILTER = "filter"
|
CONF_FILTER = "filter"
|
||||||
|
|
||||||
STEP_USER = "user"
|
STEP_USER = "user"
|
||||||
STEP_SAS = "sas"
|
STEP_SAS = "sas"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user