mirror of
https://github.com/home-assistant/core.git
synced 2026-12-02 19:57:03 -04:00
Add fault binary sensor to SteamVR Base Station (#188261)
This commit is contained in:
@@ -17,6 +17,7 @@ from .const import DOMAIN
|
||||
from .coordinator import SteamVRBaseStationConfigEntry, SteamVRBaseStationCoordinator
|
||||
|
||||
PLATFORMS: list[Platform] = [
|
||||
Platform.BINARY_SENSOR,
|
||||
Platform.BUTTON,
|
||||
Platform.SELECT,
|
||||
Platform.SENSOR,
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
"""Fault binary sensor for SteamVR Base Station."""
|
||||
|
||||
from typing import override
|
||||
|
||||
from homeassistant.components.binary_sensor import (
|
||||
BinarySensorDeviceClass,
|
||||
BinarySensorEntity,
|
||||
BinarySensorEntityDescription,
|
||||
)
|
||||
from homeassistant.const import EntityCategory
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
|
||||
|
||||
from .coordinator import SteamVRBaseStationConfigEntry
|
||||
from .entity import SteamVRBaseStationEntity
|
||||
|
||||
PARALLEL_UPDATES = 0
|
||||
|
||||
FAULT = BinarySensorEntityDescription(
|
||||
key="fault",
|
||||
device_class=BinarySensorDeviceClass.PROBLEM,
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant,
|
||||
entry: SteamVRBaseStationConfigEntry,
|
||||
async_add_entities: AddConfigEntryEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up the fault binary sensor."""
|
||||
async_add_entities([SteamVRBaseStationFaultSensor(entry.runtime_data, FAULT)])
|
||||
|
||||
|
||||
class SteamVRBaseStationFaultSensor(SteamVRBaseStationEntity, BinarySensorEntity):
|
||||
"""On when the station reports a fault."""
|
||||
|
||||
@property
|
||||
@override
|
||||
def is_on(self) -> bool | None:
|
||||
"""Return whether the station reports a fault."""
|
||||
return self.coordinator.station.state.faulty
|
||||
@@ -0,0 +1,52 @@
|
||||
# serializer version: 1
|
||||
# name: test_binary_sensor_entities[binary_sensor.lhb_747a9bc5_problem-entry]
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': list([
|
||||
None,
|
||||
]),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'config_subentry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <DeviceEntry connections=[('bluetooth', 'AA:BB:CC:DD:EE:01')]>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.lhb_747a9bc5_problem',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'labels': set({
|
||||
}),
|
||||
'name': None,
|
||||
'object_id_base': 'Problem',
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.PROBLEM: 'problem'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Problem',
|
||||
'platform': 'steamvr_base_station',
|
||||
'previous_unique_id': None,
|
||||
'suggested_object_id': None,
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'AA:BB:CC:DD:EE:01_fault',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_binary_sensor_entities[binary_sensor.lhb_747a9bc5_problem-state]
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
<EntityStateAttribute.DEVICE_CLASS: 'device_class'>: 'problem',
|
||||
<EntityStateAttribute.FRIENDLY_NAME: 'friendly_name'>: 'LHB-747A9BC5 Problem',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.lhb_747a9bc5_problem',
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'off',
|
||||
})
|
||||
# ---
|
||||
@@ -0,0 +1,46 @@
|
||||
"""Test the SteamVR Base Station fault binary sensor."""
|
||||
|
||||
import pytest
|
||||
from pytest_homeassistant.common import MockConfigEntry, snapshot_platform
|
||||
from pytest_homeassistant.components.bluetooth import (
|
||||
inject_bluetooth_service_info_bleak,
|
||||
)
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.const import STATE_OFF, STATE_ON, Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from . import make_service_info, payload
|
||||
|
||||
FAULT = "binary_sensor.lhb_747a9bc5_problem"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def platforms() -> list[Platform]:
|
||||
"""Only set up the binary sensor platform."""
|
||||
return [Platform.BINARY_SENSOR]
|
||||
|
||||
|
||||
async def test_binary_sensor_entities(
|
||||
hass: HomeAssistant,
|
||||
init_integration: MockConfigEntry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the binary sensor entities."""
|
||||
await snapshot_platform(hass, entity_registry, snapshot, init_integration.entry_id)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("fault", "expected"),
|
||||
[pytest.param(0, STATE_OFF, id="ok"), pytest.param(1, STATE_ON, id="fault")],
|
||||
)
|
||||
@pytest.mark.usefixtures("init_integration")
|
||||
async def test_fault_follows_advertisements(
|
||||
hass: HomeAssistant, fault: int, expected: str
|
||||
) -> None:
|
||||
"""Test the fault sensor reflects the advertised fault flag."""
|
||||
inject_bluetooth_service_info_bleak(hass, make_service_info(payload(fault=fault)))
|
||||
await hass.async_block_till_done()
|
||||
assert hass.states.get(FAULT).state == expected
|
||||
Reference in New Issue
Block a user