Use SnapshotAssertion in SFR sensor tests (#89619)

* Use SnapshotAssertion in SFR sensor tests

* Name snapshots

* Cleanup const.py

* Remove name from snapshot
pull/89624/head
epenet 2023-03-13 10:45:59 +01:00 committed by GitHub
parent fd5c56fc7d
commit 5e73ad9cb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 700 additions and 164 deletions

View File

@ -1,12 +1,7 @@
"""Constants for SFR Box tests."""
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.button import ButtonDeviceClass
from homeassistant.components.sensor import (
ATTR_OPTIONS,
ATTR_STATE_CLASS,
SensorDeviceClass,
SensorStateClass,
)
from homeassistant.components.sensor import ATTR_OPTIONS, ATTR_STATE_CLASS
from homeassistant.components.sfr_box.const import DOMAIN
from homeassistant.const import (
ATTR_DEVICE_CLASS,
@ -17,13 +12,9 @@ from homeassistant.const import (
ATTR_STATE,
ATTR_SW_VERSION,
ATTR_UNIT_OF_MEASUREMENT,
SIGNAL_STRENGTH_DECIBELS,
STATE_ON,
STATE_UNKNOWN,
Platform,
UnitOfDataRate,
UnitOfElectricPotential,
UnitOfTemperature,
)
ATTR_DEFAULT_DISABLED = "default_disabled"
@ -58,134 +49,4 @@ EXPECTED_ENTITIES = {
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_system_reboot",
},
],
Platform.SENSOR: [
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.ENUM,
ATTR_ENTITY_ID: "sensor.sfr_box_network_infrastructure",
ATTR_OPTIONS: ["adsl", "ftth", "gprs", "unknown"],
ATTR_STATE: "adsl",
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_system_net_infra",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
ATTR_ENTITY_ID: "sensor.sfr_box_temperature",
ATTR_STATE: "27.56",
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_system_temperature",
ATTR_UNIT_OF_MEASUREMENT: UnitOfTemperature.CELSIUS,
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.VOLTAGE,
ATTR_ENTITY_ID: "sensor.sfr_box_voltage",
ATTR_STATE: "12251",
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_system_alimvoltage",
ATTR_UNIT_OF_MEASUREMENT: UnitOfElectricPotential.MILLIVOLT,
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "sensor.sfr_box_dsl_line_mode",
ATTR_STATE: "ADSL2+",
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_dsl_linemode",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "sensor.sfr_box_dsl_counter",
ATTR_STATE: "16",
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_dsl_counter",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_ENTITY_ID: "sensor.sfr_box_dsl_crc",
ATTR_STATE: "0",
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_dsl_crc",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.SIGNAL_STRENGTH,
ATTR_ENTITY_ID: "sensor.sfr_box_dsl_noise_down",
ATTR_STATE: "5.8",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_dsl_noise_down",
ATTR_UNIT_OF_MEASUREMENT: SIGNAL_STRENGTH_DECIBELS,
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.SIGNAL_STRENGTH,
ATTR_ENTITY_ID: "sensor.sfr_box_dsl_noise_up",
ATTR_STATE: "6.0",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_dsl_noise_up",
ATTR_UNIT_OF_MEASUREMENT: SIGNAL_STRENGTH_DECIBELS,
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.SIGNAL_STRENGTH,
ATTR_ENTITY_ID: "sensor.sfr_box_dsl_attenuation_down",
ATTR_STATE: "28.5",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_dsl_attenuation_down",
ATTR_UNIT_OF_MEASUREMENT: SIGNAL_STRENGTH_DECIBELS,
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.SIGNAL_STRENGTH,
ATTR_ENTITY_ID: "sensor.sfr_box_dsl_attenuation_up",
ATTR_STATE: "20.8",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_dsl_attenuation_up",
ATTR_UNIT_OF_MEASUREMENT: SIGNAL_STRENGTH_DECIBELS,
},
{
ATTR_DEVICE_CLASS: SensorDeviceClass.DATA_RATE,
ATTR_ENTITY_ID: "sensor.sfr_box_dsl_rate_down",
ATTR_STATE: "5549",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_dsl_rate_down",
ATTR_UNIT_OF_MEASUREMENT: UnitOfDataRate.KILOBITS_PER_SECOND,
},
{
ATTR_DEVICE_CLASS: SensorDeviceClass.DATA_RATE,
ATTR_ENTITY_ID: "sensor.sfr_box_dsl_rate_up",
ATTR_STATE: "187",
ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_dsl_rate_up",
ATTR_UNIT_OF_MEASUREMENT: UnitOfDataRate.KILOBITS_PER_SECOND,
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.ENUM,
ATTR_ENTITY_ID: "sensor.sfr_box_dsl_line_status",
ATTR_OPTIONS: [
"no_defect",
"of_frame",
"loss_of_signal",
"loss_of_power",
"loss_of_signal_quality",
"unknown",
],
ATTR_STATE: "no_defect",
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_dsl_line_status",
},
{
ATTR_DEFAULT_DISABLED: True,
ATTR_DEVICE_CLASS: SensorDeviceClass.ENUM,
ATTR_ENTITY_ID: "sensor.sfr_box_dsl_training",
ATTR_OPTIONS: [
"idle",
"g_994_training",
"g_992_started",
"g_922_channel_analysis",
"g_992_message_exchange",
"g_993_started",
"g_993_channel_analysis",
"g_993_message_exchange",
"showtime",
"unknown",
],
ATTR_STATE: "showtime",
ATTR_UNIQUE_ID: "e4:5d:51:00:11:22_dsl_training",
},
],
}

