mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +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:
|
def _validate_config(data: Any) -> Any:
|
||||||
"""Validate config."""
|
"""Validate config."""
|
||||||
tariffs: list[str]
|
|
||||||
if not data[CONF_TARIFFS]:
|
|
||||||
tariffs = []
|
|
||||||
else:
|
|
||||||
tariffs = data[CONF_TARIFFS].split(",")
|
|
||||||
try:
|
try:
|
||||||
vol.Unique()(tariffs)
|
vol.Unique()(data[CONF_TARIFFS])
|
||||||
except vol.Invalid as exc:
|
except vol.Invalid as exc:
|
||||||
raise SchemaFlowError("tariffs_not_unique") from 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(
|
vol.Required(CONF_METER_NET_CONSUMPTION, default=False): selector.selector(
|
||||||
{"boolean": {}}
|
{"boolean": {}}
|
||||||
),
|
),
|
||||||
|
@ -42,12 +42,7 @@ async def async_setup_entry(
|
|||||||
) -> None:
|
) -> None:
|
||||||
"""Initialize Utility Meter config entry."""
|
"""Initialize Utility Meter config entry."""
|
||||||
name = config_entry.title
|
name = config_entry.title
|
||||||
|
tariffs = config_entry.options[CONF_TARIFFS]
|
||||||
# Remove when frontend list selector is available
|
|
||||||
if not config_entry.options.get(CONF_TARIFFS):
|
|
||||||
tariffs = []
|
|
||||||
else:
|
|
||||||
tariffs = config_entry.options[CONF_TARIFFS].split(",")
|
|
||||||
|
|
||||||
legacy_add_entities = None
|
legacy_add_entities = None
|
||||||
unique_id = config_entry.entry_id
|
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]
|
tariff_entity = hass.data[DATA_UTILITY][entry_id][CONF_TARIFF_ENTITY]
|
||||||
|
|
||||||
meters = []
|
meters = []
|
||||||
|
tariffs = config_entry.options[CONF_TARIFFS]
|
||||||
# Remove when frontend list selector is available
|
|
||||||
if not config_entry.options.get(CONF_TARIFFS):
|
|
||||||
tariffs = []
|
|
||||||
else:
|
|
||||||
tariffs = config_entry.options[CONF_TARIFFS].split(",")
|
|
||||||
|
|
||||||
if not tariffs:
|
if not tariffs:
|
||||||
# Add single sensor, not gated by a tariff selector
|
# 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",
|
"name": "Electricity meter",
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": input_sensor_entity_id,
|
"source": input_sensor_entity_id,
|
||||||
"tariffs": "",
|
"tariffs": [],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -48,7 +48,7 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
|
|||||||
"net_consumption": False,
|
"net_consumption": False,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": input_sensor_entity_id,
|
"source": input_sensor_entity_id,
|
||||||
"tariffs": "",
|
"tariffs": [],
|
||||||
}
|
}
|
||||||
assert len(mock_setup_entry.mock_calls) == 1
|
assert len(mock_setup_entry.mock_calls) == 1
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ async def test_config_flow(hass: HomeAssistant, platform) -> None:
|
|||||||
"net_consumption": False,
|
"net_consumption": False,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": input_sensor_entity_id,
|
"source": input_sensor_entity_id,
|
||||||
"tariffs": "",
|
"tariffs": [],
|
||||||
}
|
}
|
||||||
assert config_entry.title == "Electricity meter"
|
assert config_entry.title == "Electricity meter"
|
||||||
|
|
||||||
@ -83,7 +83,7 @@ async def test_tariffs(hass: HomeAssistant) -> None:
|
|||||||
"name": "Electricity meter",
|
"name": "Electricity meter",
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": input_sensor_entity_id,
|
"source": input_sensor_entity_id,
|
||||||
"tariffs": "cat,dog,horse,cow",
|
"tariffs": ["cat", "dog", "horse", "cow"],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -98,7 +98,7 @@ async def test_tariffs(hass: HomeAssistant) -> None:
|
|||||||
"net_consumption": False,
|
"net_consumption": False,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": input_sensor_entity_id,
|
"source": input_sensor_entity_id,
|
||||||
"tariffs": "cat,dog,horse,cow",
|
"tariffs": ["cat", "dog", "horse", "cow"],
|
||||||
}
|
}
|
||||||
|
|
||||||
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
|
config_entry = hass.config_entries.async_entries(DOMAIN)[0]
|
||||||
@ -110,7 +110,7 @@ async def test_tariffs(hass: HomeAssistant) -> None:
|
|||||||
"net_consumption": False,
|
"net_consumption": False,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": input_sensor_entity_id,
|
"source": input_sensor_entity_id,
|
||||||
"tariffs": "cat,dog,horse,cow",
|
"tariffs": ["cat", "dog", "horse", "cow"],
|
||||||
}
|
}
|
||||||
assert config_entry.title == "Electricity meter"
|
assert config_entry.title == "Electricity meter"
|
||||||
|
|
||||||
@ -127,7 +127,7 @@ async def test_tariffs(hass: HomeAssistant) -> None:
|
|||||||
"name": "Electricity meter",
|
"name": "Electricity meter",
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": input_sensor_entity_id,
|
"source": input_sensor_entity_id,
|
||||||
"tariffs": "cat,cat,cat,cat",
|
"tariffs": ["cat", "cat", "cat", "cat"],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -186,7 +186,7 @@ async def test_services_config_entry(hass):
|
|||||||
"net_consumption": False,
|
"net_consumption": False,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": "sensor.energy",
|
"source": "sensor.energy",
|
||||||
"tariffs": "peak,offpeak",
|
"tariffs": ["peak", "offpeak"],
|
||||||
},
|
},
|
||||||
title="Energy bill",
|
title="Energy bill",
|
||||||
)
|
)
|
||||||
@ -202,7 +202,7 @@ async def test_services_config_entry(hass):
|
|||||||
"net_consumption": False,
|
"net_consumption": False,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": "sensor.energy",
|
"source": "sensor.energy",
|
||||||
"tariffs": "peak,offpeak",
|
"tariffs": ["peak", "offpeak"],
|
||||||
},
|
},
|
||||||
title="Energy bill2",
|
title="Energy bill2",
|
||||||
)
|
)
|
||||||
@ -469,11 +469,11 @@ async def test_legacy_support(hass):
|
|||||||
"tariffs,expected_entities",
|
"tariffs,expected_entities",
|
||||||
(
|
(
|
||||||
(
|
(
|
||||||
"",
|
[],
|
||||||
["sensor.electricity_meter"],
|
["sensor.electricity_meter"],
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"high,low",
|
["high", "low"],
|
||||||
[
|
[
|
||||||
"sensor.electricity_meter_low",
|
"sensor.electricity_meter_low",
|
||||||
"sensor.electricity_meter_high",
|
"sensor.electricity_meter_high",
|
||||||
|
@ -77,7 +77,7 @@ def alter_time(retval):
|
|||||||
"net_consumption": False,
|
"net_consumption": False,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": "sensor.energy",
|
"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,
|
"net_consumption": False,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": "sensor.energy",
|
"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,
|
"net_consumption": True,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": "sensor.energy",
|
"source": "sensor.energy",
|
||||||
"tariffs": "",
|
"tariffs": [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"cycle": "none",
|
"cycle": "none",
|
||||||
@ -336,7 +336,7 @@ async def test_init(hass, yaml_config, config_entry_config):
|
|||||||
"net_consumption": False,
|
"net_consumption": False,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": "sensor.gas",
|
"source": "sensor.gas",
|
||||||
"tariffs": "",
|
"tariffs": [],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@ -411,7 +411,7 @@ async def test_device_class(hass, yaml_config, config_entry_configs):
|
|||||||
"net_consumption": False,
|
"net_consumption": False,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": "sensor.energy",
|
"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,
|
"net_consumption": True,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": "sensor.energy",
|
"source": "sensor.energy",
|
||||||
"tariffs": "",
|
"tariffs": [],
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -582,7 +582,7 @@ async def test_net_consumption(hass, yaml_config, config_entry_config):
|
|||||||
"net_consumption": False,
|
"net_consumption": False,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": "sensor.energy",
|
"source": "sensor.energy",
|
||||||
"tariffs": "",
|
"tariffs": [],
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -650,7 +650,7 @@ async def test_non_net_consumption(hass, yaml_config, config_entry_config):
|
|||||||
"net_consumption": False,
|
"net_consumption": False,
|
||||||
"offset": 0,
|
"offset": 0,
|
||||||
"source": "sensor.energy",
|
"source": "sensor.energy",
|
||||||
"tariffs": "",
|
"tariffs": [],
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user