126 files
This commit is contained in:
@@ -328,12 +328,12 @@ def fleet_excluded_entities(hass: HomeAssistant) -> set[str]:
|
||||
Inlined lookup (not via battery_fleet_setup.find_fleet_entry) to keep this
|
||||
module import-cycle-free — setup imports the aggregation, not vice versa.
|
||||
"""
|
||||
from ..const import CONF_OBJECT, DOMAIN
|
||||
from ..const import BATTERY_FLEET_EXCLUDED, BATTERY_FLEET_OBJECT_FLAG, CONF_OBJECT, DOMAIN
|
||||
|
||||
for entry in hass.config_entries.async_entries(DOMAIN):
|
||||
obj = entry.data.get(CONF_OBJECT, {})
|
||||
if obj.get("battery_fleet"):
|
||||
return set(obj.get("battery_fleet_excluded") or [])
|
||||
if obj.get(BATTERY_FLEET_OBJECT_FLAG):
|
||||
return set(obj.get(BATTERY_FLEET_EXCLUDED) or [])
|
||||
return set()
|
||||
|
||||
|
||||
@@ -357,7 +357,10 @@ def _is_self_charging(hass: HomeAssistant, device_id: str | None) -> bool:
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
device = dr.async_get(hass).async_get(device_id)
|
||||
if device and any(domain == "mobile_app" for domain, _ in device.identifiers):
|
||||
# #127: identifiers are typed (domain, id) but the registry doesn't enforce
|
||||
# it — NissanConnect ships 3-element tuples, and strict unpacking took the
|
||||
# whole fleet down. Only the domain matters here.
|
||||
if device and any(ident[0] == "mobile_app" for ident in device.identifiers):
|
||||
return True
|
||||
for reg_entry in er.async_entries_for_device(er.async_get(hass), device_id, include_disabled_entities=True):
|
||||
if reg_entry.domain in ("vacuum", "lawn_mower"):
|
||||
|
||||
@@ -18,7 +18,7 @@ from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import HomeAssistantError
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from ..const import CONF_OBJECT, CONF_PARTS, CONF_TASKS, DOMAIN
|
||||
from ..const import BATTERY_FLEET_EXCLUDED, BATTERY_FLEET_OBJECT_FLAG, CONF_OBJECT, CONF_PARTS, CONF_TASKS, DOMAIN
|
||||
from .battery_fleet import _norm_type, discover_battery_types, lifetime_months, read_batteries
|
||||
|
||||
# The global aggregate sensor the fleet task triggers on (fixed entity_id).
|
||||
@@ -26,7 +26,7 @@ LOW_COUNT_ENTITY_ID = "sensor.maintenance_supporter_batteries_to_replace"
|
||||
|
||||
# Marker on the object + task so the panel renders the battery detail section
|
||||
# and setup is idempotent (never a second fleet).
|
||||
OBJECT_FLAG = "battery_fleet"
|
||||
OBJECT_FLAG = BATTERY_FLEET_OBJECT_FLAG
|
||||
TASK_FLAG = "battery_fleet_task"
|
||||
|
||||
|
||||
@@ -347,12 +347,12 @@ def set_battery_excluded(hass: HomeAssistant, entity_id: str, excluded: bool) ->
|
||||
return False
|
||||
new_data = dict(entry.data)
|
||||
obj = dict(new_data.get(CONF_OBJECT, {}))
|
||||
current = set(obj.get("battery_fleet_excluded") or [])
|
||||
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)
|
||||
obj[BATTERY_FLEET_EXCLUDED] = sorted(current)
|
||||
new_data[CONF_OBJECT] = obj
|
||||
hass.config_entries.async_update_entry(entry, data=new_data)
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user