Exclude binary_sensor entities from HA battery entity list
This commit is contained in:
@@ -547,3 +547,22 @@ def test_ha_entities_endpoint(ha_app, ha_client_f):
|
||||
# friendly names present
|
||||
tv = next(e for e in data if e["entity_id"] == "sensor.tv_battery")
|
||||
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."""
|
||||
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"}},
|
||||
]
|
||||
mock_resp.raise_for_status.return_value = None
|
||||
|
||||
with patch("ha_client.requests.get", return_value=mock_resp):
|
||||
resp = ha_client_f.get("/ha/entities")
|
||||
|
||||
assert resp.status_code == 200
|
||||
data = resp.get_json()
|
||||
entity_ids = [e["entity_id"] for e in data]
|
||||
assert entity_ids == ["sensor.remote_battery"]
|
||||
|
||||
Reference in New Issue
Block a user