Restrict HA entity list to sensor. domain only

This commit is contained in:
2026-04-14 02:02:50 -05:00
parent 24feeb4fe4
commit f08441e799
2 changed files with 6 additions and 5 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ class HomeAssistantClient:
result = []
for s in resp.json():
eid = s.get("entity_id", "")
if eid.startswith("binary_sensor."):
if not eid.startswith("sensor."):
continue
attrs = s.get("attributes", {})
if (attrs.get("device_class") == "battery"
+3 -2
View File
@@ -549,13 +549,14 @@ def test_ha_entities_endpoint(ha_app, ha_client_f):
assert tv["friendly_name"] == "TV Battery"
def test_ha_entities_excludes_binary_sensors(ha_app, ha_client_f):
"""binary_sensor. entities are excluded even when device_class is battery."""
def test_ha_entities_only_sensor_domain(ha_app, ha_client_f):
"""Only sensor. entities are returned — all other domains are excluded."""
mock_resp = MagicMock()
mock_resp.json.return_value = [
{"entity_id": "sensor.remote_battery", "attributes": {"device_class": "battery", "friendly_name": "Remote"}},
{"entity_id": "binary_sensor.door_battery_low", "attributes": {"device_class": "battery", "friendly_name": "Door low"}},
{"entity_id": "binary_sensor.smoke_battery", "attributes": {"friendly_name": "Smoke"}},
{"entity_id": "input_number.battery_threshold", "attributes": {}},
]
mock_resp.raise_for_status.return_value = None