Remove "none" in favor of optional select in derivate (#101312)

This commit is contained in:
Robert Resch 2023-10-11 17:36:15 +02:00 committed by GitHub
parent ddfad75eb7
commit 7db2fdd68c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 13 deletions

View file

@ -24,7 +24,6 @@ from .const import (
)
UNIT_PREFIXES = [
selector.SelectOptionDict(value="none", label="none"),
selector.SelectOptionDict(value="n", label="n (nano)"),
selector.SelectOptionDict(value="µ", label="µ (micro)"),
selector.SelectOptionDict(value="m", label="m (milli)"),
@ -52,7 +51,7 @@ OPTIONS_SCHEMA = vol.Schema(
),
),
vol.Required(CONF_TIME_WINDOW): selector.DurationSelector(),
vol.Required(CONF_UNIT_PREFIX, default="none"): selector.SelectSelector(
vol.Optional(CONF_UNIT_PREFIX): selector.SelectSelector(
selector.SelectSelectorConfig(options=UNIT_PREFIXES),
),
vol.Required(CONF_UNIT_TIME, default=UnitOfTime.HOURS): selector.SelectSelector(

View file

@ -116,10 +116,6 @@ async def async_setup_entry(
else:
device_info = None
unit_prefix = config_entry.options[CONF_UNIT_PREFIX]
if unit_prefix == "none":
unit_prefix = None
derivative_sensor = DerivativeSensor(
name=config_entry.title,
round_digits=int(config_entry.options[CONF_ROUND_DIGITS]),
@ -127,7 +123,7 @@ async def async_setup_entry(
time_window=cv.time_period_dict(config_entry.options[CONF_TIME_WINDOW]),
unique_id=config_entry.entry_id,
unit_of_measurement=None,
unit_prefix=unit_prefix,
unit_prefix=config_entry.options.get(CONF_UNIT_PREFIX),
unit_time=config_entry.options[CONF_UNIT_TIME],
device_info=device_info,
)

View file

@ -33,7 +33,6 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
"round": 1,
"source": input_sensor_entity_id,
"time_window": {"seconds": 0},
"unit_prefix": "none",
"unit_time": "min",
},
)
@ -47,7 +46,6 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
"round": 1.0,
"source": "sensor.input",
"time_window": {"seconds": 0.0},
"unit_prefix": "none",
"unit_time": "min",
}
assert len(mock_setup_entry.mock_calls) == 1
@ -59,7 +57,6 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
"round": 1.0,
"source": "sensor.input",
"time_window": {"seconds": 0.0},
"unit_prefix": "none",
"unit_time": "min",
}
assert config_entry.title == "My derivative"
@ -111,7 +108,6 @@ async def test_options(hass: HomeAssistant, platform) -> None:
user_input={
"round": 2.0,
"time_window": {"seconds": 10.0},
"unit_prefix": "none",
"unit_time": "h",
},
)
@ -121,7 +117,6 @@ async def test_options(hass: HomeAssistant, platform) -> None:
"round": 2.0,
"source": "sensor.input",
"time_window": {"seconds": 10.0},
"unit_prefix": "none",
"unit_time": "h",
}
assert config_entry.data == {}
@ -130,7 +125,6 @@ async def test_options(hass: HomeAssistant, platform) -> None:
"round": 2.0,
"source": "sensor.input",
"time_window": {"seconds": 10.0},
"unit_prefix": "none",
"unit_time": "h",
}
assert config_entry.title == "My derivative"