mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 06:17:07 +00:00
Use SnapshotAssertion in SFR binary sensor tests (#89624)
This commit is contained in:
parent
429e52cf3d
commit
f3da95fb1f
@ -1,5 +1,4 @@
|
|||||||
"""Constants for SFR Box tests."""
|
"""Constants for SFR Box tests."""
|
||||||
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
|
|
||||||
from homeassistant.components.button import ButtonDeviceClass
|
from homeassistant.components.button import ButtonDeviceClass
|
||||||
from homeassistant.components.sensor import ATTR_OPTIONS, ATTR_STATE_CLASS
|
from homeassistant.components.sensor import ATTR_OPTIONS, ATTR_STATE_CLASS
|
||||||
from homeassistant.components.sfr_box.const import DOMAIN
|
from homeassistant.components.sfr_box.const import DOMAIN
|
||||||
@ -12,7 +11,6 @@ from homeassistant.const import (
|
|||||||
ATTR_STATE,
|
ATTR_STATE,
|
||||||
ATTR_SW_VERSION,
|
ATTR_SW_VERSION,
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
STATE_ON,
|
|
||||||
STATE_UNKNOWN,
|
STATE_UNKNOWN,
|
||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
@ -33,14 +31,6 @@ EXPECTED_ENTITIES = {
|
|||||||
ATTR_NAME: "SFR Box",
|
ATTR_NAME: "SFR Box",
|
||||||
ATTR_SW_VERSION: "NB6VAC-MAIN-R4.0.44k",
|
ATTR_SW_VERSION: "NB6VAC-MAIN-R4.0.44k",
|
||||||
},
|
},
|
||||||
Platform.BINARY_SENSOR: [
|
|
||||||
{
|
|
||||||
ATTR_DEVICE_CLASS: BinarySensorDeviceClass.CONNECTIVITY,
|
|
||||||
ATTR_ENTITY_ID: "binary_sensor.sfr_box_dsl_status",
|
|
||||||
ATTR_STATE: STATE_ON,
|
|
||||||
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_dsl_status",
|
|
||||||
},
|
|
||||||
],
|
|
||||||
Platform.BUTTON: [
|
Platform.BUTTON: [
|
||||||
{
|
{
|
||||||
ATTR_DEVICE_CLASS: ButtonDeviceClass.RESTART,
|
ATTR_DEVICE_CLASS: ButtonDeviceClass.RESTART,
|
||||||
|
75
tests/components/sfr_box/snapshots/test_binary_sensor.ambr
Normal file
75
tests/components/sfr_box/snapshots/test_binary_sensor.ambr
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
# serializer version: 1
|
||||||
|
# name: test_binary_sensors
|
||||||
|
list([
|
||||||
|
DeviceRegistryEntrySnapshot({
|
||||||
|
'area_id': None,
|
||||||
|
'config_entries': <ANY>,
|
||||||
|
'configuration_url': 'http://192.168.0.1',
|
||||||
|
'connections': set({
|
||||||
|
}),
|
||||||
|
'disabled_by': None,
|
||||||
|
'entry_type': None,
|
||||||
|
'hw_version': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'identifiers': set({
|
||||||
|
tuple(
|
||||||
|
'sfr_box',
|
||||||
|
'e4:5d:51:00:11:22',
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
'is_new': False,
|
||||||
|
'manufacturer': None,
|
||||||
|
'model': 'NB6VAC-FXC-r0',
|
||||||
|
'name': 'SFR Box',
|
||||||
|
'name_by_user': None,
|
||||||
|
'suggested_area': None,
|
||||||
|
'sw_version': 'NB6VAC-MAIN-R4.0.44k',
|
||||||
|
'via_device_id': None,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
# ---
|
||||||
|
# name: test_binary_sensors.1
|
||||||
|
list([
|
||||||
|
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.sfr_box_dsl_status',
|
||||||
|
'has_entity_name': True,
|
||||||
|
'hidden_by': None,
|
||||||
|
'icon': None,
|
||||||
|
'id': <ANY>,
|
||||||
|
'name': None,
|
||||||
|
'options': dict({
|
||||||
|
}),
|
||||||
|
'original_device_class': <BinarySensorDeviceClass.CONNECTIVITY: 'connectivity'>,
|
||||||
|
'original_icon': None,
|
||||||
|
'original_name': 'DSL status',
|
||||||
|
'platform': 'sfr_box',
|
||||||
|
'supported_features': 0,
|
||||||
|
'translation_key': None,
|
||||||
|
'unique_id': 'e4:5d:51:00:11:22_dsl_status',
|
||||||
|
'unit_of_measurement': None,
|
||||||
|
}),
|
||||||
|
])
|
||||||
|
# ---
|
||||||
|
# name: test_binary_sensors[binary_sensor.sfr_box_dsl_status]
|
||||||
|
StateSnapshot({
|
||||||
|
'attributes': ReadOnlyDict({
|
||||||
|
'device_class': 'connectivity',
|
||||||
|
'friendly_name': 'SFR Box DSL status',
|
||||||
|
}),
|
||||||
|
'context': <ANY>,
|
||||||
|
'entity_id': 'binary_sensor.sfr_box_dsl_status',
|
||||||
|
'last_changed': <ANY>,
|
||||||
|
'last_updated': <ANY>,
|
||||||
|
'state': 'on',
|
||||||
|
})
|
||||||
|
# ---
|
@ -1,17 +1,15 @@
|
|||||||
"""Test the SFR Box sensors."""
|
"""Test the SFR Box binary sensors."""
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import Platform
|
from homeassistant.const import Platform
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
from homeassistant.helpers import device_registry as dr, entity_registry as er
|
||||||
|
|
||||||
from . import check_device_registry, check_entities
|
|
||||||
from .const import EXPECTED_ENTITIES
|
|
||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures("system_get_info", "dsl_get_info")
|
pytestmark = pytest.mark.usefixtures("system_get_info", "dsl_get_info")
|
||||||
|
|
||||||
|
|
||||||
@ -27,14 +25,21 @@ async def test_binary_sensors(
|
|||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
device_registry: dr.DeviceRegistry,
|
device_registry: dr.DeviceRegistry,
|
||||||
entity_registry: er.EntityRegistry,
|
entity_registry: er.EntityRegistry,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test for SFR Box binary sensors."""
|
"""Test for SFR Box binary sensors."""
|
||||||
await hass.config_entries.async_setup(config_entry.entry_id)
|
await hass.config_entries.async_setup(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
check_device_registry(device_registry, EXPECTED_ENTITIES["expected_device"])
|
device_entries = dr.async_entries_for_config_entry(
|
||||||
|
device_registry, config_entry.entry_id
|
||||||
|
)
|
||||||
|
assert device_entries == snapshot
|
||||||
|
|
||||||
expected_entities = EXPECTED_ENTITIES[Platform.BINARY_SENSOR]
|
entity_entries = er.async_entries_for_config_entry(
|
||||||
assert len(entity_registry.entities) == len(expected_entities)
|
entity_registry, config_entry.entry_id
|
||||||
|
)
|
||||||
|
assert entity_entries == snapshot
|
||||||
|
|
||||||
check_entities(hass, entity_registry, expected_entities)
|
for entity in entity_entries:
|
||||||
|
assert hass.states.get(entity.entity_id) == snapshot(name=entity.entity_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user