Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions homeassistant/components/utility_meter/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,8 @@

def _validate_config(data: Any) -> Any:
"""Validate config."""
tariffs: list[str]
if not data[CONF_TARIFFS]:
tariffs = []
else:
tariffs = data[CONF_TARIFFS].split(",")
try:
vol.Unique()(tariffs)
vol.Unique()(data[CONF_TARIFFS])
except vol.Invalid as exc:
raise SchemaFlowError("tariffs_not_unique") from exc

Expand Down Expand Up @@ -88,7 +83,9 @@ def _validate_config(data: Any) -> Any:
}
}
),
vol.Optional(CONF_TARIFFS): selector.selector({"text": {}}),
vol.Required(CONF_TARIFFS, default=[]): selector.selector(
{"select": {"options": [], "custom_value": True, "multiple": True}}
),
vol.Required(CONF_METER_NET_CONSUMPTION, default=False): selector.selector(
{"boolean": {}}
),
Expand Down
7 changes: 1 addition & 6 deletions homeassistant/components/utility_meter/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,7 @@ async def async_setup_entry(
) -> None:
"""Initialize Utility Meter config entry."""
name = config_entry.title

# Remove when frontend list selector is available
if not config_entry.options.get(CONF_TARIFFS):
tariffs = []
else:
tariffs = config_entry.options[CONF_TARIFFS].split(",")
tariffs = config_entry.options[CONF_TARIFFS]

legacy_add_entities = None
unique_id = config_entry.entry_id
Expand Down
7 changes: 1 addition & 6 deletions homeassistant/components/utility_meter/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ async def async_setup_entry(
tariff_entity = hass.data[DATA_UTILITY][entry_id][CONF_TARIFF_ENTITY]

meters = []

# Remove when frontend list selector is available
if not config_entry.options.get(CONF_TARIFFS):
tariffs = []
else:
tariffs = config_entry.options[CONF_TARIFFS].split(",")
tariffs = config_entry.options[CONF_TARIFFS]

if not tariffs:
# Add single sensor, not gated by a tariff selector
Expand Down
14 changes: 7 additions & 7 deletions tests/components/utility_meter/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
"name": "Electricity meter",
"offset": 0,
"source": input_sensor_entity_id,
"tariffs": "",
"tariffs": [],
},
)
await hass.async_block_till_done()
Expand All @@ -48,7 +48,7 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
"net_consumption": False,
"offset": 0,
"source": input_sensor_entity_id,
"tariffs": "",
"tariffs": [],
}
assert len(mock_setup_entry.mock_calls) == 1

Expand All @@ -61,7 +61,7 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
"net_consumption": False,
"offset": 0,
"source": input_sensor_entity_id,
"tariffs": "",
"tariffs": [],
}
assert config_entry.title == "Electricity meter"

Expand All @@ -83,7 +83,7 @@ async def test_tariffs(hass: HomeAssistant) -> None:
"name": "Electricity meter",
"offset": 0,
"source": input_sensor_entity_id,
"tariffs": "cat,dog,horse,cow",
"tariffs": ["cat", "dog", "horse", "cow"],
},
)
await hass.async_block_till_done()
Expand All @@ -98,7 +98,7 @@ async def test_tariffs(hass: HomeAssistant) -> None:
"net_consumption": False,
"offset": 0,
"source": input_sensor_entity_id,
"tariffs": "cat,dog,horse,cow",
"tariffs": ["cat", "dog", "horse", "cow"],
}

config_entry = hass.config_entries.async_entries(DOMAIN)[0]
Expand All @@ -110,7 +110,7 @@ async def test_tariffs(hass: HomeAssistant) -> None:
"net_consumption": False,
"offset": 0,
"source": input_sensor_entity_id,
"tariffs": "cat,dog,horse,cow",
"tariffs": ["cat", "dog", "horse", "cow"],
}
assert config_entry.title == "Electricity meter"

Expand All @@ -127,7 +127,7 @@ async def test_tariffs(hass: HomeAssistant) -> None:
"name": "Electricity meter",
"offset": 0,
"source": input_sensor_entity_id,
"tariffs": "cat,cat,cat,cat",
"tariffs": ["cat", "cat", "cat", "cat"],
},
)
await hass.async_block_till_done()
Expand Down
8 changes: 4 additions & 4 deletions tests/components/utility_meter/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ async def test_services_config_entry(hass):
"net_consumption": False,
"offset": 0,
"source": "sensor.energy",
"tariffs": "peak,offpeak",
"tariffs": ["peak", "offpeak"],
},
title="Energy bill",
)
Expand All @@ -202,7 +202,7 @@ async def test_services_config_entry(hass):
"net_consumption": False,
"offset": 0,
"source": "sensor.energy",
"tariffs": "peak,offpeak",
"tariffs": ["peak", "offpeak"],
},
title="Energy bill2",
)
Expand Down Expand Up @@ -469,11 +469,11 @@ def async_reset_meter(entity_id):
"tariffs,expected_entities",
(
(
"",
[],
["sensor.electricity_meter"],
),
(
"high,low",
["high", "low"],
[
"sensor.electricity_meter_low",
"sensor.electricity_meter_high",
Expand Down
16 changes: 8 additions & 8 deletions tests/components/utility_meter/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def alter_time(retval):
"net_consumption": False,
"offset": 0,
"source": "sensor.energy",
"tariffs": "onpeak,midpeak,offpeak",
"tariffs": ["onpeak", "midpeak", "offpeak"],
},
),
),
Expand Down Expand Up @@ -249,7 +249,7 @@ async def test_state(hass, yaml_config, config_entry_config):
"net_consumption": False,
"offset": 0,
"source": "sensor.energy",
"tariffs": "onpeak,midpeak,offpeak",
"tariffs": ["onpeak", "midpeak", "offpeak"],
},
),
),
Expand Down Expand Up @@ -327,7 +327,7 @@ async def test_init(hass, yaml_config, config_entry_config):
"net_consumption": True,
"offset": 0,
"source": "sensor.energy",
"tariffs": "",
"tariffs": [],
},
{
"cycle": "none",
Expand All @@ -336,7 +336,7 @@ async def test_init(hass, yaml_config, config_entry_config):
"net_consumption": False,
"offset": 0,
"source": "sensor.gas",
"tariffs": "",
"tariffs": [],
},
],
),
Expand Down Expand Up @@ -411,7 +411,7 @@ async def test_device_class(hass, yaml_config, config_entry_configs):
"net_consumption": False,
"offset": 0,
"source": "sensor.energy",
"tariffs": "onpeak,midpeak,offpeak",
"tariffs": ["onpeak", "midpeak", "offpeak"],
},
),
),
Expand Down Expand Up @@ -514,7 +514,7 @@ async def test_restore_state(hass, yaml_config, config_entry_config):
"net_consumption": True,
"offset": 0,
"source": "sensor.energy",
"tariffs": "",
"tariffs": [],
},
),
),
Expand Down Expand Up @@ -582,7 +582,7 @@ async def test_net_consumption(hass, yaml_config, config_entry_config):
"net_consumption": False,
"offset": 0,
"source": "sensor.energy",
"tariffs": "",
"tariffs": [],
},
),
),
Expand Down Expand Up @@ -650,7 +650,7 @@ async def test_non_net_consumption(hass, yaml_config, config_entry_config):
"net_consumption": False,
"offset": 0,
"source": "sensor.energy",
"tariffs": "",
"tariffs": [],
},
),
),
Expand Down