Refactor SnapshotAssertion is SFR Box (#90775)

This commit is contained in:
epenet 2023-04-22 17:20:27 +02:00 committed by GitHub
parent ee23d79a00
commit b568dd3060
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 304 additions and 316 deletions

View File

@ -88,31 +88,31 @@
}), }),
]) ])
# --- # ---
# name: test_binary_sensors[adsl][binary_sensor.sfr_box_dsl_status] # name: test_binary_sensors[adsl].2
StateSnapshot({ list([
'attributes': ReadOnlyDict({ StateSnapshot({
'device_class': 'connectivity', 'attributes': ReadOnlyDict({
'friendly_name': 'SFR Box DSL status', 'device_class': 'connectivity',
'friendly_name': 'SFR Box WAN status',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.sfr_box_wan_status',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'on',
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'binary_sensor.sfr_box_dsl_status', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'device_class': 'connectivity',
'last_updated': <ANY>, 'friendly_name': 'SFR Box DSL status',
'state': 'on', }),
}) 'context': <ANY>,
# --- 'entity_id': 'binary_sensor.sfr_box_dsl_status',
# name: test_binary_sensors[adsl][binary_sensor.sfr_box_wan_status] 'last_changed': <ANY>,
StateSnapshot({ 'last_updated': <ANY>,
'attributes': ReadOnlyDict({ 'state': 'on',
'device_class': 'connectivity',
'friendly_name': 'SFR Box WAN status',
}), }),
'context': <ANY>, ])
'entity_id': 'binary_sensor.sfr_box_wan_status',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# --- # ---
# name: test_binary_sensors[ftth] # name: test_binary_sensors[ftth]
list([ list([
@ -203,29 +203,29 @@
}), }),
]) ])
# --- # ---
# name: test_binary_sensors[ftth][binary_sensor.sfr_box_ftth_status] # name: test_binary_sensors[ftth].2
StateSnapshot({ list([
'attributes': ReadOnlyDict({ StateSnapshot({
'device_class': 'connectivity', 'attributes': ReadOnlyDict({
'friendly_name': 'SFR Box FTTH status', 'device_class': 'connectivity',
'friendly_name': 'SFR Box WAN status',
}),
'context': <ANY>,
'entity_id': 'binary_sensor.sfr_box_wan_status',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'on',
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'binary_sensor.sfr_box_ftth_status', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'device_class': 'connectivity',
'last_updated': <ANY>, 'friendly_name': 'SFR Box FTTH status',
'state': 'off', }),
}) 'context': <ANY>,
# --- 'entity_id': 'binary_sensor.sfr_box_ftth_status',
# name: test_binary_sensors[ftth][binary_sensor.sfr_box_wan_status] 'last_changed': <ANY>,
StateSnapshot({ 'last_updated': <ANY>,
'attributes': ReadOnlyDict({ 'state': 'off',
'device_class': 'connectivity',
'friendly_name': 'SFR Box WAN status',
}), }),
'context': <ANY>, ])
'entity_id': 'binary_sensor.sfr_box_wan_status',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'on',
})
# --- # ---

View File

@ -60,16 +60,18 @@
}), }),
]) ])
# --- # ---
# name: test_buttons[button.sfr_box_restart] # name: test_buttons.2
StateSnapshot({ list([
'attributes': ReadOnlyDict({ StateSnapshot({
'device_class': 'restart', 'attributes': ReadOnlyDict({
'friendly_name': 'SFR Box Restart', 'device_class': 'restart',
'friendly_name': 'SFR Box Restart',
}),
'context': <ANY>,
'entity_id': 'button.sfr_box_restart',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
}), }),
'context': <ANY>, ])
'entity_id': 'button.sfr_box_restart',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'unknown',
})
# --- # ---

View File

