Sfoglia il codice sorgente

Fix HA energy sensors not detected due to case-sensitive unit matching

Home Assistant integrations may report units in different cases (e.g., "w"
instead of "W", "kwh" instead of "kWh"). The sensor entity filter was using
case-sensitive comparison, causing valid energy sensors to not appear in
the Energy Monitoring dropdown.

Changed unit comparison to case-insensitive matching in list_sensor_entities().

Closes #119
maziggy 4 mesi fa
parent
commit
721eab1f67
1 ha cambiato i file con 5 aggiunte e 5 eliminazioni
  1. 5 5
      backend/app/services/homeassistant.py

+ 5 - 5
backend/app/services/homeassistant.py

@@ -282,9 +282,9 @@ class HomeAssistantService:
                 )
                 )
                 response.raise_for_status()
                 response.raise_for_status()
 
 
-                # Valid units for energy monitoring sensors
-                power_units = {"W", "kW", "mW"}
-                energy_units = {"kWh", "Wh", "MWh"}
+                # Valid units for energy monitoring sensors (lowercase for case-insensitive matching)
+                power_units = {"w", "kw", "mw"}
+                energy_units = {"kwh", "wh", "mwh"}
                 valid_units = power_units | energy_units
                 valid_units = power_units | energy_units
 
 
                 entities = []
                 entities = []
@@ -299,8 +299,8 @@ class HomeAssistantService:
                     attrs = entity.get("attributes", {})
                     attrs = entity.get("attributes", {})
                     unit = attrs.get("unit_of_measurement", "")
                     unit = attrs.get("unit_of_measurement", "")
 
 
-                    # Only include sensors with power/energy units
-                    if unit in valid_units:
+                    # Only include sensors with power/energy units (case-insensitive)
+                    if unit.lower() in valid_units:
                         entities.append(
                         entities.append(
                             {
                             {
                                 "entity_id": entity_id,
                                 "entity_id": entity_id,