View File

@ -0,0 +1,684 @@
# serializer version: 1
# name: test_sensors
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_sensors.1
list([
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'options': list([
'adsl',
'ftth',
'gprs',
'unknown',
]),
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.sfr_box_network_infrastructure',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.ENUM: 'enum'>,
'original_icon': None,
'original_name': 'Network infrastructure',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': 'net_infra',
'unique_id': 'e4:5d:51:00:11:22_system_net_infra',
'unit_of_measurement': None,
}),
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.sfr_box_voltage',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.VOLTAGE: 'voltage'>,
'original_icon': None,
'original_name': 'Voltage',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': None,
'unique_id': 'e4:5d:51:00:11:22_system_alimvoltage',
'unit_of_measurement': <UnitOfElectricPotential.MILLIVOLT: 'mV'>,
}),
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.sfr_box_temperature',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.TEMPERATURE: 'temperature'>,
'original_icon': None,
'original_name': 'Temperature',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': None,
'unique_id': 'e4:5d:51:00:11:22_system_temperature',
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
}),
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.sfr_box_dsl_line_mode',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'DSL line mode',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': None,
'unique_id': 'e4:5d:51:00:11:22_dsl_linemode',
'unit_of_measurement': None,
}),
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.sfr_box_dsl_counter',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'DSL counter',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': None,
'unique_id': 'e4:5d:51:00:11:22_dsl_counter',
'unit_of_measurement': None,
}),
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': None,
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.sfr_box_dsl_crc',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': None,
'original_icon': None,
'original_name': 'DSL CRC',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': None,
'unique_id': 'e4:5d:51:00:11:22_dsl_crc',
'unit_of_measurement': None,
}),
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.sfr_box_dsl_noise_down',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.SIGNAL_STRENGTH: 'signal_strength'>,
'original_icon': None,
'original_name': 'DSL noise down',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': None,
'unique_id': 'e4:5d:51:00:11:22_dsl_noise_down',
'unit_of_measurement': 'dB',
}),
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.sfr_box_dsl_noise_up',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.SIGNAL_STRENGTH: 'signal_strength'>,
'original_icon': None,
'original_name': 'DSL noise up',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': None,
'unique_id': 'e4:5d:51:00:11:22_dsl_noise_up',
'unit_of_measurement': 'dB',
}),
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.sfr_box_dsl_attenuation_down',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.SIGNAL_STRENGTH: 'signal_strength'>,
'original_icon': None,
'original_name': 'DSL attenuation down',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': None,
'unique_id': 'e4:5d:51:00:11:22_dsl_attenuation_down',
'unit_of_measurement': 'dB',
}),
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.sfr_box_dsl_attenuation_up',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.SIGNAL_STRENGTH: 'signal_strength'>,
'original_icon': None,
'original_name': 'DSL attenuation up',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': None,
'unique_id': 'e4:5d:51:00:11:22_dsl_attenuation_up',
'unit_of_measurement': 'dB',
}),
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.sfr_box_dsl_rate_down',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.DATA_RATE: 'data_rate'>,
'original_icon': None,
'original_name': 'DSL rate down',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': None,
'unique_id': 'e4:5d:51:00:11:22_dsl_rate_down',
'unit_of_measurement': <UnitOfDataRate.KILOBITS_PER_SECOND: 'kbit/s'>,
}),
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': None,
'domain': 'sensor',
'entity_category': None,
'entity_id': 'sensor.sfr_box_dsl_rate_up',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.DATA_RATE: 'data_rate'>,
'original_icon': None,
'original_name': 'DSL rate up',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': None,
'unique_id': 'e4:5d:51:00:11:22_dsl_rate_up',
'unit_of_measurement': <UnitOfDataRate.KILOBITS_PER_SECOND: 'kbit/s'>,
}),
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'options': list([
'no_defect',
'of_frame',
'loss_of_signal',
'loss_of_power',
'loss_of_signal_quality',
'unknown',
]),
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.sfr_box_dsl_line_status',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.ENUM: 'enum'>,
'original_icon': None,
'original_name': 'DSL line status',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': 'line_status',
'unique_id': 'e4:5d:51:00:11:22_dsl_line_status',
'unit_of_measurement': None,
}),
EntityRegistryEntrySnapshot({
'aliases': set({
}),
'area_id': None,
'capabilities': dict({
'options': list([
'idle',
'g_994_training',
'g_992_started',
'g_922_channel_analysis',
'g_992_message_exchange',
'g_993_started',
'g_993_channel_analysis',
'g_993_message_exchange',
'showtime',
'unknown',
]),
}),
'config_entry_id': <ANY>,
'device_class': None,
'device_id': <ANY>,
'disabled_by': <RegistryEntryDisabler.INTEGRATION: 'integration'>,
'domain': 'sensor',
'entity_category': <EntityCategory.DIAGNOSTIC: 'diagnostic'>,
'entity_id': 'sensor.sfr_box_dsl_training',
'has_entity_name': True,
'hidden_by': None,
'icon': None,
'id': <ANY>,
'name': None,
'options': dict({
}),
'original_device_class': <SensorDeviceClass.ENUM: 'enum'>,
'original_icon': None,
'original_name': 'DSL training',
'platform': 'sfr_box',
'supported_features': 0,
'translation_key': 'training',
'unique_id': 'e4:5d:51:00:11:22_dsl_training',
'unit_of_measurement': None,
}),
])
# ---
# name: test_sensors[sensor.sfr_box_dsl_attenuation_down]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'signal_strength',
'friendly_name': 'SFR Box DSL attenuation down',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'dB',
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_dsl_attenuation_down',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '28.5',
})
# ---
# name: test_sensors[sensor.sfr_box_dsl_attenuation_up]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'signal_strength',
'friendly_name': 'SFR Box DSL attenuation up',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'dB',
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_dsl_attenuation_up',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '20.8',
})
# ---
# name: test_sensors[sensor.sfr_box_dsl_counter]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'SFR Box DSL counter',
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_dsl_counter',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '16',
})
# ---
# name: test_sensors[sensor.sfr_box_dsl_crc]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'SFR Box DSL CRC',
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_dsl_crc',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '0',
})
# ---
# name: test_sensors[sensor.sfr_box_dsl_line_mode]
StateSnapshot({
'attributes': ReadOnlyDict({
'friendly_name': 'SFR Box DSL line mode',
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_dsl_line_mode',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'ADSL2+',
})
# ---
# name: test_sensors[sensor.sfr_box_dsl_line_status]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'enum',
'friendly_name': 'SFR Box DSL line status',
'options': list([
'no_defect',
'of_frame',
'loss_of_signal',
'loss_of_power',
'loss_of_signal_quality',
'unknown',
]),
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_dsl_line_status',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'no_defect',
})
# ---
# name: test_sensors[sensor.sfr_box_dsl_noise_down]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'signal_strength',
'friendly_name': 'SFR Box DSL noise down',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'dB',
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_dsl_noise_down',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '5.8',
})
# ---
# name: test_sensors[sensor.sfr_box_dsl_noise_up]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'signal_strength',
'friendly_name': 'SFR Box DSL noise up',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'dB',
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_dsl_noise_up',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '6.0',
})
# ---
# name: test_sensors[sensor.sfr_box_dsl_rate_down]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'data_rate',
'friendly_name': 'SFR Box DSL rate down',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfDataRate.KILOBITS_PER_SECOND: 'kbit/s'>,
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_dsl_rate_down',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '5549',
})
# ---
# name: test_sensors[sensor.sfr_box_dsl_rate_up]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'data_rate',
'friendly_name': 'SFR Box DSL rate up',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfDataRate.KILOBITS_PER_SECOND: 'kbit/s'>,
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_dsl_rate_up',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '187',
})
# ---
# name: test_sensors[sensor.sfr_box_dsl_training]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'enum',
'friendly_name': 'SFR Box DSL training',
'options': list([
'idle',
'g_994_training',
'g_992_started',
'g_922_channel_analysis',
'g_992_message_exchange',
'g_993_started',
'g_993_channel_analysis',
'g_993_message_exchange',
'showtime',
'unknown',
]),
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_dsl_training',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'showtime',
})
# ---
# name: test_sensors[sensor.sfr_box_network_infrastructure]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'enum',
'friendly_name': 'SFR Box Network infrastructure',
'options': list([
'adsl',
'ftth',
'gprs',
'unknown',
]),
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_network_infrastructure',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'adsl',
})
# ---
# name: test_sensors[sensor.sfr_box_temperature]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'temperature',
'friendly_name': 'SFR Box Temperature',
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_temperature',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '27.56',
})
# ---
# name: test_sensors[sensor.sfr_box_voltage]
StateSnapshot({
'attributes': ReadOnlyDict({
'device_class': 'voltage',
'friendly_name': 'SFR Box Voltage',
'unit_of_measurement': <UnitOfElectricPotential.MILLIVOLT: 'mV'>,
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_voltage',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': '12251',
})
# ---

View File

@ -1,18 +1,16 @@
"""Test the SFR Box sensors."""
from collections.abc import Generator
from types import MappingProxyType
from unittest.mock import patch
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.sfr_box import DOMAIN
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ATTR_ENTITY_ID, Platform
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.helpers import device_registry as dr, entity_registry as er
from . import check_device_registry, check_entities
from .const import ATTR_DEFAULT_DISABLED, EXPECTED_ENTITIES
pytestmark = pytest.mark.usefixtures("system_get_info", "dsl_get_info")
@ -23,37 +21,30 @@ def override_platforms() -> Generator[None, None, None]:
yield
def _check_and_enable_disabled_entities(
entity_registry: er.EntityRegistry, expected_entities: MappingProxyType
) -> None:
"""Ensure that the expected_entities are correctly disabled."""
for expected_entity in expected_entities:
if expected_entity.get(ATTR_DEFAULT_DISABLED):
entity_id = expected_entity[ATTR_ENTITY_ID]
registry_entry = entity_registry.entities.get(entity_id)
assert registry_entry, f"Registry entry not found for {entity_id}"
assert registry_entry.disabled
assert registry_entry.disabled_by is er.RegistryEntryDisabler.INTEGRATION
entity_registry.async_update_entity(entity_id, **{"disabled_by": None})
async def test_sensors(
hass: HomeAssistant,
config_entry: ConfigEntry,
device_registry: dr.DeviceRegistry,
entity_registry: er.EntityRegistry,
snapshot: SnapshotAssertion,
) -> None:
"""Test for SFR Box sensors."""
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
check_device_registry(device_registry, EXPECTED_ENTITIES["expected_device"])
device_entry = device_registry.async_get_device({(DOMAIN, "e4:5d:51:00:11:22")})
assert device_entry == snapshot
expected_entities = EXPECTED_ENTITIES[Platform.SENSOR]
assert len(entity_registry.entities) == len(expected_entities)
entity_entries = er.async_entries_for_config_entry(
entity_registry, config_entry.entry_id
)
assert entity_entries == snapshot
for entity in entity_entries:
entity_registry.async_update_entity(entity.entity_id, **{"disabled_by": None})
_check_and_enable_disabled_entities(entity_registry, expected_entities)
await hass.config_entries.async_reload(config_entry.entry_id)
await hass.async_block_till_done()
check_entities(hass, entity_registry, expected_entities)
for entity in entity_entries:
assert hass.states.get(entity.entity_id) == snapshot(name=entity.entity_id)