mirror of
https://github.com/home-assistant/core.git
synced 2025-09-05 21:01:37 +02:00
Mod sensor setup
This commit is contained in:
@@ -49,7 +49,7 @@ from homeassistant.helpers.trigger_template_entity import (
|
|||||||
)
|
)
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||||
|
|
||||||
from .const import CONF_COLUMN_NAME, CONF_QUERY, DOMAIN
|
from .const import CONF_ADVANCED_OPTIONS, CONF_COLUMN_NAME, CONF_QUERY, DOMAIN
|
||||||
from .models import SQLData
|
from .models import SQLData
|
||||||
from .util import redact_credentials, resolve_db_url
|
from .util import redact_credentials, resolve_db_url
|
||||||
|
|
||||||
@@ -111,10 +111,10 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Set up the SQL sensor from config entry."""
|
"""Set up the SQL sensor from config entry."""
|
||||||
|
|
||||||
db_url: str = resolve_db_url(hass, entry.options.get(CONF_DB_URL))
|
db_url: str = resolve_db_url(hass, entry.data.get(CONF_DB_URL))
|
||||||
name: str = entry.options[CONF_NAME]
|
name: str = entry.title
|
||||||
query_str: str = entry.options[CONF_QUERY]
|
query_str: str = entry.options[CONF_QUERY]
|
||||||
template: str | None = entry.options.get(CONF_VALUE_TEMPLATE)
|
template: str | None = entry.options[CONF_ADVANCED_OPTIONS].get(CONF_VALUE_TEMPLATE)
|
||||||
column_name: str = entry.options[CONF_COLUMN_NAME]
|
column_name: str = entry.options[CONF_COLUMN_NAME]
|
||||||
|
|
||||||
value_template: ValueTemplate | None = None
|
value_template: ValueTemplate | None = None
|
||||||
@@ -128,9 +128,9 @@ async def async_setup_entry(
|
|||||||
name_template = Template(name, hass)
|
name_template = Template(name, hass)
|
||||||
trigger_entity_config = {CONF_NAME: name_template, CONF_UNIQUE_ID: entry.entry_id}
|
trigger_entity_config = {CONF_NAME: name_template, CONF_UNIQUE_ID: entry.entry_id}
|
||||||
for key in TRIGGER_ENTITY_OPTIONS:
|
for key in TRIGGER_ENTITY_OPTIONS:
|
||||||
if key not in entry.options:
|
if key not in entry.options[CONF_ADVANCED_OPTIONS]:
|
||||||
continue
|
continue
|
||||||
trigger_entity_config[key] = entry.options[key]
|
trigger_entity_config[key] = entry.options[CONF_ADVANCED_OPTIONS][key]
|
||||||
|
|
||||||
await async_setup_sensor(
|
await async_setup_sensor(
|
||||||
hass,
|
hass,
|
||||||
|
Reference in New Issue
Block a user