Implement config flow for SQL integration (#68700)

This commit is contained in:
G Johansson 2022-04-24 20:50:32 +02:00 committed by GitHub
parent 776565c23f
commit 472ffd3bc6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 962 additions and 208 deletions

View file

@ -1 +1,58 @@
"""Tests for the sql component."""
from __future__ import annotations
from typing import Any
from homeassistant.components.recorder import CONF_DB_URL
from homeassistant.components.sql.const import CONF_COLUMN_NAME, CONF_QUERY, DOMAIN
from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_UNIT_OF_MEASUREMENT
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry
ENTRY_CONFIG = {
CONF_DB_URL: "sqlite://",
CONF_QUERY: "SELECT 5 as value",
CONF_COLUMN_NAME: "value",
CONF_UNIT_OF_MEASUREMENT: "MiB",
}
ENTRY_CONFIG_INVALID_QUERY = {
CONF_DB_URL: "sqlite://",
CONF_QUERY: "UPDATE 5 as value",
CONF_COLUMN_NAME: "size",
CONF_UNIT_OF_MEASUREMENT: "MiB",
}
ENTRY_CONFIG_NO_RESULTS = {
CONF_DB_URL: "sqlite://",
CONF_QUERY: "SELECT kalle as value from no_table;",
CONF_COLUMN_NAME: "value",
CONF_UNIT_OF_MEASUREMENT: "MiB",
}
async def init_integration(
hass: HomeAssistant,
config: dict[str, Any] = None,
entry_id: str = "1",
source: str = SOURCE_USER,
) -> MockConfigEntry:
"""Set up the SQL integration in Home Assistant."""
if not config:
config = ENTRY_CONFIG
config_entry = MockConfigEntry(
domain=DOMAIN,
source=source,
data={},
options=config,
entry_id=entry_id,
)
config_entry.add_to_hass(hass)
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
return config_entry