mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Make utility_meter tariffs a list (#68967)
This commit is contained in:
parent
3c478c312a
commit
400943ce99
@ -48,13 +48,8 @@ METER_TYPES = [
|
||||
|
||||
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
|
||||
|
||||
@ -88,7 +83,9 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
}
|
||||
}
|
||||
),
|
||||
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": {}}
|
||||
),
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
@ -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
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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()
|
||||
@ -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]
|
||||
@ -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"
|
||||
|
||||
@ -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()
|
||||
|
@ -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",
|
||||
)
|
||||
@ -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",
|
||||
)
|
||||
@ -469,11 +469,11 @@ async def test_legacy_support(hass):
|
||||
"tariffs,expected_entities",
|
||||
(
|
||||
(
|
||||
"",
|
||||
[],
|
||||
["sensor.electricity_meter"],
|
||||
),
|
||||
(
|
||||
"high,low",
|
||||
["high", "low"],
|
||||
[
|
||||
"sensor.electricity_meter_low",
|
||||
"sensor.electricity_meter_high",
|
||||
|
@ -77,7 +77,7 @@ def alter_time(retval):
|
||||
"net_consumption": False,
|
||||
"offset": 0,
|
||||
"source": "sensor.energy",
|
||||
"tariffs": "onpeak,midpeak,offpeak",
|
||||
"tariffs": ["onpeak", "midpeak", "offpeak"],
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -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"],
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -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",
|
||||
@ -336,7 +336,7 @@ async def test_init(hass, yaml_config, config_entry_config):
|
||||
"net_consumption": False,
|
||||
"offset": 0,
|
||||
"source": "sensor.gas",
|
||||
"tariffs": "",
|
||||
"tariffs": [],
|
||||
},
|
||||
],
|
||||
),
|
||||
@ -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"],
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -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": [],
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -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": [],
|
||||
},
|
||||
),
|
||||
),
|
||||
@ -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": [],
|
||||
},
|
||||
),
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user