Makes sure YAML defined tariffs are unique (#69151)

This commit is contained in:
Diogo Gomes
2022-04-04 11:12:25 +02:00
committed by Franck Nijhof
parent 39a38d9866
commit d99e04e2bc
2 changed files with 22 additions and 1 deletions
@@ -85,7 +85,7 @@ METER_CONFIG_SCHEMA = vol.Schema(
vol.Optional(CONF_METER_DELTA_VALUES, default=False): cv.boolean,
vol.Optional(CONF_METER_NET_CONSUMPTION, default=False): cv.boolean,
vol.Optional(CONF_TARIFFS, default=[]): vol.All(
cv.ensure_list, [cv.string]
cv.ensure_list, vol.Unique(), [cv.string]
),
vol.Optional(CONF_CRON_PATTERN): validate_cron_pattern,
},
@@ -226,6 +226,27 @@ async def test_state(hass, yaml_config, config_entry_config):
assert state.state == "0.123"
@pytest.mark.parametrize(
"yaml_config",
(
(
{
"utility_meter": {
"energy_bill": {
"source": "sensor.energy",
"tariffs": ["onpeak", "onpeak"],
}
}
},
None,
),
),
)
async def test_not_unique_tariffs(hass, yaml_config):
"""Test utility sensor state initializtion."""
assert not await async_setup_component(hass, DOMAIN, yaml_config)
@pytest.mark.parametrize(
"yaml_config,config_entry_config",
(