mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix Azure data explorer (#119089)
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
08eb8232e5
commit
511547c29a
@ -62,13 +62,12 @@ 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.
|
||||||
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: {}})
|
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][CONF_FILTER]
|
hass.data[DOMAIN][DATA_FILTER] = yaml_config[DOMAIN].pop(CONF_FILTER)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -207,6 +206,6 @@ class AzureDataExplorer:
|
|||||||
if "\n" in state.state:
|
if "\n" in state.state:
|
||||||
return None, dropped + 1
|
return None, dropped + 1
|
||||||
|
|
||||||
json_event = str(json.dumps(obj=state, cls=JSONEncoder).encode("utf-8"))
|
json_event = json.dumps(obj=state, cls=JSONEncoder)
|
||||||
|
|
||||||
return (json_event, dropped)
|
return (json_event, dropped)
|
||||||
|
@ -23,7 +23,7 @@ from .const import (
|
|||||||
CONF_APP_REG_ID,
|
CONF_APP_REG_ID,
|
||||||
CONF_APP_REG_SECRET,
|
CONF_APP_REG_SECRET,
|
||||||
CONF_AUTHORITY_ID,
|
CONF_AUTHORITY_ID,
|
||||||
CONF_USE_FREE,
|
CONF_USE_QUEUED_CLIENT,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -35,7 +35,6 @@ class AzureDataExplorerClient:
|
|||||||
def __init__(self, data: Mapping[str, Any]) -> None:
|
def __init__(self, data: Mapping[str, Any]) -> None:
|
||||||
"""Create the right class."""
|
"""Create the right class."""
|
||||||
|
|
||||||
self._cluster_ingest_uri = data[CONF_ADX_CLUSTER_INGEST_URI]
|
|
||||||
self._database = data[CONF_ADX_DATABASE_NAME]
|
self._database = data[CONF_ADX_DATABASE_NAME]
|
||||||
self._table = data[CONF_ADX_TABLE_NAME]
|
self._table = data[CONF_ADX_TABLE_NAME]
|
||||||
self._ingestion_properties = IngestionProperties(
|
self._ingestion_properties = IngestionProperties(
|
||||||
@ -45,24 +44,36 @@ class AzureDataExplorerClient:
|
|||||||
ingestion_mapping_reference="ha_json_mapping",
|
ingestion_mapping_reference="ha_json_mapping",
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create cLient for ingesting and querying data
|
# Create client for ingesting data
|
||||||
kcsb = KustoConnectionStringBuilder.with_aad_application_key_authentication(
|
kcsb_ingest = (
|
||||||
self._cluster_ingest_uri,
|
KustoConnectionStringBuilder.with_aad_application_key_authentication(
|
||||||
|
data[CONF_ADX_CLUSTER_INGEST_URI],
|
||||||
data[CONF_APP_REG_ID],
|
data[CONF_APP_REG_ID],
|
||||||
data[CONF_APP_REG_SECRET],
|
data[CONF_APP_REG_SECRET],
|
||||||
data[CONF_AUTHORITY_ID],
|
data[CONF_AUTHORITY_ID],
|
||||||
)
|
)
|
||||||
|
)
|
||||||
|
|
||||||
if data[CONF_USE_FREE] is True:
|
# Create client for querying data
|
||||||
|
kcsb_query = (
|
||||||
|
KustoConnectionStringBuilder.with_aad_application_key_authentication(
|
||||||
|
data[CONF_ADX_CLUSTER_INGEST_URI].replace("ingest-", ""),
|
||||||
|
data[CONF_APP_REG_ID],
|
||||||
|
data[CONF_APP_REG_SECRET],
|
||||||
|
data[CONF_AUTHORITY_ID],
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if data[CONF_USE_QUEUED_CLIENT] is True:
|
||||||
# Queded is the only option supported on free tear of ADX
|
# Queded is the only option supported on free tear of ADX
|
||||||
self.write_client = QueuedIngestClient(kcsb)
|
self.write_client = QueuedIngestClient(kcsb_ingest)
|
||||||
else:
|
else:
|
||||||
self.write_client = ManagedStreamingIngestClient.from_dm_kcsb(kcsb)
|
self.write_client = ManagedStreamingIngestClient.from_dm_kcsb(kcsb_ingest)
|
||||||
|
|
||||||
self.query_client = KustoClient(kcsb)
|
self.query_client = KustoClient(kcsb_query)
|
||||||
|
|
||||||
def test_connection(self) -> None:
|
def test_connection(self) -> None:
|
||||||
"""Test connection, will throw Exception when it cannot connect."""
|
"""Test connection, will throw Exception if it cannot connect."""
|
||||||
|
|
||||||
query = f"{self._table} | take 1"
|
query = f"{self._table} | take 1"
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import voluptuous as vol
|
|||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
from homeassistant.config_entries import ConfigFlowResult
|
from homeassistant.config_entries import ConfigFlowResult
|
||||||
|
from homeassistant.helpers.selector import BooleanSelector
|
||||||
|
|
||||||
from . import AzureDataExplorerClient
|
from . import AzureDataExplorerClient
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -19,7 +20,7 @@ from .const import (
|
|||||||
CONF_APP_REG_ID,
|
CONF_APP_REG_ID,
|
||||||
CONF_APP_REG_SECRET,
|
CONF_APP_REG_SECRET,
|
||||||
CONF_AUTHORITY_ID,
|
CONF_AUTHORITY_ID,
|
||||||
CONF_USE_FREE,
|
CONF_USE_QUEUED_CLIENT,
|
||||||
DEFAULT_OPTIONS,
|
DEFAULT_OPTIONS,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
@ -34,7 +35,7 @@ STEP_USER_DATA_SCHEMA = vol.Schema(
|
|||||||
vol.Required(CONF_APP_REG_ID): str,
|
vol.Required(CONF_APP_REG_ID): str,
|
||||||
vol.Required(CONF_APP_REG_SECRET): str,
|
vol.Required(CONF_APP_REG_SECRET): str,
|
||||||
vol.Required(CONF_AUTHORITY_ID): str,
|
vol.Required(CONF_AUTHORITY_ID): str,
|
||||||
vol.Optional(CONF_USE_FREE, default=False): bool,
|
vol.Required(CONF_USE_QUEUED_CLIENT, default=False): BooleanSelector(),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ 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 = DATA_FILTER = "filter"
|
||||||
CONF_USE_FREE = "use_queued_ingestion"
|
CONF_USE_QUEUED_CLIENT = "use_queued_ingestion"
|
||||||
DATA_HUB = "hub"
|
DATA_HUB = "hub"
|
||||||
STEP_USER = "user"
|
STEP_USER = "user"
|
||||||
|
|
||||||
|
@ -3,15 +3,19 @@
|
|||||||
"step": {
|
"step": {
|
||||||
"user": {
|
"user": {
|
||||||
"title": "Setup your Azure Data Explorer integration",
|
"title": "Setup your Azure Data Explorer integration",
|
||||||
"description": "Enter connection details.",
|
"description": "Enter connection details",
|
||||||
"data": {
|
"data": {
|
||||||
"cluster_ingest_uri": "Cluster ingest URI",
|
"cluster_ingest_uri": "Cluster Ingest URI",
|
||||||
"database": "Database name",
|
"authority_id": "Authority ID",
|
||||||
"table": "Table name",
|
|
||||||
"client_id": "Client ID",
|
"client_id": "Client ID",
|
||||||
"client_secret": "Client secret",
|
"client_secret": "Client secret",
|
||||||
"authority_id": "Authority ID",
|
"database": "Database name",
|
||||||
|
"table": "Table name",
|
||||||
"use_queued_ingestion": "Use queued ingestion"
|
"use_queued_ingestion": "Use queued ingestion"
|
||||||
|
},
|
||||||
|
"data_description": {
|
||||||
|
"cluster_ingest_uri": "Ingest-URI of the cluster",
|
||||||
|
"use_queued_ingestion": "Must be enabled when using ADX free cluster"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -8,7 +8,7 @@ from homeassistant.components.azure_data_explorer.const import (
|
|||||||
CONF_APP_REG_SECRET,
|
CONF_APP_REG_SECRET,
|
||||||
CONF_AUTHORITY_ID,
|
CONF_AUTHORITY_ID,
|
||||||
CONF_SEND_INTERVAL,
|
CONF_SEND_INTERVAL,
|
||||||
CONF_USE_FREE,
|
CONF_USE_QUEUED_CLIENT,
|
||||||
)
|
)
|
||||||
|
|
||||||
AZURE_DATA_EXPLORER_PATH = "homeassistant.components.azure_data_explorer"
|
AZURE_DATA_EXPLORER_PATH = "homeassistant.components.azure_data_explorer"
|
||||||
@ -29,7 +29,7 @@ BASE_CONFIG_URI = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
BASIC_OPTIONS = {
|
BASIC_OPTIONS = {
|
||||||
CONF_USE_FREE: False,
|
CONF_USE_QUEUED_CLIENT: False,
|
||||||
CONF_SEND_INTERVAL: 5,
|
CONF_SEND_INTERVAL: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -39,10 +39,10 @@ BASE_CONFIG_FULL = BASE_CONFIG | BASIC_OPTIONS | BASE_CONFIG_URI
|
|||||||
|
|
||||||
BASE_CONFIG_IMPORT = {
|
BASE_CONFIG_IMPORT = {
|
||||||
CONF_ADX_CLUSTER_INGEST_URI: "https://cluster.region.kusto.windows.net",
|
CONF_ADX_CLUSTER_INGEST_URI: "https://cluster.region.kusto.windows.net",
|
||||||
CONF_USE_FREE: False,
|
CONF_USE_QUEUED_CLIENT: False,
|
||||||
CONF_SEND_INTERVAL: 5,
|
CONF_SEND_INTERVAL: 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
FREE_OPTIONS = {CONF_USE_FREE: True, CONF_SEND_INTERVAL: 5}
|
FREE_OPTIONS = {CONF_USE_QUEUED_CLIENT: True, CONF_SEND_INTERVAL: 5}
|
||||||
|
|
||||||
BASE_CONFIG_FREE = BASE_CONFIG | FREE_OPTIONS
|
BASE_CONFIG_FREE = BASE_CONFIG | FREE_OPTIONS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user