217 files
This commit is contained in:
@@ -48,6 +48,7 @@ from homeassistant.helpers.event import (
|
||||
from homeassistant.helpers.json import JSONEncoder
|
||||
from homeassistant.helpers.singleton import singleton
|
||||
from homeassistant.helpers.storage import Store
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from custom_components.powercalc.analytics.analytics import collect_analytics
|
||||
from custom_components.powercalc.const import (
|
||||
@@ -124,6 +125,11 @@ from custom_components.powercalc.unit import (
|
||||
ENTITY_ID_FORMAT = SENSOR_DOMAIN + ".{}"
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# Predicate used to narrow a list of entities down to the group members.
|
||||
EntityPredicate = Callable[[Entity], bool]
|
||||
# Shape persisted by PreviousStateStoreStore: group id -> entity id -> serialized State.
|
||||
StoredStates = dict[str, dict[str, Any]]
|
||||
STORAGE_KEY = "powercalc_group"
|
||||
STORAGE_VERSION = 2
|
||||
# How long between periodically saving the current states to disk
|
||||
@@ -134,7 +140,7 @@ def create_group_sensors_yaml(
|
||||
hass: HomeAssistant,
|
||||
sensor_config: dict[str, Any],
|
||||
entities: list[Entity],
|
||||
filters: list[Callable] | None = None,
|
||||
filters: list[EntityPredicate] | None = None,
|
||||
) -> list[Entity]:
|
||||
"""Create grouped power and energy sensors."""
|
||||
power_sensor_ids = filter_entity_list_by_class(entities, SensorDeviceClass.POWER, filters)
|
||||
@@ -155,7 +161,7 @@ def create_group_sensors_yaml(
|
||||
async def create_group_sensors_gui(
|
||||
hass: HomeAssistant,
|
||||
entry: ConfigEntry,
|
||||
sensor_config: dict,
|
||||
sensor_config: ConfigType,
|
||||
) -> list[Entity]:
|
||||
"""Create group sensors based on a config_entry."""
|
||||
group_name = str(entry.data.get(CONF_NAME))
|
||||
@@ -220,9 +226,9 @@ def create_group_sensors_custom(
|
||||
|
||||
|
||||
def filter_entity_list_by_class(
|
||||
all_entities: list,
|
||||
all_entities: list[Entity],
|
||||
device_class: SensorDeviceClass,
|
||||
default_filters: list[Callable] | None = None,
|
||||
default_filters: list[EntityPredicate] | None = None,
|
||||
) -> set[str]:
|
||||
"""Filter entity list to only include entities of the given class."""
|
||||
class_name = PowerSensor if device_class == SensorDeviceClass.POWER else EnergySensor
|
||||
@@ -346,7 +352,7 @@ def create_grouped_power_sensor(
|
||||
hass: HomeAssistant,
|
||||
group_name: str,
|
||||
group_type: GroupType,
|
||||
sensor_config: dict,
|
||||
sensor_config: ConfigType,
|
||||
power_sensor_ids: set[str],
|
||||
) -> GroupedPowerSensor:
|
||||
name = generate_power_sensor_name(sensor_config, group_name)
|
||||
@@ -378,7 +384,7 @@ def create_grouped_energy_sensor(
|
||||
hass: HomeAssistant,
|
||||
group_name: str,
|
||||
group_type: GroupType,
|
||||
sensor_config: dict,
|
||||
sensor_config: ConfigType,
|
||||
energy_sensor_ids: set[str],
|
||||
power_sensor: GroupedPowerSensor | None,
|
||||
) -> EnergySensor:
|
||||
@@ -941,7 +947,7 @@ class PreviousStateStore:
|
||||
return instance
|
||||
|
||||
def __init__(self, hass: HomeAssistant) -> None:
|
||||
self.store: Store = PreviousStateStoreStore(
|
||||
self.store: Store[StoredStates] = PreviousStateStoreStore(
|
||||
hass,
|
||||
STORAGE_VERSION,
|
||||
STORAGE_KEY,
|
||||
@@ -1007,7 +1013,7 @@ class PreviousStateStore:
|
||||
)
|
||||
|
||||
|
||||
class PreviousStateStoreStore(Store):
|
||||
class PreviousStateStoreStore(Store[StoredStates]):
|
||||
"""Store area registry data."""
|
||||
|
||||
async def _async_migrate_func( # type: ignore
|
||||
|
||||
Reference in New Issue
Block a user