diff --git a/ha_client.py b/ha_client.py index 6b6019c..8dc79c0 100644 --- a/ha_client.py +++ b/ha_client.py @@ -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" diff --git a/tests/test_ha_integration.py b/tests/test_ha_integration.py index be75c3a..7586300 100644 --- a/tests/test_ha_integration.py +++ b/tests/test_ha_integration.py @@ -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": "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": "binary_sensor.smoke_battery", "attributes": {"friendly_name": "Smoke"}}, + {"entity_id": "input_number.battery_threshold", "attributes": {}}, ] mock_resp.raise_for_status.return_value = None