mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Use HassKey in azure_data_explorer (#127087)
* Use HassKey in azure_data_explorer * Adjust tests * Adjust * Remove test
This commit is contained in:
parent
07fa1fa771
commit
d96fd518e7
@ -16,19 +16,18 @@ from homeassistant.config_entries import ConfigEntry
|
|||||||
from homeassistant.const import MATCH_ALL
|
from homeassistant.const import MATCH_ALL
|
||||||
from homeassistant.core import Event, HomeAssistant, State
|
from homeassistant.core import Event, HomeAssistant, State
|
||||||
from homeassistant.exceptions import ConfigEntryError
|
from homeassistant.exceptions import ConfigEntryError
|
||||||
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 ExtendedJSONEncoder
|
from homeassistant.helpers.json import ExtendedJSONEncoder
|
||||||
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 AzureDataExplorerClient
|
from .client import AzureDataExplorerClient
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_APP_REG_SECRET,
|
CONF_APP_REG_SECRET,
|
||||||
CONF_FILTER,
|
CONF_FILTER,
|
||||||
CONF_SEND_INTERVAL,
|
CONF_SEND_INTERVAL,
|
||||||
DATA_FILTER,
|
|
||||||
DATA_HUB,
|
|
||||||
DEFAULT_MAX_DELAY,
|
DEFAULT_MAX_DELAY,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
FILTER_STATES,
|
FILTER_STATES,
|
||||||
@ -46,6 +45,7 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
},
|
},
|
||||||
extra=vol.ALLOW_EXTRA,
|
extra=vol.ALLOW_EXTRA,
|
||||||
)
|
)
|
||||||
|
DATA_COMPONENT: HassKey[EntityFilter] = HassKey(DOMAIN)
|
||||||
|
|
||||||
|
|
||||||
# fixtures for both init and config flow tests
|
# fixtures for both init and config flow tests
|
||||||
@ -63,10 +63,10 @@ async def async_setup(hass: HomeAssistant, yaml_config: ConfigType) -> bool:
|
|||||||
Adds an empty filter to hass data.
|
Adds an empty filter to hass data.
|
||||||
Tries to get a filter from yaml, if present set to hass data.
|
Tries to get a filter from yaml, if present set to hass data.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
hass.data.setdefault(DOMAIN, {DATA_FILTER: FILTER_SCHEMA({})})
|
|
||||||
if DOMAIN in yaml_config:
|
if DOMAIN in yaml_config:
|
||||||
hass.data[DOMAIN][DATA_FILTER] = yaml_config[DOMAIN].pop(CONF_FILTER)
|
hass.data[DATA_COMPONENT] = yaml_config[DOMAIN].pop(CONF_FILTER)
|
||||||
|
else:
|
||||||
|
hass.data[DATA_COMPONENT] = FILTER_SCHEMA({})
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -83,15 +83,13 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
except KustoAuthenticationError:
|
except KustoAuthenticationError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
hass.data[DOMAIN][DATA_HUB] = adx
|
entry.async_on_unload(adx.async_stop)
|
||||||
await adx.async_start()
|
await adx.async_start()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
adx = hass.data[DOMAIN].pop(DATA_HUB)
|
|
||||||
await adx.async_stop()
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -107,7 +105,7 @@ class AzureDataExplorer:
|
|||||||
|
|
||||||
self.hass = hass
|
self.hass = hass
|
||||||
self._entry = entry
|
self._entry = entry
|
||||||
self._entities_filter = hass.data[DOMAIN][DATA_FILTER]
|
self._entities_filter = hass.data[DATA_COMPONENT]
|
||||||
|
|
||||||
self._client = AzureDataExplorerClient(entry.data)
|
self._client = AzureDataExplorerClient(entry.data)
|
||||||
|
|
||||||
|
@ -16,9 +16,8 @@ CONF_APP_REG_SECRET = "client_secret"
|
|||||||
CONF_AUTHORITY_ID = "authority_id"
|
CONF_AUTHORITY_ID = "authority_id"
|
||||||
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"
|
||||||
CONF_USE_QUEUED_CLIENT = "use_queued_ingestion"
|
CONF_USE_QUEUED_CLIENT = "use_queued_ingestion"
|
||||||
DATA_HUB = "hub"
|
|
||||||
STEP_USER = "user"
|
STEP_USER = "user"
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,14 +9,10 @@ from azure.kusto.ingest import StreamDescriptor
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import azure_data_explorer
|
from homeassistant.components import azure_data_explorer
|
||||||
from homeassistant.components.azure_data_explorer.const import (
|
from homeassistant.components.azure_data_explorer.const import CONF_SEND_INTERVAL
|
||||||
CONF_SEND_INTERVAL,
|
|
||||||
DOMAIN,
|
|
||||||
)
|
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
from homeassistant.const import STATE_ON
|
from homeassistant.const import STATE_ON
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
from homeassistant.util.dt import utcnow
|
from homeassistant.util.dt import utcnow
|
||||||
|
|
||||||
from . import FilterTest
|
from . import FilterTest
|
||||||
@ -99,27 +95,6 @@ async def test_put_event_on_queue_with_queueing_client(
|
|||||||
assert type(mock_queued_ingest.call_args.args[0]) is StreamDescriptor
|
assert type(mock_queued_ingest.call_args.args[0]) is StreamDescriptor
|
||||||
|
|
||||||
|
|
||||||
async def test_import(hass: HomeAssistant) -> None:
|
|
||||||
"""Test the popping of the filter and further import of the config."""
|
|
||||||
config = {
|
|
||||||
DOMAIN: {
|
|
||||||
"filter": {
|
|
||||||
"include_domains": ["light"],
|
|
||||||
"include_entity_globs": ["sensor.included_*"],
|
|
||||||
"include_entities": ["binary_sensor.included"],
|
|
||||||
"exclude_domains": ["light"],
|
|
||||||
"exclude_entity_globs": ["sensor.excluded_*"],
|
|
||||||
"exclude_entities": ["binary_sensor.excluded"],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert await async_setup_component(hass, DOMAIN, config)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert "filter" in hass.data[DOMAIN]
|
|
||||||
|
|
||||||
|
|
||||||
async def test_unload_entry(
|
async def test_unload_entry(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
entry_managed: MockConfigEntry,
|
entry_managed: MockConfigEntry,
|
||||||
@ -239,7 +214,6 @@ async def test_filter(
|
|||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert mock_managed_streaming.called == test.expect_called
|
assert mock_managed_streaming.called == test.expect_called
|
||||||
assert "filter" in hass.data[DOMAIN]
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user