Refactor SQL with ManualTriggerEntity (#95116)
* First go * Finalize sensor * Add tests * Remove not need _attr_name * device_class * _process_manual_data allow Any as value
This commit is contained in:
@@ -13,12 +13,14 @@ from homeassistant.components.sql.const import CONF_COLUMN_NAME, CONF_QUERY, DOM
|
||||
from homeassistant.config_entries import SOURCE_USER
|
||||
from homeassistant.const import (
|
||||
CONF_DEVICE_CLASS,
|
||||
CONF_ICON,
|
||||
CONF_NAME,
|
||||
CONF_UNIQUE_ID,
|
||||
CONF_UNIT_OF_MEASUREMENT,
|
||||
CONF_VALUE_TEMPLATE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.template_entity import CONF_AVAILABILITY, CONF_PICTURE
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@@ -148,6 +150,23 @@ YAML_CONFIG_NO_DB = {
|
||||
}
|
||||
}
|
||||
|
||||
YAML_CONFIG_ALL_TEMPLATES = {
|
||||
"sql": {
|
||||
CONF_DB_URL: "sqlite://",
|
||||
CONF_NAME: "Get values with template",
|
||||
CONF_QUERY: "SELECT 5 as output",
|
||||
CONF_COLUMN_NAME: "output",
|
||||
CONF_UNIT_OF_MEASUREMENT: "MiB/s",
|
||||
CONF_UNIQUE_ID: "unique_id_123456",
|
||||
CONF_VALUE_TEMPLATE: "{{ value }}",
|
||||
CONF_ICON: '{% if states("sensor.input1")=="on" %} mdi:on {% else %} mdi:off {% endif %}',
|
||||
CONF_PICTURE: '{% if states("sensor.input1")=="on" %} /local/picture1.jpg {% else %} /local/picture2.jpg {% endif %}',
|
||||
CONF_AVAILABILITY: '{{ states("sensor.input2")=="on" }}',
|
||||
CONF_DEVICE_CLASS: SensorDeviceClass.DATA_RATE,
|
||||
CONF_STATE_CLASS: SensorStateClass.MEASUREMENT,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
async def init_integration(
|
||||
hass: HomeAssistant,
|
||||
|
||||
Reference in New Issue
Block a user