mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 07:07:28 +00:00
Remove "none" in favor of optional select in derivate (#101312)
This commit is contained in:
parent
ddfad75eb7
commit
7db2fdd68c
@ -24,7 +24,6 @@ from .const import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
UNIT_PREFIXES = [
|
UNIT_PREFIXES = [
|
||||||
selector.SelectOptionDict(value="none", label="none"),
|
|
||||||
selector.SelectOptionDict(value="n", label="n (nano)"),
|
selector.SelectOptionDict(value="n", label="n (nano)"),
|
||||||
selector.SelectOptionDict(value="µ", label="µ (micro)"),
|
selector.SelectOptionDict(value="µ", label="µ (micro)"),
|
||||||
selector.SelectOptionDict(value="m", label="m (milli)"),
|
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_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),
|
selector.SelectSelectorConfig(options=UNIT_PREFIXES),
|
||||||
),
|
),
|
||||||
vol.Required(CONF_UNIT_TIME, default=UnitOfTime.HOURS): selector.SelectSelector(
|
vol.Required(CONF_UNIT_TIME, default=UnitOfTime.HOURS): selector.SelectSelector(
|
||||||
|
@ -116,10 +116,6 @@ async def async_setup_entry(
|
|||||||
else:
|
else:
|
||||||
device_info = None
|
device_info = None
|
||||||
|
|
||||||
unit_prefix = config_entry.options[CONF_UNIT_PREFIX]
|
|
||||||
if unit_prefix == "none":
|
|
||||||
unit_prefix = None
|
|
||||||
|
|
||||||
derivative_sensor = DerivativeSensor(
|
derivative_sensor = DerivativeSensor(
|
||||||
name=config_entry.title,
|
name=config_entry.title,
|
||||||
round_digits=int(config_entry.options[CONF_ROUND_DIGITS]),
|
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]),
|
time_window=cv.time_period_dict(config_entry.options[CONF_TIME_WINDOW]),
|
||||||
unique_id=config_entry.entry_id,
|
unique_id=config_entry.entry_id,
|
||||||
unit_of_measurement=None,
|
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],
|
unit_time=config_entry.options[CONF_UNIT_TIME],
|
||||||
device_info=device_info,
|
device_info=device_info,
|
||||||
)
|
)
|
||||||
|
@ -33,7 +33,6 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
|
|||||||
"round": 1,
|
"round": 1,
|
||||||
"source": input_sensor_entity_id,
|
"source": input_sensor_entity_id,
|
||||||
"time_window": {"seconds": 0},
|
"time_window": {"seconds": 0},
|
||||||
"unit_prefix": "none",
|
|
||||||
"unit_time": "min",
|
"unit_time": "min",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -47,7 +46,6 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
|
|||||||
"round": 1.0,
|
"round": 1.0,
|
||||||
"source": "sensor.input",
|
"source": "sensor.input",
|
||||||
"time_window": {"seconds": 0.0},
|
"time_window": {"seconds": 0.0},
|
||||||
"unit_prefix": "none",
|
|
||||||
"unit_time": "min",
|
"unit_time": "min",
|
||||||
}
|
}
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
@ -59,7 +57,6 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
|
|||||||
"round": 1.0,
|
"round": 1.0,
|
||||||
"source": "sensor.input",
|
"source": "sensor.input",
|
||||||
"time_window": {"seconds": 0.0},
|
"time_window": {"seconds": 0.0},
|
||||||
"unit_prefix": "none",
|
|
||||||
"unit_time": "min",
|
"unit_time": "min",
|
||||||
}
|
}
|
||||||
assert config_entry.title == "My derivative"
|
assert config_entry.title == "My derivative"
|
||||||
@ -111,7 +108,6 @@ async def test_options(hass: HomeAssistant, platform) -> None:
|
|||||||
user_input={
|
user_input={
|
||||||
"round": 2.0,
|
"round": 2.0,
|
||||||
"time_window": {"seconds": 10.0},
|
"time_window": {"seconds": 10.0},
|
||||||
"unit_prefix": "none",
|
|
||||||
"unit_time": "h",
|
"unit_time": "h",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -121,7 +117,6 @@ async def test_options(hass: HomeAssistant, platform) -> None:
|
|||||||
"round": 2.0,
|
"round": 2.0,
|
||||||
"source": "sensor.input",
|
"source": "sensor.input",
|
||||||
"time_window": {"seconds": 10.0},
|
"time_window": {"seconds": 10.0},
|
||||||
"unit_prefix": "none",
|
|
||||||
"unit_time": "h",
|
"unit_time": "h",
|
||||||
}
|
}
|
||||||
assert config_entry.data == {}
|
assert config_entry.data == {}
|
||||||
@ -130,7 +125,6 @@ async def test_options(hass: HomeAssistant, platform) -> None:
|
|||||||
"round": 2.0,
|
"round": 2.0,
|
||||||
"source": "sensor.input",
|
"source": "sensor.input",
|
||||||
"time_window": {"seconds": 10.0},
|
"time_window": {"seconds": 10.0},
|
||||||
"unit_prefix": "none",
|
|
||||||
"unit_time": "h",
|
"unit_time": "h",
|
||||||
}
|
}
|
||||||
assert config_entry.title == "My derivative"
|
assert config_entry.title == "My derivative"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user