217 files

This commit is contained in:
Home Assistant Version Control
2026-07-30 23:59:38 +00:00
parent d43a63ad29
commit 7b5e46e702
217 changed files with 15978 additions and 3912 deletions
@@ -38,6 +38,29 @@ def _convert_template(config: ConfigType, source_key: str, target_key: str, hass
config[target_key] = Template(config.pop(source_key), hass)
def _convert_daily_fixed_energy(sensor_config: ConfigType, hass: HomeAssistant) -> None:
daily_fixed_config = dict(sensor_config[CONF_DAILY_FIXED_ENERGY])
_convert_template(daily_fixed_config, CONF_VALUE_TEMPLATE, CONF_VALUE, hass)
on_time = daily_fixed_config.get(CONF_ON_TIME)
daily_fixed_config[CONF_ON_TIME] = (
timedelta(hours=on_time["hours"], minutes=on_time["minutes"], seconds=on_time["seconds"])
if on_time
else timedelta(days=1)
)
sensor_config[CONF_DAILY_FIXED_ENERGY] = daily_fixed_config
def _convert_fixed(sensor_config: ConfigType, hass: HomeAssistant) -> None:
fixed_config = dict(sensor_config[CONF_FIXED])
_convert_template(fixed_config, CONF_POWER_TEMPLATE, CONF_POWER, hass)
if CONF_STATES_POWER in fixed_config:
fixed_config[CONF_STATES_POWER] = {
key: Template(value, hass) if isinstance(value, str) and "{{" in value else value
for key, value in normalize_states_power(fixed_config[CONF_STATES_POWER]).items()
}
sensor_config[CONF_FIXED] = fixed_config
def convert_config_entry_to_sensor_config(config_entry: ConfigEntry, hass: HomeAssistant) -> ConfigType:
"""Convert the config entry structure to the sensor config used to create the entities."""
sensor_config = dict(config_entry.data)
@@ -49,25 +72,10 @@ def convert_config_entry_to_sensor_config(config_entry: ConfigEntry, hass: HomeA
sensor_config[CONF_FORCE_ENERGY_SENSOR_CREATION] = True
if CONF_DAILY_FIXED_ENERGY in sensor_config:
daily_fixed_config = dict(sensor_config[CONF_DAILY_FIXED_ENERGY])
_convert_template(daily_fixed_config, CONF_VALUE_TEMPLATE, CONF_VALUE, hass)
on_time = daily_fixed_config.get(CONF_ON_TIME)
daily_fixed_config[CONF_ON_TIME] = (
timedelta(hours=on_time["hours"], minutes=on_time["minutes"], seconds=on_time["seconds"])
if on_time
else timedelta(days=1)
)
sensor_config[CONF_DAILY_FIXED_ENERGY] = daily_fixed_config
_convert_daily_fixed_energy(sensor_config, hass)
if CONF_FIXED in sensor_config:
fixed_config = dict(sensor_config[CONF_FIXED])
_convert_template(fixed_config, CONF_POWER_TEMPLATE, CONF_POWER, hass)
if CONF_STATES_POWER in fixed_config:
fixed_config[CONF_STATES_POWER] = {
key: Template(value, hass) if isinstance(value, str) and "{{" in value else value
for key, value in normalize_states_power(fixed_config[CONF_STATES_POWER]).items()
}
sensor_config[CONF_FIXED] = fixed_config
_convert_fixed(sensor_config, hass)
if CONF_LINEAR in sensor_config:
sensor_config[CONF_LINEAR] = dict(sensor_config[CONF_LINEAR])
@@ -97,7 +97,7 @@ def get_global_configuration(hass: HomeAssistant, config: ConfigType) -> ConfigT
global_config.update(get_global_gui_configuration(global_config_entry))
# Then override with YAML configuration if available
yaml_config: dict = config.get(DOMAIN, {})
yaml_config: ConfigType = config.get(DOMAIN, {})
if yaml_config:
global_config.update(yaml_config)
@@ -2,6 +2,8 @@
from __future__ import annotations
from typing import Any
from homeassistant.components.sensor import PLATFORM_SCHEMA as SENSOR_PLATFORM_SCHEMA
from homeassistant.components.utility_meter import max_28_days
from homeassistant.components.utility_meter.const import METER_TYPES
@@ -162,7 +164,7 @@ SENSOR_CONFIG = {
}
def build_nested_configuration_schema(schema: dict, iteration: int = 0) -> dict:
def build_nested_configuration_schema(schema: dict[Any, Any], iteration: int = 0) -> dict[Any, Any]:
if iteration == MAX_GROUP_NESTING_LEVEL:
return schema
iteration += 1