224 files

This commit is contained in:
Home Assistant Version Control
2026-07-27 13:30:34 +00:00
parent b5723aa856
commit e36b8a1a22
224 changed files with 9967 additions and 2663 deletions
@@ -49,10 +49,10 @@ async def async_setup_battery_fleet(hass: HomeAssistant, language: str | None =
"""
from ..websocket.objects import async_create_object
from ..websocket.tasks_persist import async_persist_task
from .i18n import normalize_language
from .i18n import normalize_language, normalize_language_code
from .parts import normalize_part
lang = (language or normalize_language(hass))[:2].lower()
lang = normalize_language_code(language) if language else normalize_language(hass)
types = discover_battery_types(hass) # {TYPE: total_qty}
existing = find_fleet_entry(hass)
@@ -220,6 +220,30 @@ async def async_mark_replaced(hass: HomeAssistant, entity_ids: list[str] | None
return {"marked": len(targets), "pressed": pressed, "consumed": consumed}
def set_battery_excluded(hass: HomeAssistant, entity_id: str, excluded: bool) -> bool:
"""Persist a manual exclude/include of one battery on the fleet object.
Issue #107: some tracked batteries should never appear (a rechargeable
device the heuristics missed, a neighbour's sensor, …). Stored as
``battery_fleet_excluded`` on the fleet object dict. Returns False when
no fleet exists yet.
"""
entry = find_fleet_entry(hass)
if entry is None:
return False
new_data = dict(entry.data)
obj = dict(new_data.get(CONF_OBJECT, {}))
current = set(obj.get("battery_fleet_excluded") or [])
if excluded:
current.add(entity_id)
else:
current.discard(entity_id)
obj["battery_fleet_excluded"] = sorted(current)
new_data[CONF_OBJECT] = obj
hass.config_entries.async_update_entry(entry, data=new_data)
return True
def find_fleet_task(entry: ConfigEntry) -> tuple[str, dict[str, Any]] | None:
"""The flagged fleet task (id, data) on the fleet entry, or None."""
for task_id, task_data in (entry.data.get(CONF_TASKS) or {}).items():