Use glass break device class in Hive (#182239)

Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
Jonas Petersson
2026-09-19 11:03:02 +02:00
committed by GitHub
co-authored by Codex
parent af4a191d6e
commit 3199454185
2 changed files with 52 additions and 3 deletions
@@ -42,7 +42,7 @@ BINARY_SENSOR_TYPES: tuple[BinarySensorEntityDescription, ...] = (
),
BinarySensorEntityDescription(
key="GLASS_BREAK",
device_class=BinarySensorDeviceClass.SOUND,
device_class=BinarySensorDeviceClass.GLASS_BREAK,
),
)
+51 -2
View File
@@ -3,10 +3,11 @@
from typing import Any
from unittest.mock import AsyncMock, MagicMock, patch
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.hive.const import DOMAIN
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.const import ATTR_DEVICE_CLASS, CONF_PASSWORD, CONF_USERNAME
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers import device_registry as dr, entity_registry as er
from tests.common import MockConfigEntry
@@ -50,6 +51,23 @@ _CHILD_BINARY_SENSOR = {
"status": {"state": True},
}
_GLASS_BREAK_BINARY_SENSOR = {
"device_id": "hive-glass-break-id",
"hiveID": "hive-glass-break-id",
"hiveName": "Glass Break",
"haName": "Glass Break",
"device_name": "Glass Break Sensor",
"hiveType": "GLASS_BREAK",
"parentDevice": "hive-hub-id",
"deviceData": {
"model": "Glass Break Sensor",
"version": "1.2.3",
"manufacturer": "Hive",
"online": True,
},
"status": {"state": False},
}
# The hub's own diagnostic sensor reports the hub as its own parent
# (parentDevice == device_id), which would link the hub device to itself.
_HUB_BINARY_SENSOR = {
@@ -195,3 +213,34 @@ async def test_hub_diagnostic_sensor_not_linked_to_itself(
)
assert hub_device is not None
assert hub_device.via_device_id is None
async def test_glass_break_device_class(
hass: HomeAssistant,
entity_registry: er.EntityRegistry,
) -> None:
"""Test the glass break binary sensor device class."""
entry = MockConfigEntry(domain=DOMAIN, data=_ENTRY_DATA)
entry.add_to_hass(hass)
mock_hive = _make_mock_hive(
{"macAddress": "00:1C:2B:1C:2E:68"},
{"binary_sensor": [_GLASS_BREAK_BINARY_SENSOR], "sensor": []},
)
mock_hive.session.updateData = AsyncMock()
mock_hive.sensor.getSensor = AsyncMock(side_effect=lambda device: device)
with patch(
"homeassistant.components.hive.Hive",
return_value=mock_hive,
):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
entity_id = entity_registry.async_get_entity_id(
"binary_sensor", DOMAIN, "hive-glass-break-id-GLASS_BREAK"
)
assert entity_id
state = hass.states.get(entity_id)
assert state
assert state.attributes[ATTR_DEVICE_CLASS] == BinarySensorDeviceClass.GLASS_BREAK