From 1915fee9ba2e9bdd268b15e8aa25d942e36580b3 Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Wed, 11 Oct 2023 17:36:53 +0200 Subject: [PATCH] Remove "none" in favor of optional select in integration (#101396) --- homeassistant/components/integration/config_flow.py | 3 +-- homeassistant/components/integration/sensor.py | 10 +++------- tests/components/integration/test_config_flow.py | 3 --- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/homeassistant/components/integration/config_flow.py b/homeassistant/components/integration/config_flow.py index 90fc7195cec..0b1eda7201e 100644 --- a/homeassistant/components/integration/config_flow.py +++ b/homeassistant/components/integration/config_flow.py @@ -27,7 +27,6 @@ from .const import ( ) UNIT_PREFIXES = [ - selector.SelectOptionDict(value="none", label="none"), selector.SelectOptionDict(value="k", label="k (kilo)"), selector.SelectOptionDict(value="M", label="M (mega)"), selector.SelectOptionDict(value="G", label="G (giga)"), @@ -74,7 +73,7 @@ CONFIG_SCHEMA = vol.Schema( unit_of_measurement="decimals", ), ), - 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( diff --git a/homeassistant/components/integration/sensor.py b/homeassistant/components/integration/sensor.py index 66a99b63681..909266c51d4 100644 --- a/homeassistant/components/integration/sensor.py +++ b/homeassistant/components/integration/sensor.py @@ -77,7 +77,7 @@ PLATFORM_SCHEMA = vol.All( vol.Optional(CONF_UNIQUE_ID): cv.string, vol.Required(CONF_SOURCE_SENSOR): cv.entity_id, vol.Optional(CONF_ROUND_DIGITS, default=DEFAULT_ROUND): vol.Coerce(int), - vol.Optional(CONF_UNIT_PREFIX, default=None): vol.In(UNIT_PREFIXES), + vol.Optional(CONF_UNIT_PREFIX): vol.In(UNIT_PREFIXES), vol.Optional(CONF_UNIT_TIME, default=UnitOfTime.HOURS): vol.In(UNIT_TIME), vol.Remove(CONF_UNIT_OF_MEASUREMENT): cv.string, vol.Optional(CONF_METHOD, default=METHOD_TRAPEZOIDAL): vol.In( @@ -169,17 +169,13 @@ async def async_setup_entry( else: device_info = None - unit_prefix = config_entry.options[CONF_UNIT_PREFIX] - if unit_prefix == "none": - unit_prefix = None - integral = IntegrationSensor( integration_method=config_entry.options[CONF_METHOD], name=config_entry.title, round_digits=int(config_entry.options[CONF_ROUND_DIGITS]), source_entity=source_entity_id, unique_id=config_entry.entry_id, - 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, ) @@ -200,7 +196,7 @@ async def async_setup_platform( round_digits=config[CONF_ROUND_DIGITS], source_entity=config[CONF_SOURCE_SENSOR], unique_id=config.get(CONF_UNIQUE_ID), - unit_prefix=config[CONF_UNIT_PREFIX], + unit_prefix=config.get(CONF_UNIT_PREFIX), unit_time=config[CONF_UNIT_TIME], ) diff --git a/tests/components/integration/test_config_flow.py b/tests/components/integration/test_config_flow.py index aedfbc6e8bc..c92cf70b0c2 100644 --- a/tests/components/integration/test_config_flow.py +++ b/tests/components/integration/test_config_flow.py @@ -33,7 +33,6 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None: "name": "My integration", "round": 1, "source": input_sensor_entity_id, - "unit_prefix": "none", "unit_time": "min", }, ) @@ -47,7 +46,6 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None: "name": "My integration", "round": 1.0, "source": "sensor.input", - "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: "name": "My integration", "round": 1.0, "source": "sensor.input", - "unit_prefix": "none", "unit_time": "min", } assert config_entry.title == "My integration"