Remove NONE_SENTINEL in favor of optional select in sql (#101309)

This commit is contained in:
Robert Resch 2023-10-11 17:38:29 +02:00 committed by GitHub
parent 1915fee9ba
commit 952a17532f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 28 deletions

View File

@ -32,7 +32,6 @@ from .util import resolve_db_url
_LOGGER = logging.getLogger(__name__)
NONE_SENTINEL = "none"
OPTIONS_SCHEMA: vol.Schema = vol.Schema(
{
@ -51,32 +50,24 @@ OPTIONS_SCHEMA: vol.Schema = vol.Schema(
vol.Optional(
CONF_VALUE_TEMPLATE,
): selector.TemplateSelector(),
vol.Optional(
CONF_DEVICE_CLASS,
default=NONE_SENTINEL,
): selector.SelectSelector(
vol.Optional(CONF_DEVICE_CLASS): selector.SelectSelector(
selector.SelectSelectorConfig(
options=[NONE_SENTINEL]
+ sorted(
[
cls.value
for cls in SensorDeviceClass
if cls != SensorDeviceClass.ENUM
]
),
options=[
cls.value
for cls in SensorDeviceClass
if cls != SensorDeviceClass.ENUM
],
mode=selector.SelectSelectorMode.DROPDOWN,
translation_key="device_class",
sort=True,
)
),
vol.Optional(
CONF_STATE_CLASS,
default=NONE_SENTINEL,
): selector.SelectSelector(
vol.Optional(CONF_STATE_CLASS): selector.SelectSelector(
selector.SelectSelectorConfig(
options=[NONE_SENTINEL]
+ sorted([cls.value for cls in SensorStateClass]),
options=[cls.value for cls in SensorStateClass],
mode=selector.SelectSelectorMode.DROPDOWN,
translation_key="state_class",
sort=True,
)
),
}
@ -179,9 +170,9 @@ class SQLConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
options[CONF_UNIT_OF_MEASUREMENT] = uom
if value_template := user_input.get(CONF_VALUE_TEMPLATE):
options[CONF_VALUE_TEMPLATE] = value_template
if (device_class := user_input[CONF_DEVICE_CLASS]) != NONE_SENTINEL:
if device_class := user_input.get(CONF_DEVICE_CLASS):
options[CONF_DEVICE_CLASS] = device_class
if (state_class := user_input[CONF_STATE_CLASS]) != NONE_SENTINEL:
if state_class := user_input.get(CONF_STATE_CLASS):
options[CONF_STATE_CLASS] = state_class
if db_url_for_validation != get_instance(self.hass).db_url:
options[CONF_DB_URL] = db_url_for_validation
@ -248,9 +239,9 @@ class SQLOptionsFlowHandler(config_entries.OptionsFlowWithConfigEntry):
options[CONF_UNIT_OF_MEASUREMENT] = uom
if value_template := user_input.get(CONF_VALUE_TEMPLATE):
options[CONF_VALUE_TEMPLATE] = value_template
if (device_class := user_input[CONF_DEVICE_CLASS]) != NONE_SENTINEL:
if device_class := user_input.get(CONF_DEVICE_CLASS):
options[CONF_DEVICE_CLASS] = device_class
if (state_class := user_input[CONF_STATE_CLASS]) != NONE_SENTINEL:
if state_class := user_input.get(CONF_STATE_CLASS):
options[CONF_STATE_CLASS] = state_class
if db_url_for_validation != get_instance(self.hass).db_url:
options[CONF_DB_URL] = db_url_for_validation

View File

@ -67,7 +67,6 @@
"selector": {
"device_class": {
"options": {
"none": "No device class",
"date": "[%key:component::sensor::entity_component::date::name%]",
"duration": "[%key:component::sensor::entity_component::duration::name%]",
"apparent_power": "[%key:component::sensor::entity_component::apparent_power::name%]",
@ -121,7 +120,6 @@
},
"state_class": {
"options": {
"none": "No state class",
"measurement": "[%key:component::sensor::entity_component::_::state_attributes::state_class::state::measurement%]",
"total": "[%key:component::sensor::entity_component::_::state_attributes::state_class::state::total%]",
"total_increasing": "[%key:component::sensor::entity_component::_::state_attributes::state_class::state::total_increasing%]"

View File

@ -8,7 +8,6 @@ from sqlalchemy.exc import SQLAlchemyError
from homeassistant import config_entries
from homeassistant.components.recorder import Recorder
from homeassistant.components.sensor.const import SensorDeviceClass, SensorStateClass
from homeassistant.components.sql.config_flow import NONE_SENTINEL
from homeassistant.components.sql.const import DOMAIN
from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType
@ -669,8 +668,6 @@ async def test_device_state_class(recorder_mock: Recorder, hass: HomeAssistant)
"query": "SELECT 5 as value",
"column": "value",
"unit_of_measurement": "MiB",
"device_class": NONE_SENTINEL,
"state_class": NONE_SENTINEL,
},
)
await hass.async_block_till_done()