From 91da7516d0500c4b1f98edcc6e45f1f1c7c04f1b Mon Sep 17 00:00:00 2001 From: Guido Schmitz Date: Mon, 22 May 2023 18:16:57 +0200 Subject: [PATCH] Use snapshots in devolo_home_control tests (#93202) --- .../devolo_home_control/__init__.py | 5 +- .../snapshots/test_binary_sensor.ambr | 129 ++++++++++++ .../snapshots/test_climate.ambr | 59 ++++++ .../snapshots/test_cover.ambr | 46 +++++ .../snapshots/test_diagnostics.ambr | 53 +++++ .../snapshots/test_light.ambr | 105 ++++++++++ .../snapshots/test_sensor.ambr | 189 ++++++++++++++++++ .../snapshots/test_siren.ambr | 151 ++++++++++++++ .../snapshots/test_switch.ambr | 43 ++++ .../devolo_home_control/test_binary_sensor.py | 33 ++- .../devolo_home_control/test_climate.py | 20 +- .../devolo_home_control/test_cover.py | 20 +- .../devolo_home_control/test_diagnostics.py | 44 +--- .../devolo_home_control/test_light.py | 38 ++-- .../devolo_home_control/test_sensor.py | 64 ++---- .../devolo_home_control/test_siren.py | 33 +-- .../devolo_home_control/test_switch.py | 12 +- 17 files changed, 874 insertions(+), 170 deletions(-) create mode 100644 tests/components/devolo_home_control/snapshots/test_binary_sensor.ambr create mode 100644 tests/components/devolo_home_control/snapshots/test_climate.ambr create mode 100644 tests/components/devolo_home_control/snapshots/test_cover.ambr create mode 100644 tests/components/devolo_home_control/snapshots/test_diagnostics.ambr create mode 100644 tests/components/devolo_home_control/snapshots/test_light.ambr create mode 100644 tests/components/devolo_home_control/snapshots/test_sensor.ambr create mode 100644 tests/components/devolo_home_control/snapshots/test_siren.ambr create mode 100644 tests/components/devolo_home_control/snapshots/test_switch.ambr diff --git a/tests/components/devolo_home_control/__init__.py b/tests/components/devolo_home_control/__init__.py index 5ffc0781c84..a7217b0d530 100644 --- a/tests/components/devolo_home_control/__init__.py +++ b/tests/components/devolo_home_control/__init__.py @@ -1,5 +1,4 @@ """Tests for the devolo_home_control integration.""" - from homeassistant.components.devolo_home_control.const import DOMAIN from homeassistant.core import HomeAssistant @@ -13,7 +12,9 @@ def configure_integration(hass: HomeAssistant) -> MockConfigEntry: "password": "test-password", "mydevolo_url": "https://test_mydevolo_url.test", } - entry = MockConfigEntry(domain=DOMAIN, data=config, unique_id="123456") + entry = MockConfigEntry( + domain=DOMAIN, data=config, entry_id="123456", unique_id="123456" + ) entry.add_to_hass(hass) return entry diff --git a/tests/components/devolo_home_control/snapshots/test_binary_sensor.ambr b/tests/components/devolo_home_control/snapshots/test_binary_sensor.ambr new file mode 100644 index 00000000000..0c86cc94321 --- /dev/null +++ b/tests/components/devolo_home_control/snapshots/test_binary_sensor.ambr @@ -0,0 +1,129 @@ +# serializer version: 1 +# name: test_binary_sensor + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'door', + 'friendly_name': 'Test Door', + }), + 'context': , + 'entity_id': 'binary_sensor.test_door', + 'last_changed': , + 'last_updated': , + 'state': 'off', + }) +# --- +# name: test_binary_sensor.1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'binary_sensor', + 'entity_category': None, + 'entity_id': 'binary_sensor.test_door', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Door', + 'platform': 'devolo_home_control', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'Test', + 'unit_of_measurement': None, + }) +# --- +# name: test_binary_sensor.2 + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'safety', + 'friendly_name': 'Test Overload', + }), + 'context': , + 'entity_id': 'binary_sensor.test_overload', + 'last_changed': , + 'last_updated': , + 'state': 'off', + }) +# --- +# name: test_binary_sensor.3 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'binary_sensor', + 'entity_category': , + 'entity_id': 'binary_sensor.test_overload', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Overload', + 'platform': 'devolo_home_control', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'Overload', + 'unit_of_measurement': None, + }) +# --- +# name: test_remote_control + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Test Button 1', + }), + 'context': , + 'entity_id': 'binary_sensor.test_button_1', + 'last_changed': , + 'last_updated': , + 'state': 'off', + }) +# --- +# name: test_remote_control.1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'binary_sensor', + 'entity_category': None, + 'entity_id': 'binary_sensor.test_button_1', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': 'Button 1', + 'platform': 'devolo_home_control', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'Test_1', + 'unit_of_measurement': None, + }) +# --- diff --git a/tests/components/devolo_home_control/snapshots/test_climate.ambr b/tests/components/devolo_home_control/snapshots/test_climate.ambr new file mode 100644 index 00000000000..e0066a10656 --- /dev/null +++ b/tests/components/devolo_home_control/snapshots/test_climate.ambr @@ -0,0 +1,59 @@ +# serializer version: 1 +# name: test_climate + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'current_temperature': 20, + 'friendly_name': 'Test', + 'hvac_modes': list([ + , + ]), + 'max_temp': 24, + 'min_temp': 4, + 'supported_features': , + 'target_temp_step': 0.5, + 'temperature': 20, + }), + 'context': , + 'entity_id': 'climate.test', + 'last_changed': , + 'last_updated': , + 'state': 'heat', + }) +# --- +# name: test_climate.1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'hvac_modes': list([ + , + ]), + 'max_temp': 24, + 'min_temp': 4, + 'target_temp_step': 0.5, + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'climate', + 'entity_category': None, + 'entity_id': 'climate.test', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': None, + 'platform': 'devolo_home_control', + 'supported_features': , + 'translation_key': None, + 'unique_id': 'Test', + 'unit_of_measurement': None, + }) +# --- diff --git a/tests/components/devolo_home_control/snapshots/test_cover.ambr b/tests/components/devolo_home_control/snapshots/test_cover.ambr new file mode 100644 index 00000000000..b2872d0c912 --- /dev/null +++ b/tests/components/devolo_home_control/snapshots/test_cover.ambr @@ -0,0 +1,46 @@ +# serializer version: 1 +# name: test_cover + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'current_position': 20, + 'device_class': 'blind', + 'friendly_name': 'Test', + 'supported_features': , + }), + 'context': , + 'entity_id': 'cover.test', + 'last_changed': , + 'last_updated': , + 'state': 'open', + }) +# --- +# name: test_cover.1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'cover', + 'entity_category': None, + 'entity_id': 'cover.test', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': None, + 'platform': 'devolo_home_control', + 'supported_features': , + 'translation_key': None, + 'unique_id': 'devolo.Blinds', + 'unit_of_measurement': None, + }) +# --- diff --git a/tests/components/devolo_home_control/snapshots/test_diagnostics.ambr b/tests/components/devolo_home_control/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..d2ff64ad596 --- /dev/null +++ b/tests/components/devolo_home_control/snapshots/test_diagnostics.ambr @@ -0,0 +1,53 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + 'device_info': list([ + dict({ + 'devices': list([ + dict({ + 'device_id': 'Test', + 'device_model_uid': 'Test', + 'device_type': 'Test', + 'name': 'Test Device', + }), + dict({ + 'device_id': 'Overload', + 'device_model_uid': 'Test', + 'device_type': 'Test', + 'name': 'Test Device', + }), + ]), + 'gateway': dict({ + 'firmware_version': '8.94.0', + 'local_connection': True, + }), + }), + dict({ + 'devices': list([ + ]), + 'gateway': dict({ + 'firmware_version': '8.94.0', + 'local_connection': True, + }), + }), + ]), + 'entry': dict({ + 'data': dict({ + 'mydevolo_url': 'https://test_mydevolo_url.test', + 'password': '**REDACTED**', + 'username': '**REDACTED**', + }), + 'disabled_by': None, + 'domain': 'devolo_home_control', + 'entry_id': '123456', + 'options': dict({ + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'title': 'Mock Title', + 'unique_id': '123456', + 'version': 1, + }), + }) +# --- diff --git a/tests/components/devolo_home_control/snapshots/test_light.ambr b/tests/components/devolo_home_control/snapshots/test_light.ambr new file mode 100644 index 00000000000..81c1e9b4293 --- /dev/null +++ b/tests/components/devolo_home_control/snapshots/test_light.ambr @@ -0,0 +1,105 @@ +# serializer version: 1 +# name: test_light_with_binary_sensor + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'brightness': 51, + 'color_mode': , + 'friendly_name': 'Test', + 'supported_color_modes': list([ + , + ]), + 'supported_features': , + }), + 'context': , + 'entity_id': 'light.test', + 'last_changed': , + 'last_updated': , + 'state': 'on', + }) +# --- +# name: test_light_with_binary_sensor.1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'supported_color_modes': list([ + , + ]), + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'light', + 'entity_category': None, + 'entity_id': 'light.test', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': None, + 'platform': 'devolo_home_control', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'devolo.Dimmer:Test', + 'unit_of_measurement': None, + }) +# --- +# name: test_light_without_binary_sensor + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'brightness': 51, + 'color_mode': , + 'friendly_name': 'Test', + 'supported_color_modes': list([ + , + ]), + 'supported_features': , + }), + 'context': , + 'entity_id': 'light.test', + 'last_changed': , + 'last_updated': , + 'state': 'on', + }) +# --- +# name: test_light_without_binary_sensor.1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'supported_color_modes': list([ + , + ]), + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'light', + 'entity_category': None, + 'entity_id': 'light.test', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': None, + 'platform': 'devolo_home_control', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'devolo.Dimmer:Test', + 'unit_of_measurement': None, + }) +# --- diff --git a/tests/components/devolo_home_control/snapshots/test_sensor.ambr b/tests/components/devolo_home_control/snapshots/test_sensor.ambr new file mode 100644 index 00000000000..cb97ce77af0 --- /dev/null +++ b/tests/components/devolo_home_control/snapshots/test_sensor.ambr @@ -0,0 +1,189 @@ +# serializer version: 1 +# name: test_battery_sensor + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'battery', + 'friendly_name': 'Test Battery level', + 'state_class': , + 'unit_of_measurement': '%', + }), + 'context': , + 'entity_id': 'sensor.test_battery_level', + 'last_changed': , + 'last_updated': , + 'state': '25', + }) +# --- +# name: test_battery_sensor.1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': , + 'entity_id': 'sensor.test_battery_level', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Battery level', + 'platform': 'devolo_home_control', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'devolo.BatterySensor:Test', + 'unit_of_measurement': '%', + }) +# --- +# name: test_consumption_sensor + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'power', + 'friendly_name': 'Test Current consumption', + 'state_class': , + 'unit_of_measurement': 'W', + }), + 'context': , + 'entity_id': 'sensor.test_current_consumption', + 'last_changed': , + 'last_updated': , + 'state': '0.0', + }) +# --- +# name: test_consumption_sensor.1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.test_current_consumption', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Current consumption', + 'platform': 'devolo_home_control', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'devolo.Meter:Test_current', + 'unit_of_measurement': 'W', + }) +# --- +# name: test_consumption_sensor.2 + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'energy', + 'friendly_name': 'Test Total consumption', + 'state_class': , + 'unit_of_measurement': 'kWh', + }), + 'context': , + 'entity_id': 'sensor.test_total_consumption', + 'last_changed': , + 'last_updated': , + 'state': '0.0', + }) +# --- +# name: test_consumption_sensor.3 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.test_total_consumption', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Total consumption', + 'platform': 'devolo_home_control', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'devolo.Meter:Test_total', + 'unit_of_measurement': 'kWh', + }) +# --- +# name: test_temperature_sensor + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'device_class': 'temperature', + 'friendly_name': 'Test Temperature', + 'state_class': , + 'unit_of_measurement': , + }), + 'context': , + 'entity_id': 'sensor.test_temperature', + 'last_changed': , + 'last_updated': , + 'state': '20', + }) +# --- +# name: test_temperature_sensor.1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'state_class': , + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'sensor', + 'entity_category': None, + 'entity_id': 'sensor.test_temperature', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': , + 'original_icon': None, + 'original_name': 'Temperature', + 'platform': 'devolo_home_control', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'devolo.MultiLevelSensor:Test', + 'unit_of_measurement': , + }) +# --- diff --git a/tests/components/devolo_home_control/snapshots/test_siren.ambr b/tests/components/devolo_home_control/snapshots/test_siren.ambr new file mode 100644 index 00000000000..df1d514a11d --- /dev/null +++ b/tests/components/devolo_home_control/snapshots/test_siren.ambr @@ -0,0 +1,151 @@ +# serializer version: 1 +# name: test_siren + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'available_tones': list([ + 0, + ]), + 'friendly_name': 'Test', + 'supported_features': , + }), + 'context': , + 'entity_id': 'siren.test', + 'last_changed': , + 'last_updated': , + 'state': 'off', + }) +# --- +# name: test_siren.1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'available_tones': list([ + 0, + ]), + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'siren', + 'entity_category': None, + 'entity_id': 'siren.test', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': None, + 'platform': 'devolo_home_control', + 'supported_features': , + 'translation_key': None, + 'unique_id': 'devolo.SirenMultiLevelSwitch:Test', + 'unit_of_measurement': None, + }) +# --- +# name: test_siren_change_default_tone + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'available_tones': list([ + 0, + ]), + 'friendly_name': 'Test', + 'supported_features': , + }), + 'context': , + 'entity_id': 'siren.test', + 'last_changed': , + 'last_updated': , + 'state': 'off', + }) +# --- +# name: test_siren_change_default_tone.1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'available_tones': list([ + 0, + ]), + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'siren', + 'entity_category': None, + 'entity_id': 'siren.test', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': None, + 'platform': 'devolo_home_control', + 'supported_features': , + 'translation_key': None, + 'unique_id': 'devolo.SirenMultiLevelSwitch:Test', + 'unit_of_measurement': None, + }) +# --- +# name: test_siren_switching + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'available_tones': list([ + 0, + ]), + 'friendly_name': 'Test', + 'supported_features': , + }), + 'context': , + 'entity_id': 'siren.test', + 'last_changed': , + 'last_updated': , + 'state': 'off', + }) +# --- +# name: test_siren_switching.1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': dict({ + 'available_tones': list([ + 0, + ]), + }), + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'siren', + 'entity_category': None, + 'entity_id': 'siren.test', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': None, + 'platform': 'devolo_home_control', + 'supported_features': , + 'translation_key': None, + 'unique_id': 'devolo.SirenMultiLevelSwitch:Test', + 'unit_of_measurement': None, + }) +# --- diff --git a/tests/components/devolo_home_control/snapshots/test_switch.ambr b/tests/components/devolo_home_control/snapshots/test_switch.ambr new file mode 100644 index 00000000000..4aa95944be0 --- /dev/null +++ b/tests/components/devolo_home_control/snapshots/test_switch.ambr @@ -0,0 +1,43 @@ +# serializer version: 1 +# name: test_switch + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'friendly_name': 'Test', + }), + 'context': , + 'entity_id': 'switch.test', + 'last_changed': , + 'last_updated': , + 'state': 'off', + }) +# --- +# name: test_switch.1 + EntityRegistryEntrySnapshot({ + 'aliases': set({ + }), + 'area_id': None, + 'capabilities': None, + 'config_entry_id': , + 'device_class': None, + 'device_id': , + 'disabled_by': None, + 'domain': 'switch', + 'entity_category': None, + 'entity_id': 'switch.test', + 'has_entity_name': True, + 'hidden_by': None, + 'icon': None, + 'id': , + 'name': None, + 'options': dict({ + }), + 'original_device_class': None, + 'original_icon': None, + 'original_name': None, + 'platform': 'devolo_home_control', + 'supported_features': 0, + 'translation_key': None, + 'unique_id': 'devolo.BinarySwitch:Test', + 'unit_of_measurement': None, + }) +# --- diff --git a/tests/components/devolo_home_control/test_binary_sensor.py b/tests/components/devolo_home_control/test_binary_sensor.py index 1fa2248c717..ffb1794f006 100644 --- a/tests/components/devolo_home_control/test_binary_sensor.py +++ b/tests/components/devolo_home_control/test_binary_sensor.py @@ -2,15 +2,10 @@ from unittest.mock import patch import pytest +from syrupy.assertion import SnapshotAssertion from homeassistant.components.binary_sensor import DOMAIN -from homeassistant.const import ( - ATTR_FRIENDLY_NAME, - STATE_OFF, - STATE_ON, - STATE_UNAVAILABLE, - EntityCategory, -) +from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er @@ -25,7 +20,7 @@ from .mocks import ( @pytest.mark.usefixtures("mock_zeroconf") async def test_binary_sensor( - hass: HomeAssistant, entity_registry: er.EntityRegistry + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion ) -> None: """Test setup and state change of a binary sensor device.""" entry = configure_integration(hass) @@ -39,17 +34,12 @@ async def test_binary_sensor( await hass.async_block_till_done() state = hass.states.get(f"{DOMAIN}.test_door") - assert state is not None - assert state.state == STATE_OFF - assert state.attributes[ATTR_FRIENDLY_NAME] == "Test Door" + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test_door") == snapshot state = hass.states.get(f"{DOMAIN}.test_overload") - assert state is not None - assert state.attributes[ATTR_FRIENDLY_NAME] == "Test Overload" - assert ( - entity_registry.async_get(f"{DOMAIN}.test_overload").entity_category - == EntityCategory.DIAGNOSTIC - ) + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test_overload") == snapshot # Emulate websocket message: sensor turned on test_gateway.publisher.dispatch("Test", ("Test", True)) @@ -64,7 +54,9 @@ async def test_binary_sensor( @pytest.mark.usefixtures("mock_zeroconf") -async def test_remote_control(hass: HomeAssistant) -> None: +async def test_remote_control( + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion +) -> None: """Test setup and state change of a remote control device.""" entry = configure_integration(hass) test_gateway = HomeControlMockRemoteControl() @@ -77,9 +69,8 @@ async def test_remote_control(hass: HomeAssistant) -> None: await hass.async_block_till_done() state = hass.states.get(f"{DOMAIN}.test_button_1") - assert state is not None - assert state.state == STATE_OFF - assert state.attributes[ATTR_FRIENDLY_NAME] == "Test Button 1" + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test_button_1") == snapshot # Emulate websocket message: button pressed test_gateway.publisher.dispatch("Test", ("Test", 1)) diff --git a/tests/components/devolo_home_control/test_climate.py b/tests/components/devolo_home_control/test_climate.py index fc93125a7bb..11d5b01ec5a 100644 --- a/tests/components/devolo_home_control/test_climate.py +++ b/tests/components/devolo_home_control/test_climate.py @@ -1,25 +1,25 @@ """Tests for the devolo Home Control climate.""" from unittest.mock import patch +from syrupy.assertion import SnapshotAssertion + from homeassistant.components.climate import ( ATTR_HVAC_MODE, DOMAIN, SERVICE_SET_TEMPERATURE, HVACMode, ) -from homeassistant.const import ( - ATTR_ENTITY_ID, - ATTR_FRIENDLY_NAME, - ATTR_TEMPERATURE, - STATE_UNAVAILABLE, -) +from homeassistant.const import ATTR_ENTITY_ID, ATTR_TEMPERATURE, STATE_UNAVAILABLE from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er from . import configure_integration from .mocks import HomeControlMock, HomeControlMockClimate -async def test_climate(hass: HomeAssistant) -> None: +async def test_climate( + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion +) -> None: """Test setup and state change of a climate device.""" entry = configure_integration(hass) test_gateway = HomeControlMockClimate() @@ -32,10 +32,8 @@ async def test_climate(hass: HomeAssistant) -> None: await hass.async_block_till_done() state = hass.states.get(f"{DOMAIN}.test") - assert state is not None - assert state.state == HVACMode.HEAT - assert state.attributes[ATTR_TEMPERATURE] == test_gateway.devices["Test"].value - assert state.attributes[ATTR_FRIENDLY_NAME] == "Test" + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test") == snapshot # Emulate websocket message: temperature changed test_gateway.publisher.dispatch("Test", ("Test", 21.0)) diff --git a/tests/components/devolo_home_control/test_cover.py b/tests/components/devolo_home_control/test_cover.py index 190d339cc11..54f0cc34222 100644 --- a/tests/components/devolo_home_control/test_cover.py +++ b/tests/components/devolo_home_control/test_cover.py @@ -1,24 +1,27 @@ """Tests for the devolo Home Control cover platform.""" from unittest.mock import patch +from syrupy.assertion import SnapshotAssertion + from homeassistant.components.cover import ATTR_CURRENT_POSITION, ATTR_POSITION, DOMAIN from homeassistant.const import ( ATTR_ENTITY_ID, - ATTR_FRIENDLY_NAME, SERVICE_CLOSE_COVER, SERVICE_OPEN_COVER, SERVICE_SET_COVER_POSITION, STATE_CLOSED, - STATE_OPEN, STATE_UNAVAILABLE, ) from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er from . import configure_integration from .mocks import HomeControlMock, HomeControlMockCover -async def test_cover(hass: HomeAssistant) -> None: +async def test_cover( + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion +) -> None: """Test setup and state change of a cover device.""" entry = configure_integration(hass) test_gateway = HomeControlMockCover() @@ -31,15 +34,8 @@ async def test_cover(hass: HomeAssistant) -> None: await hass.async_block_till_done() state = hass.states.get(f"{DOMAIN}.test") - assert state is not None - assert state.state == STATE_OPEN - assert state.attributes[ATTR_FRIENDLY_NAME] == "Test" - assert ( - state.attributes[ATTR_CURRENT_POSITION] - == test_gateway.devices["Test"] - .multi_level_switch_property["devolo.Blinds"] - .value - ) + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test") == snapshot # Emulate websocket message: position changed test_gateway.publisher.dispatch("Test", ("devolo.Blinds", 0.0)) diff --git a/tests/components/devolo_home_control/test_diagnostics.py b/tests/components/devolo_home_control/test_diagnostics.py index 00c582ebf92..ad267c4c52e 100644 --- a/tests/components/devolo_home_control/test_diagnostics.py +++ b/tests/components/devolo_home_control/test_diagnostics.py @@ -3,10 +3,8 @@ from __future__ import annotations from unittest.mock import patch -from aiohttp import ClientSession +from syrupy.assertion import SnapshotAssertion -from homeassistant.components.devolo_home_control.diagnostics import TO_REDACT -from homeassistant.components.diagnostics import REDACTED from homeassistant.config_entries import ConfigEntryState from homeassistant.core import HomeAssistant @@ -14,9 +12,14 @@ from . import configure_integration from .mocks import HomeControlMock, HomeControlMockBinarySensor from tests.components.diagnostics import get_diagnostics_for_config_entry +from tests.typing import ClientSessionGenerator -async def test_entry_diagnostics(hass: HomeAssistant, hass_client: ClientSession): +async def test_entry_diagnostics( + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + snapshot: SnapshotAssertion, +) -> None: """Test setup and state change of a climate device.""" entry = configure_integration(hass) gateway_1 = HomeControlMockBinarySensor() @@ -30,36 +33,5 @@ async def test_entry_diagnostics(hass: HomeAssistant, hass_client: ClientSession assert entry.state == ConfigEntryState.LOADED - entry_dict = entry.as_dict() - for key in TO_REDACT: - entry_dict["data"][key] = REDACTED - result = await get_diagnostics_for_config_entry(hass, hass_client, entry) - - assert result == { - "entry": entry_dict, - "device_info": [ - { - "gateway": { - "local_connection": gateway_1.gateway.local_connection, - "firmware_version": gateway_1.gateway.firmware_version, - }, - "devices": [ - { - "device_id": device_id, - "device_model_uid": properties.device_model_uid, - "device_type": properties.device_type, - "name": properties.name, - } - for device_id, properties in gateway_1.devices.items() - ], - }, - { - "gateway": { - "local_connection": gateway_2.gateway.local_connection, - "firmware_version": gateway_2.gateway.firmware_version, - }, - "devices": [], - }, - ], - } + assert result == snapshot diff --git a/tests/components/devolo_home_control/test_light.py b/tests/components/devolo_home_control/test_light.py index 5a80a650b5e..8cb31dde8cc 100644 --- a/tests/components/devolo_home_control/test_light.py +++ b/tests/components/devolo_home_control/test_light.py @@ -1,16 +1,11 @@ """Tests for the devolo Home Control light platform.""" from unittest.mock import patch -from homeassistant.components.light import ( - ATTR_BRIGHTNESS, - ATTR_COLOR_MODE, - ATTR_SUPPORTED_COLOR_MODES, - DOMAIN, - ColorMode, -) +from syrupy.assertion import SnapshotAssertion + +from homeassistant.components.light import ATTR_BRIGHTNESS, DOMAIN from homeassistant.const import ( ATTR_ENTITY_ID, - ATTR_FRIENDLY_NAME, SERVICE_TURN_OFF, SERVICE_TURN_ON, STATE_OFF, @@ -18,12 +13,15 @@ from homeassistant.const import ( STATE_UNAVAILABLE, ) from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er from . import configure_integration from .mocks import BinarySwitchPropertyMock, HomeControlMock, HomeControlMockLight -async def test_light_without_binary_sensor(hass: HomeAssistant) -> None: +async def test_light_without_binary_sensor( + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion +) -> None: """Test setup and state change of a light device that does not have an additional binary sensor.""" entry = configure_integration(hass) test_gateway = HomeControlMockLight() @@ -35,18 +33,8 @@ async def test_light_without_binary_sensor(hass: HomeAssistant) -> None: await hass.async_block_till_done() state = hass.states.get(f"{DOMAIN}.test") - assert state is not None - assert state.state == STATE_ON - assert state.attributes[ATTR_FRIENDLY_NAME] == "Test" - assert state.attributes[ATTR_COLOR_MODE] == ColorMode.BRIGHTNESS - assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ColorMode.BRIGHTNESS] - assert state.attributes[ATTR_BRIGHTNESS] == round( - test_gateway.devices["Test"] - .multi_level_switch_property["devolo.Dimmer:Test"] - .value - / 100 - * 255 - ) + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test") == snapshot # Emulate websocket message: brightness changed test_gateway.publisher.dispatch("Test", ("devolo.Dimmer:Test", 0.0)) @@ -96,7 +84,9 @@ async def test_light_without_binary_sensor(hass: HomeAssistant) -> None: assert hass.states.get(f"{DOMAIN}.test").state == STATE_UNAVAILABLE -async def test_light_with_binary_sensor(hass: HomeAssistant) -> None: +async def test_light_with_binary_sensor( + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion +) -> None: """Test setup and state change of a light device that has an additional binary sensor.""" entry = configure_integration(hass) test_gateway = HomeControlMockLight() @@ -111,8 +101,8 @@ async def test_light_with_binary_sensor(hass: HomeAssistant) -> None: await hass.async_block_till_done() state = hass.states.get(f"{DOMAIN}.test") - assert state is not None - assert state.state == STATE_ON + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test") == snapshot # Emulate websocket message: brightness changed test_gateway.publisher.dispatch("Test", ("devolo.Dimmer:Test", 0.0)) diff --git a/tests/components/devolo_home_control/test_sensor.py b/tests/components/devolo_home_control/test_sensor.py index 9746fca6b6f..afc4289fccf 100644 --- a/tests/components/devolo_home_control/test_sensor.py +++ b/tests/components/devolo_home_control/test_sensor.py @@ -1,19 +1,10 @@ """Tests for the devolo Home Control sensor platform.""" from unittest.mock import patch -from homeassistant.components.sensor import ( - ATTR_STATE_CLASS, - DOMAIN, - SensorDeviceClass, - SensorStateClass, -) -from homeassistant.const import ( - ATTR_DEVICE_CLASS, - ATTR_UNIT_OF_MEASUREMENT, - PERCENTAGE, - STATE_UNAVAILABLE, - EntityCategory, -) +from syrupy.assertion import SnapshotAssertion + +from homeassistant.components.sensor import DOMAIN +from homeassistant.const import STATE_UNAVAILABLE from homeassistant.core import HomeAssistant from homeassistant.helpers import entity_registry as er @@ -21,7 +12,9 @@ from . import configure_integration from .mocks import HomeControlMock, HomeControlMockConsumption, HomeControlMockSensor -async def test_temperature_sensor(hass: HomeAssistant) -> None: +async def test_temperature_sensor( + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion +) -> None: """Test setup of a temperature sensor device.""" entry = configure_integration(hass) test_gateway = HomeControlMockSensor() @@ -33,18 +26,12 @@ async def test_temperature_sensor(hass: HomeAssistant) -> None: await hass.async_block_till_done() state = hass.states.get(f"{DOMAIN}.test_temperature") - assert state is not None - assert state.state == str( - test_gateway.devices["Test"] - .multi_level_sensor_property["devolo.MultiLevelSensor:Test"] - .value - ) - assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT - assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.TEMPERATURE + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test_temperature") == snapshot async def test_battery_sensor( - hass: HomeAssistant, entity_registry: er.EntityRegistry + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion ) -> None: """Test setup and state change of a battery sensor device.""" entry = configure_integration(hass) @@ -58,15 +45,8 @@ async def test_battery_sensor( await hass.async_block_till_done() state = hass.states.get(f"{DOMAIN}.test_battery_level") - assert state is not None - assert state.state == str(test_gateway.devices["Test"].battery_level) - assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT - assert state.attributes[ATTR_UNIT_OF_MEASUREMENT] == PERCENTAGE - assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.BATTERY - assert ( - entity_registry.async_get(f"{DOMAIN}.test_battery_level").entity_category - is EntityCategory.DIAGNOSTIC - ) + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test_battery_level") == snapshot # Emulate websocket message: value changed test_gateway.publisher.dispatch("Test", ("Test", 10, "battery_level")) @@ -74,7 +54,9 @@ async def test_battery_sensor( assert hass.states.get(f"{DOMAIN}.test_battery_level").state == "10" -async def test_consumption_sensor(hass: HomeAssistant) -> None: +async def test_consumption_sensor( + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion +) -> None: """Test setup and state change of a consumption sensor device.""" entry = configure_integration(hass) test_gateway = HomeControlMockConsumption() @@ -86,20 +68,12 @@ async def test_consumption_sensor(hass: HomeAssistant) -> None: await hass.async_block_till_done() state = hass.states.get(f"{DOMAIN}.test_current_consumption") - assert state is not None - assert state.state == str( - test_gateway.devices["Test"].consumption_property["devolo.Meter:Test"].current - ) - assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.MEASUREMENT - assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.POWER + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test_current_consumption") == snapshot state = hass.states.get(f"{DOMAIN}.test_total_consumption") - assert state is not None - assert state.state == str( - test_gateway.devices["Test"].consumption_property["devolo.Meter:Test"].total - ) - assert state.attributes[ATTR_STATE_CLASS] == SensorStateClass.TOTAL_INCREASING - assert state.attributes[ATTR_DEVICE_CLASS] == SensorDeviceClass.ENERGY + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test_total_consumption") == snapshot # Emulate websocket message: value changed test_gateway.devices["Test"].consumption_property["devolo.Meter:Test"].total = 50.0 diff --git a/tests/components/devolo_home_control/test_siren.py b/tests/components/devolo_home_control/test_siren.py index 7aee5b53e42..5e72f771112 100644 --- a/tests/components/devolo_home_control/test_siren.py +++ b/tests/components/devolo_home_control/test_siren.py @@ -2,22 +2,21 @@ from unittest.mock import patch import pytest +from syrupy.assertion import SnapshotAssertion from homeassistant.components.siren import DOMAIN -from homeassistant.const import ( - ATTR_FRIENDLY_NAME, - STATE_OFF, - STATE_ON, - STATE_UNAVAILABLE, -) +from homeassistant.const import STATE_OFF, STATE_ON, STATE_UNAVAILABLE from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er from . import configure_integration from .mocks import HomeControlMock, HomeControlMockSiren @pytest.mark.usefixtures("mock_zeroconf") -async def test_siren(hass: HomeAssistant) -> None: +async def test_siren( + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion +) -> None: """Test setup and state change of a siren device.""" entry = configure_integration(hass) test_gateway = HomeControlMockSiren() @@ -30,9 +29,8 @@ async def test_siren(hass: HomeAssistant) -> None: await hass.async_block_till_done() state = hass.states.get(f"{DOMAIN}.test") - assert state is not None - assert state.state == STATE_OFF - assert state.attributes[ATTR_FRIENDLY_NAME] == "Test" + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test") == snapshot # Emulate websocket message: sensor turned on test_gateway.publisher.dispatch("Test", ("devolo.SirenMultiLevelSwitch:Test", 1)) @@ -47,7 +45,9 @@ async def test_siren(hass: HomeAssistant) -> None: @pytest.mark.usefixtures("mock_zeroconf") -async def test_siren_switching(hass: HomeAssistant) -> None: +async def test_siren_switching( + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion +) -> None: """Test setup and state change via switching of a siren device.""" entry = configure_integration(hass) test_gateway = HomeControlMockSiren() @@ -60,8 +60,8 @@ async def test_siren_switching(hass: HomeAssistant) -> None: await hass.async_block_till_done() state = hass.states.get(f"{DOMAIN}.test") - assert state is not None - assert state.state == STATE_OFF + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test") == snapshot with patch( "devolo_home_control_api.properties.multi_level_switch_property.MultiLevelSwitchProperty.set" @@ -98,7 +98,9 @@ async def test_siren_switching(hass: HomeAssistant) -> None: @pytest.mark.usefixtures("mock_zeroconf") -async def test_siren_change_default_tone(hass: HomeAssistant) -> None: +async def test_siren_change_default_tone( + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion +) -> None: """Test changing the default tone on message.""" entry = configure_integration(hass) test_gateway = HomeControlMockSiren() @@ -111,7 +113,8 @@ async def test_siren_change_default_tone(hass: HomeAssistant) -> None: await hass.async_block_till_done() state = hass.states.get(f"{DOMAIN}.test") - assert state is not None + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test") == snapshot with patch( "devolo_home_control_api.properties.multi_level_switch_property.MultiLevelSwitchProperty.set" diff --git a/tests/components/devolo_home_control/test_switch.py b/tests/components/devolo_home_control/test_switch.py index 8f160702408..9216768b9c3 100644 --- a/tests/components/devolo_home_control/test_switch.py +++ b/tests/components/devolo_home_control/test_switch.py @@ -1,22 +1,26 @@ """Tests for the devolo Home Control switch platform.""" from unittest.mock import patch +from syrupy.assertion import SnapshotAssertion + from homeassistant.components.switch import DOMAIN from homeassistant.const import ( ATTR_ENTITY_ID, SERVICE_TURN_OFF, SERVICE_TURN_ON, - STATE_OFF, STATE_ON, STATE_UNAVAILABLE, ) from homeassistant.core import HomeAssistant +from homeassistant.helpers import entity_registry as er from . import configure_integration from .mocks import HomeControlMock, HomeControlMockSwitch -async def test_switch(hass: HomeAssistant) -> None: +async def test_switch( + hass: HomeAssistant, entity_registry: er.EntityRegistry, snapshot: SnapshotAssertion +) -> None: """Test setup and state change of a switch device.""" entry = configure_integration(hass) test_gateway = HomeControlMockSwitch() @@ -28,8 +32,8 @@ async def test_switch(hass: HomeAssistant) -> None: await hass.async_block_till_done() state = hass.states.get(f"{DOMAIN}.test") - assert state is not None - assert state.state == STATE_OFF + assert state == snapshot + assert entity_registry.async_get(f"{DOMAIN}.test") == snapshot # Emulate websocket message: switched on test_gateway.devices["Test"].binary_switch_property[