Refactor WLED binary sensor test (#88579)
This commit is contained in:
parent
adb0455bd2
commit
19c08bfdd5
2 changed files with 91 additions and 26 deletions
75
tests/components/wled/snapshots/test_binary_sensor.ambr
Normal file
75
tests/components/wled/snapshots/test_binary_sensor.ambr
Normal file
|
@ -0,0 +1,75 @@
|
|||
# serializer version: 1
|
||||
# name: test_update_available
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'device_class': 'update',
|
||||
'friendly_name': 'WLED RGB Light Firmware',
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'binary_sensor.wled_rgb_light_firmware',
|
||||
'last_changed': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'on',
|
||||
})
|
||||
# ---
|
||||
# name: test_update_available.1
|
||||
EntityRegistryEntrySnapshot({
|
||||
'aliases': set({
|
||||
}),
|
||||
'area_id': None,
|
||||
'capabilities': None,
|
||||
'config_entry_id': <ANY>,
|
||||
'device_class': None,
|
||||
'device_id': <ANY>,
|
||||
'disabled_by': None,
|
||||
'domain': 'binary_sensor',
|
||||
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
|
||||
'entity_id': 'binary_sensor.wled_rgb_light_firmware',
|
||||
'has_entity_name': True,
|
||||
'hidden_by': None,
|
||||
'icon': None,
|
||||
'id': <ANY>,
|
||||
'name': None,
|
||||
'options': dict({
|
||||
}),
|
||||
'original_device_class': <BinarySensorDeviceClass.UPDATE: 'update'>,
|
||||
'original_icon': None,
|
||||
'original_name': 'Firmware',
|
||||
'platform': 'wled',
|
||||
'supported_features': 0,
|
||||
'translation_key': None,
|
||||
'unique_id': 'aabbccddeeff_update',
|
||||
'unit_of_measurement': None,
|
||||
})
|
||||
# ---
|
||||
# name: test_update_available.2
|
||||
DeviceRegistryEntrySnapshot({
|
||||
'area_id': None,
|
||||
'config_entries': <ANY>,
|
||||
'configuration_url': 'http://127.0.0.1',
|
||||
'connections': set({
|
||||
tuple(
|
||||
'mac',
|
||||
'aa:bb:cc:dd:ee:ff',
|
||||
),
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'entry_type': None,
|
||||
'hw_version': 'esp8266',
|
||||
'id': <ANY>,
|
||||
'identifiers': set({
|
||||
tuple(
|
||||
'wled',
|
||||
'aabbccddeeff',
|
||||
),
|
||||
}),
|
||||
'is_new': False,
|
||||
'manufacturer': 'WLED',
|
||||
'model': 'DIY light',
|
||||
'name': 'WLED RGB Light',
|
||||
'name_by_user': None,
|
||||
'suggested_area': None,
|
||||
'sw_version': '0.8.5',
|
||||
'via_device_id': None,
|
||||
})
|
||||
# ---
|
|
@ -1,56 +1,46 @@
|
|||
"""Tests for the WLED binary sensor platform."""
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
|
||||
from homeassistant.const import (
|
||||
ATTR_DEVICE_CLASS,
|
||||
ATTR_ICON,
|
||||
STATE_OFF,
|
||||
STATE_ON,
|
||||
EntityCategory,
|
||||
)
|
||||
from homeassistant.const import STATE_OFF
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("init_integration")
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_update_available(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||
hass: HomeAssistant,
|
||||
device_registry: dr.DeviceRegistry,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the firmware update binary sensor."""
|
||||
assert (state := hass.states.get("binary_sensor.wled_rgb_light_firmware"))
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == BinarySensorDeviceClass.UPDATE
|
||||
assert state.state == STATE_ON
|
||||
assert ATTR_ICON not in state.attributes
|
||||
assert state == snapshot
|
||||
|
||||
assert (entry := entity_registry.async_get("binary_sensor.wled_rgb_light_firmware"))
|
||||
assert entry.unique_id == "aabbccddeeff_update"
|
||||
assert entry.entity_category is EntityCategory.DIAGNOSTIC
|
||||
assert (entity_entry := entity_registry.async_get(state.entity_id))
|
||||
assert entity_entry == snapshot
|
||||
|
||||
assert entity_entry.device_id
|
||||
assert (device_entry := device_registry.async_get(entity_entry.device_id))
|
||||
assert device_entry == snapshot
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
@pytest.mark.parametrize("device_fixture", ["rgb_websocket"])
|
||||
async def test_no_update_available(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||
) -> None:
|
||||
async def test_no_update_available(hass: HomeAssistant) -> None:
|
||||
"""Test the update binary sensor. There is no update available."""
|
||||
assert (state := hass.states.get("binary_sensor.wled_websocket_firmware"))
|
||||
assert state.attributes.get(ATTR_DEVICE_CLASS) == BinarySensorDeviceClass.UPDATE
|
||||
assert state.state == STATE_OFF
|
||||
assert ATTR_ICON not in state.attributes
|
||||
|
||||
assert (entry := entity_registry.async_get("binary_sensor.wled_websocket_firmware"))
|
||||
assert entry.unique_id == "aabbccddeeff_update"
|
||||
assert entry.entity_category is EntityCategory.DIAGNOSTIC
|
||||
|
||||
|
||||
async def test_disabled_by_default(
|
||||
hass: HomeAssistant, entity_registry: er.EntityRegistry
|
||||
) -> None:
|
||||
"""Test that the binary update sensor is disabled by default."""
|
||||
assert hass.states.get("binary_sensor.wled_rgb_light_firmware") is None
|
||||
assert not hass.states.get("binary_sensor.wled_rgb_light_firmware")
|
||||
|
||||
assert (entry := entity_registry.async_get("binary_sensor.wled_rgb_light_firmware"))
|
||||
assert entry.disabled
|
||||
|
|
Loading…
Add table
Reference in a new issue