@ -1,30 +1,32 @@
# serializer version: 1 # serializer version: 1
# name: test_sensors # name: test_sensors
DeviceRegistryEntrySnapshot({ list([
'area_id': None, DeviceRegistryEntrySnapshot({
'config_entries': <ANY>, 'area_id': None,
'configuration_url': 'http://192.168.0.1', 'config_entries': <ANY>,
'connections': set({ '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,
}), }),
'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 # name: test_sensors.1
list([ list([
@ -499,242 +501,216 @@
}), }),
]) ])
# --- # ---
# name: test_sensors[sensor.sfr_box_dsl_attenuation_down] # name: test_sensors.2
StateSnapshot({ list([
'attributes': ReadOnlyDict({ StateSnapshot({
'device_class': 'signal_strength', 'attributes': ReadOnlyDict({
'friendly_name': 'SFR Box DSL attenuation down', 'device_class': 'enum',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>, 'friendly_name': 'SFR Box Network infrastructure',
'unit_of_measurement': 'dB', 'options': list([
'adsl',
'ftth',
'gprs',
'unknown',
]),
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_network_infrastructure',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'adsl',
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'sensor.sfr_box_dsl_attenuation_down', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'device_class': 'voltage',
'last_updated': <ANY>, 'friendly_name': 'SFR Box Voltage',
'state': '28.5', 'unit_of_measurement': <UnitOfElectricPotential.MILLIVOLT: 'mV'>,
}) }),
# --- 'context': <ANY>,
# name: test_sensors[sensor.sfr_box_dsl_attenuation_up] 'entity_id': 'sensor.sfr_box_voltage',
StateSnapshot({ 'last_changed': <ANY>,
'attributes': ReadOnlyDict({ 'last_updated': <ANY>,
'device_class': 'signal_strength', 'state': '12251',
'friendly_name': 'SFR Box DSL attenuation up',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'dB',
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'sensor.sfr_box_dsl_attenuation_up', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'device_class': 'temperature',
'last_updated': <ANY>, 'friendly_name': 'SFR Box Temperature',
'state': '20.8', 'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
}) }),
# --- 'context': <ANY>,
# name: test_sensors[sensor.sfr_box_dsl_counter] 'entity_id': 'sensor.sfr_box_temperature',
StateSnapshot({ 'last_changed': <ANY>,
'attributes': ReadOnlyDict({ 'last_updated': <ANY>,
'friendly_name': 'SFR Box DSL counter', 'state': '27.56',
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'sensor.sfr_box_dsl_counter', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'device_class': 'enum',
'last_updated': <ANY>, 'friendly_name': 'SFR Box WAN mode',
'state': '16', 'options': list([
}) 'adsl_ppp',
# --- 'adsl_routed',
# name: test_sensors[sensor.sfr_box_dsl_crc] 'ftth_routed',
StateSnapshot({ 'grps_ppp',
'attributes': ReadOnlyDict({ 'unknown',
'friendly_name': 'SFR Box DSL CRC', ]),
}),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_wan_mode',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'adsl_routed',
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'sensor.sfr_box_dsl_crc', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'friendly_name': 'SFR Box DSL line mode',
'last_updated': <ANY>, }),
'state': '0', 'context': <ANY>,
}) 'entity_id': 'sensor.sfr_box_dsl_line_mode',
# --- 'last_changed': <ANY>,
# name: test_sensors[sensor.sfr_box_dsl_line_mode] 'last_updated': <ANY>,
StateSnapshot({ 'state': 'ADSL2+',
'attributes': ReadOnlyDict({
'friendly_name': 'SFR Box DSL line mode',
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'sensor.sfr_box_dsl_line_mode', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'friendly_name': 'SFR Box DSL counter',
'last_updated': <ANY>, }),
'state': 'ADSL2+', 'context': <ANY>,
}) 'entity_id': 'sensor.sfr_box_dsl_counter',
# --- 'last_changed': <ANY>,
# name: test_sensors[sensor.sfr_box_dsl_line_status] 'last_updated': <ANY>,
StateSnapshot({ 'state': '16',
'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>, StateSnapshot({
'entity_id': 'sensor.sfr_box_dsl_line_status', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'friendly_name': 'SFR Box DSL CRC',
'last_updated': <ANY>, }),
'state': 'no_defect', 'context': <ANY>,
}) 'entity_id': 'sensor.sfr_box_dsl_crc',
# --- 'last_changed': <ANY>,
# name: test_sensors[sensor.sfr_box_dsl_noise_down] 'last_updated': <ANY>,
StateSnapshot({ 'state': '0',
'attributes': ReadOnlyDict({
'device_class': 'signal_strength',
'friendly_name': 'SFR Box DSL noise down',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'dB',
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'sensor.sfr_box_dsl_noise_down', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'device_class': 'signal_strength',
'last_updated': <ANY>, 'friendly_name': 'SFR Box DSL noise down',
'state': '5.8', 'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}) 'unit_of_measurement': 'dB',
# --- }),
# name: test_sensors[sensor.sfr_box_dsl_noise_up] 'context': <ANY>,
StateSnapshot({ 'entity_id': 'sensor.sfr_box_dsl_noise_down',
'attributes': ReadOnlyDict({ 'last_changed': <ANY>,
'device_class': 'signal_strength', 'last_updated': <ANY>,
'friendly_name': 'SFR Box DSL noise up', 'state': '5.8',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': 'dB',
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'sensor.sfr_box_dsl_noise_up', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'device_class': 'signal_strength',
'last_updated': <ANY>, 'friendly_name': 'SFR Box DSL noise up',
'state': '6.0', 'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}) 'unit_of_measurement': 'dB',
# --- }),
# name: test_sensors[sensor.sfr_box_dsl_rate_down] 'context': <ANY>,
StateSnapshot({ 'entity_id': 'sensor.sfr_box_dsl_noise_up',
'attributes': ReadOnlyDict({ 'last_changed': <ANY>,
'device_class': 'data_rate', 'last_updated': <ANY>,
'friendly_name': 'SFR Box DSL rate down', 'state': '6.0',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfDataRate.KILOBITS_PER_SECOND: 'kbit/s'>,
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'sensor.sfr_box_dsl_rate_down', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'device_class': 'signal_strength',
'last_updated': <ANY>, 'friendly_name': 'SFR Box DSL attenuation down',
'state': '5549', 'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}) 'unit_of_measurement': 'dB',
# --- }),
# name: test_sensors[sensor.sfr_box_dsl_rate_up] 'context': <ANY>,
StateSnapshot({ 'entity_id': 'sensor.sfr_box_dsl_attenuation_down',
'attributes': ReadOnlyDict({ 'last_changed': <ANY>,
'device_class': 'data_rate', 'last_updated': <ANY>,
'friendly_name': 'SFR Box DSL rate up', 'state': '28.5',
'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
'unit_of_measurement': <UnitOfDataRate.KILOBITS_PER_SECOND: 'kbit/s'>,
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'sensor.sfr_box_dsl_rate_up', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'device_class': 'signal_strength',
'last_updated': <ANY>, 'friendly_name': 'SFR Box DSL attenuation up',
'state': '187', 'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}) 'unit_of_measurement': 'dB',
# --- }),
# name: test_sensors[sensor.sfr_box_dsl_training] 'context': <ANY>,
StateSnapshot({ 'entity_id': 'sensor.sfr_box_dsl_attenuation_up',
'attributes': ReadOnlyDict({ 'last_changed': <ANY>,
'device_class': 'enum', 'last_updated': <ANY>,
'friendly_name': 'SFR Box DSL training', 'state': '20.8',
'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>, StateSnapshot({
'entity_id': 'sensor.sfr_box_dsl_training', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'device_class': 'data_rate',
'last_updated': <ANY>, 'friendly_name': 'SFR Box DSL rate down',
'state': 'showtime', 'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}) 'unit_of_measurement': <UnitOfDataRate.KILOBITS_PER_SECOND: 'kbit/s'>,
# --- }),
# name: test_sensors[sensor.sfr_box_network_infrastructure] 'context': <ANY>,
StateSnapshot({ 'entity_id': 'sensor.sfr_box_dsl_rate_down',
'attributes': ReadOnlyDict({ 'last_changed': <ANY>,
'device_class': 'enum', 'last_updated': <ANY>,
'friendly_name': 'SFR Box Network infrastructure', 'state': '5549',
'options': list([
'adsl',
'ftth',
'gprs',
'unknown',
]),
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'sensor.sfr_box_network_infrastructure', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'device_class': 'data_rate',
'last_updated': <ANY>, 'friendly_name': 'SFR Box DSL rate up',
'state': 'adsl', 'state_class': <SensorStateClass.MEASUREMENT: 'measurement'>,
}) 'unit_of_measurement': <UnitOfDataRate.KILOBITS_PER_SECOND: 'kbit/s'>,
# --- }),
# name: test_sensors[sensor.sfr_box_temperature] 'context': <ANY>,
StateSnapshot({ 'entity_id': 'sensor.sfr_box_dsl_rate_up',
'attributes': ReadOnlyDict({ 'last_changed': <ANY>,
'device_class': 'temperature', 'last_updated': <ANY>,
'friendly_name': 'SFR Box Temperature', 'state': '187',
'unit_of_measurement': <UnitOfTemperature.CELSIUS: '°C'>,
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'sensor.sfr_box_temperature', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'device_class': 'enum',
'last_updated': <ANY>, 'friendly_name': 'SFR Box DSL line status',
'state': '27.56', 'options': list([
}) 'no_defect',
# --- 'of_frame',
# name: test_sensors[sensor.sfr_box_voltage] 'loss_of_signal',
StateSnapshot({ 'loss_of_power',
'attributes': ReadOnlyDict({ 'loss_of_signal_quality',
'device_class': 'voltage', 'unknown',
'friendly_name': 'SFR Box Voltage', ]),
'unit_of_measurement': <UnitOfElectricPotential.MILLIVOLT: 'mV'>, }),
'context': <ANY>,
'entity_id': 'sensor.sfr_box_dsl_line_status',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'no_defect',
}), }),
'context': <ANY>, StateSnapshot({
'entity_id': 'sensor.sfr_box_voltage', 'attributes': ReadOnlyDict({
'last_changed': <ANY>, 'device_class': 'enum',
'last_updated': <ANY>, 'friendly_name': 'SFR Box DSL training',
'state': '12251', 'options': list([
}) 'idle',
# --- 'g_994_training',
# name: test_sensors[sensor.sfr_box_wan_mode] 'g_992_started',
StateSnapshot({ 'g_922_channel_analysis',
'attributes': ReadOnlyDict({ 'g_992_message_exchange',
'device_class': 'enum', 'g_993_started',
'friendly_name': 'SFR Box WAN mode', 'g_993_channel_analysis',
'options': list([ 'g_993_message_exchange',
'adsl_ppp', 'showtime',
'adsl_routed', 'unknown',
'ftth_routed', ]),
'grps_ppp', }),
'unknown', 'context': <ANY>,
]), 'entity_id': 'sensor.sfr_box_dsl_training',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'showtime',
}), }),
'context': <ANY>, ])
'entity_id': 'sensor.sfr_box_wan_mode',
'last_changed': <ANY>,
'last_updated': <ANY>,
'state': 'adsl_routed',
})
# --- # ---

View File

@ -38,15 +38,18 @@ async def test_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()
# Ensure devices are correctly registered
device_entries = dr.async_entries_for_config_entry( device_entries = dr.async_entries_for_config_entry(
device_registry, config_entry.entry_id device_registry, config_entry.entry_id
) )
assert device_entries == snapshot assert device_entries == snapshot
# Ensure entities are correctly registered
entity_entries = er.async_entries_for_config_entry( entity_entries = er.async_entries_for_config_entry(
entity_registry, config_entry.entry_id entity_registry, config_entry.entry_id
) )
assert entity_entries == snapshot assert entity_entries == snapshot
for entity in entity_entries: # Ensure entity states are correct
assert hass.states.get(entity.entity_id) == snapshot(name=entity.entity_id) states = [hass.states.get(ent.entity_id) for ent in entity_entries]
assert states == snapshot

View File

@ -36,18 +36,21 @@ async def test_buttons(
await hass.config_entries.async_setup(config_entry_with_auth.entry_id) await hass.config_entries.async_setup(config_entry_with_auth.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
# Ensure devices are correctly registered
device_entries = dr.async_entries_for_config_entry( device_entries = dr.async_entries_for_config_entry(
device_registry, config_entry_with_auth.entry_id device_registry, config_entry_with_auth.entry_id
) )
assert device_entries == snapshot assert device_entries == snapshot
# Ensure entities are correctly registered
entity_entries = er.async_entries_for_config_entry( entity_entries = er.async_entries_for_config_entry(
entity_registry, config_entry_with_auth.entry_id entity_registry, config_entry_with_auth.entry_id
) )
assert entity_entries == snapshot assert entity_entries == snapshot
for entity in entity_entries: # Ensure entity states are correct
assert hass.states.get(entity.entity_id) == snapshot(name=entity.entity_id) states = [hass.states.get(ent.entity_id) for ent in entity_entries]
assert states == snapshot
async def test_reboot(hass: HomeAssistant, config_entry_with_auth: ConfigEntry) -> None: async def test_reboot(hass: HomeAssistant, config_entry_with_auth: ConfigEntry) -> None:

View File

@ -5,7 +5,6 @@ from unittest.mock import patch
import pytest import pytest
from syrupy.assertion import SnapshotAssertion from syrupy.assertion import SnapshotAssertion
from homeassistant.components.sfr_box import DOMAIN
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
@ -32,19 +31,24 @@ async def test_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()
device_entry = device_registry.async_get_device({(DOMAIN, "e4:5d:51:00:11:22")}) # Ensure devices are correctly registered
assert device_entry == snapshot device_entries = dr.async_entries_for_config_entry(
device_registry, config_entry.entry_id
)
assert device_entries == snapshot
# Ensure entities are correctly registered
entity_entries = er.async_entries_for_config_entry( entity_entries = er.async_entries_for_config_entry(
entity_registry, config_entry.entry_id entity_registry, config_entry.entry_id
) )
assert entity_entries == snapshot assert entity_entries == snapshot
for entity in entity_entries: # Some entities are disabled, enable them and reload before checking states
entity_registry.async_update_entity(entity.entity_id, **{"disabled_by": None}) for ent in entity_entries:
entity_registry.async_update_entity(ent.entity_id, **{"disabled_by": None})
await hass.config_entries.async_reload(config_entry.entry_id) await hass.config_entries.async_reload(config_entry.entry_id)
await hass.async_block_till_done() await hass.async_block_till_done()
for entity in entity_entries: # Ensure entity states are correct
assert hass.states.get(entity.entity_id) == snapshot(name=entity.entity_id) states = [hass.states.get(ent.entity_id) for ent in entity_entries]
assert states == snapshot