From cf59ea3c47a3491508be20a3950437e1d538c573 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Benecke Date: Fri, 1 Sep 2023 19:27:54 +0200 Subject: [PATCH] Use snapshot assertion for netatmo diagnostics test (#99159) --- .../netatmo/snapshots/test_diagnostics.ambr | 620 ++++++++++++++++++ tests/components/netatmo/test_diagnostics.py | 88 +-- 2 files changed, 630 insertions(+), 78 deletions(-) create mode 100644 tests/components/netatmo/snapshots/test_diagnostics.ambr diff --git a/tests/components/netatmo/snapshots/test_diagnostics.ambr b/tests/components/netatmo/snapshots/test_diagnostics.ambr new file mode 100644 index 00000000000..228fc7563e0 --- /dev/null +++ b/tests/components/netatmo/snapshots/test_diagnostics.ambr @@ -0,0 +1,620 @@ +# serializer version: 1 +# name: test_entry_diagnostics + dict({ + 'data': dict({ + 'account': dict({ + 'errors': list([ + ]), + 'homes': list([ + dict({ + 'altitude': 112, + 'coordinates': '**REDACTED**', + 'country': 'DE', + 'id': '91763b24c43d3e344f424e8b', + 'modules': list([ + dict({ + 'id': '12:34:56:00:fa:d0', + 'modules_bridged': list([ + '12:34:56:00:01:ae', + '12:34:56:03:a0:ac', + '12:34:56:03:a5:54', + ]), + 'name': '**REDACTED**', + 'setup_date': 1494963356, + 'type': 'NAPlug', + }), + dict({ + 'bridge': '12:34:56:00:fa:d0', + 'id': '12:34:56:00:01:ae', + 'name': '**REDACTED**', + 'room_id': '2746182631', + 'setup_date': 1494963356, + 'type': 'NATherm1', + }), + dict({ + 'bridge': '12:34:56:00:fa:d0', + 'id': '12:34:56:03:a5:54', + 'name': '**REDACTED**', + 'room_id': '2833524037', + 'setup_date': 1554549767, + 'type': 'NRV', + }), + dict({ + 'bridge': '12:34:56:00:fa:d0', + 'id': '12:34:56:03:a0:ac', + 'name': '**REDACTED**', + 'room_id': '2940411577', + 'setup_date': 1554554444, + 'type': 'NRV', + }), + dict({ + 'id': '12:34:56:00:f1:62', + 'modules_bridged': list([ + '12:34:56:00:86:99', + '12:34:56:00:e3:9b', + ]), + 'name': '**REDACTED**', + 'room_id': '3688132631', + 'setup_date': 1544828430, + 'type': 'NACamera', + }), + dict({ + 'customer_id': '1000010', + 'hk_device_id': '123456007df1', + 'id': '12:34:56:10:f1:66', + 'name': '**REDACTED**', + 'network_lock': False, + 'quick_display_zone': 62, + 'reachable': True, + 'room_id': '3688132631', + 'setup_date': 1602691361, + 'type': 'NDB', + }), + dict({ + 'customer_id': 'A00010', + 'id': '12:34:56:10:b9:0e', + 'name': '**REDACTED**', + 'network_lock': False, + 'reachable': True, + 'setup_date': 1509290599, + 'type': 'NOC', + 'use_pincode': False, + }), + dict({ + 'capabilities': list([ + dict({ + 'available': True, + 'name': '**REDACTED**', + }), + ]), + 'hk_device_id': '12:34:56:20:d0:c5', + 'id': '12:34:56:20:f5:44', + 'max_modules_nb': 21, + 'modules_bridged': list([ + '12:34:56:20:f5:8c', + ]), + 'name': '**REDACTED**', + 'reachable': True, + 'room_id': '222452125', + 'setup_date': 1607443936, + 'type': 'OTH', + }), + dict({ + 'bridge': '12:34:56:20:f5:44', + 'id': '12:34:56:20:f5:8c', + 'name': '**REDACTED**', + 'room_id': '222452125', + 'setup_date': 1607443939, + 'type': 'OTM', + }), + dict({ + 'id': '12:34:56:30:d5:d4', + 'modules_bridged': list([ + '0009999992', + ]), + 'name': '**REDACTED**', + 'room_id': '222452125', + 'setup_date': 1562262465, + 'type': 'NBG', + }), + dict({ + 'bridge': '12:34:56:30:d5:d4', + 'id': '0009999992', + 'name': '**REDACTED**', + 'room_id': '3688132631', + 'setup_date': 1578551339, + 'type': 'NBR', + }), + dict({ + 'alarm_config': dict({ + 'default_alarm': list([ + dict({ + 'db_alarm_number': 0, + }), + dict({ + 'db_alarm_number': 1, + }), + dict({ + 'db_alarm_number': 2, + }), + dict({ + 'db_alarm_number': 6, + }), + dict({ + 'db_alarm_number': 4, + }), + dict({ + 'db_alarm_number': 5, + }), + dict({ + 'db_alarm_number': 7, + }), + dict({ + 'db_alarm_number': 22, + }), + ]), + 'personnalized': list([ + dict({ + 'data_type': 1, + 'db_alarm_number': 8, + 'direction': 0, + 'threshold': 20, + }), + dict({ + 'data_type': 1, + 'db_alarm_number': 9, + 'direction': 1, + 'threshold': 17, + }), + dict({ + 'data_type': 4, + 'db_alarm_number': 16, + 'direction': 0, + 'threshold': 65, + }), + dict({ + 'data_type': 8, + 'db_alarm_number': 22, + 'direction': 0, + 'threshold': 19, + }), + ]), + }), + 'customer_id': 'C00016', + 'hardware_version': 251, + 'id': '12:34:56:80:bb:26', + 'module_offset': dict({ + '03:00:00:03:1b:0e': dict({ + 'a': 0, + }), + '12:34:56:80:bb:26': dict({ + 'a': 0.1, + }), + }), + 'modules_bridged': list([ + '12:34:56:80:44:92', + '12:34:56:80:7e:18', + '12:34:56:80:1c:42', + '12:34:56:80:c1:ea', + ]), + 'name': '**REDACTED**', + 'public_ext_counter': 0, + 'public_ext_data': False, + 'reachable': True, + 'room_id': '4122897288', + 'setup_date': 1419453350, + 'type': 'NAMain', + }), + dict({ + 'bridge': '12:34:56:80:bb:26', + 'id': '12:34:56:80:1c:42', + 'name': '**REDACTED**', + 'setup_date': 1448565785, + 'type': 'NAModule1', + }), + dict({ + 'bridge': '12:34:56:80:bb:26', + 'id': '12:34:56:80:c1:ea', + 'name': '**REDACTED**', + 'setup_date': 1591770206, + 'type': 'NAModule3', + }), + dict({ + 'bridge': '12:34:56:80:bb:26', + 'id': '12:34:56:80:44:92', + 'name': '**REDACTED**', + 'setup_date': 1484997703, + 'type': 'NAModule4', + }), + dict({ + 'bridge': '12:34:56:80:bb:26', + 'id': '12:34:56:80:7e:18', + 'name': '**REDACTED**', + 'setup_date': 1543579864, + 'type': 'NAModule4', + }), + dict({ + 'bridge': '12:34:56:80:bb:26', + 'id': '12:34:56:03:1b:e4', + 'name': '**REDACTED**', + 'setup_date': 1543579864, + 'type': 'NAModule2', + }), + dict({ + 'id': '12:34:56:80:60:40', + 'modules_bridged': list([ + '12:34:56:80:00:12:ac:f2', + '12:34:56:80:00:c3:69:3c', + '12:34:56:00:00:a1:4c:da', + '12:34:56:00:01:01:01:a1', + '00:11:22:33:00:11:45:fe', + ]), + 'name': '**REDACTED**', + 'room_id': '1310352496', + 'setup_date': 1641841257, + 'type': 'NLG', + }), + dict({ + 'bridge': '12:34:56:80:60:40', + 'id': '12:34:56:80:00:12:ac:f2', + 'name': '**REDACTED**', + 'room_id': '1310352496', + 'setup_date': 1641841262, + 'type': 'NLP', + }), + dict({ + 'bridge': '12:34:56:80:60:40', + 'id': '12:34:56:80:00:c3:69:3c', + 'name': '**REDACTED**', + 'setup_date': 1641841262, + 'type': 'NLT', + }), + dict({ + 'bridge': '12:34:56:00:f1:62', + 'category': 'window', + 'id': '12:34:56:00:86:99', + 'name': '**REDACTED**', + 'setup_date': 1581177375, + 'type': 'NACamDoorTag', + }), + dict({ + 'bridge': '12:34:56:00:f1:62', + 'id': '12:34:56:00:e3:9b', + 'name': '**REDACTED**', + 'setup_date': 1620479901, + 'type': 'NIS', + }), + dict({ + 'id': '12:34:56:00:16:0e', + 'modules_bridged': list([ + '12:34:56:00:16:0e#0', + '12:34:56:00:16:0e#1', + '12:34:56:00:16:0e#2', + '12:34:56:00:16:0e#3', + '12:34:56:00:16:0e#4', + '12:34:56:00:16:0e#5', + '12:34:56:00:16:0e#6', + '12:34:56:00:16:0e#7', + '12:34:56:00:16:0e#8', + ]), + 'name': '**REDACTED**', + 'room_id': '100007519', + 'setup_date': 1644496884, + 'type': 'NLE', + }), + dict({ + 'bridge': '12:34:56:00:16:0e', + 'id': '12:34:56:00:16:0e#0', + 'name': '**REDACTED**', + 'room_id': '100007519', + 'setup_date': 1644496886, + 'type': 'NLE', + }), + dict({ + 'bridge': '12:34:56:00:16:0e', + 'id': '12:34:56:00:16:0e#1', + 'name': '**REDACTED**', + 'room_id': '100007519', + 'setup_date': 1644496886, + 'type': 'NLE', + }), + dict({ + 'bridge': '12:34:56:00:16:0e', + 'id': '12:34:56:00:16:0e#2', + 'name': '**REDACTED**', + 'room_id': '100007519', + 'setup_date': 1644496886, + 'type': 'NLE', + }), + dict({ + 'bridge': '12:34:56:00:16:0e', + 'id': '12:34:56:00:16:0e#3', + 'name': '**REDACTED**', + 'room_id': '100007519', + 'setup_date': 1644496886, + 'type': 'NLE', + }), + dict({ + 'bridge': '12:34:56:00:16:0e', + 'id': '12:34:56:00:16:0e#4', + 'name': '**REDACTED**', + 'room_id': '100007519', + 'setup_date': 1644496886, + 'type': 'NLE', + }), + dict({ + 'bridge': '12:34:56:00:16:0e', + 'id': '12:34:56:00:16:0e#5', + 'name': '**REDACTED**', + 'room_id': '100007519', + 'setup_date': 1644496886, + 'type': 'NLE', + }), + dict({ + 'bridge': '12:34:56:00:16:0e', + 'id': '12:34:56:00:16:0e#6', + 'name': '**REDACTED**', + 'room_id': '100007519', + 'setup_date': 1644496886, + 'type': 'NLE', + }), + dict({ + 'bridge': '12:34:56:00:16:0e', + 'id': '12:34:56:00:16:0e#7', + 'name': '**REDACTED**', + 'room_id': '100007519', + 'setup_date': 1644496886, + 'type': 'NLE', + }), + dict({ + 'bridge': '12:34:56:00:16:0e', + 'id': '12:34:56:00:16:0e#8', + 'name': '**REDACTED**', + 'room_id': '100007519', + 'setup_date': 1644496886, + 'type': 'NLE', + }), + dict({ + 'bridge': '12:34:56:80:60:40', + 'id': '12:34:56:00:00:a1:4c:da', + 'name': '**REDACTED**', + 'room_id': '100008999', + 'setup_date': 1638376602, + 'type': 'NLPC', + }), + dict({ + 'id': '10:20:30:bd:b8:1e', + 'name': '**REDACTED**', + 'room_id': '1002003001', + 'setup_date': 1638022197, + 'type': 'BNS', + }), + dict({ + 'bridge': '12:34:56:80:60:40', + 'brightness': 63, + 'firmware_revision': 57, + 'id': '00:11:22:33:00:11:45:fe', + 'last_seen': 1657086939, + 'on': False, + 'power': 0, + 'reachable': True, + 'type': 'NLF', + }), + dict({ + 'bridge': '12:34:56:80:60:40', + 'id': '12:34:56:00:01:01:01:a1', + 'name': '**REDACTED**', + 'room_id': '1002003001', + 'setup_date': 1598367404, + 'type': 'NLFN', + }), + ]), + 'name': '**REDACTED**', + 'persons': list([ + dict({ + 'id': '91827374-7e04-5298-83ad-a0cb8372dff1', + 'pseudo': '**REDACTED**', + 'url': '**REDACTED**', + }), + dict({ + 'id': '91827375-7e04-5298-83ae-a0cb8372dff2', + 'pseudo': '**REDACTED**', + 'url': '**REDACTED**', + }), + dict({ + 'id': '91827376-7e04-5298-83af-a0cb8372dff3', + 'pseudo': '**REDACTED**', + 'url': '**REDACTED**', + }), + ]), + 'rooms': list([ + dict({ + 'id': '2746182631', + 'module_ids': list([ + '12:34:56:00:01:ae', + ]), + 'name': '**REDACTED**', + 'type': 'livingroom', + }), + dict({ + 'id': '3688132631', + 'module_ids': list([ + '12:34:56:00:f1:62', + '12:34:56:10:f1:66', + '12:34:56:00:e3:9b', + '0009999992', + ]), + 'name': '**REDACTED**', + 'type': 'custom', + }), + dict({ + 'id': '2833524037', + 'module_ids': list([ + '12:34:56:03:a5:54', + ]), + 'name': '**REDACTED**', + 'type': 'lobby', + }), + dict({ + 'id': '2940411577', + 'module_ids': list([ + '12:34:56:03:a0:ac', + ]), + 'name': '**REDACTED**', + 'type': 'kitchen', + }), + dict({ + 'id': '222452125', + 'module_ids': list([ + '12:34:56:20:f5:44', + '12:34:56:20:f5:8c', + ]), + 'modules': list([ + '12:34:56:20:f5:44', + '12:34:56:20:f5:8c', + ]), + 'name': '**REDACTED**', + 'therm_relay': '12:34:56:20:f5:44', + 'true_temperature_available': True, + 'type': 'electrical_cabinet', + }), + dict({ + 'id': '100007519', + 'module_ids': list([ + '12:34:56:00:16:0e', + '12:34:56:00:16:0e#0', + '12:34:56:00:16:0e#1', + '12:34:56:00:16:0e#2', + '12:34:56:00:16:0e#3', + '12:34:56:00:16:0e#4', + '12:34:56:00:16:0e#5', + '12:34:56:00:16:0e#6', + '12:34:56:00:16:0e#7', + '12:34:56:00:16:0e#8', + ]), + 'name': '**REDACTED**', + 'type': 'electrical_cabinet', + }), + dict({ + 'id': '1002003001', + 'module_ids': list([ + '10:20:30:bd:b8:1e', + ]), + 'name': '**REDACTED**', + 'type': 'corridor', + }), + dict({ + 'id': '100007520', + 'module_ids': list([ + '00:11:22:33:00:11:45:fe', + ]), + 'name': '**REDACTED**', + 'type': 'toilets', + }), + ]), + 'schedules': list([ + dict({ + 'away_temp': 14, + 'hg_temp': 7, + 'id': '591b54a2764ff4d50d8b5795', + 'name': '**REDACTED**', + 'selected': True, + 'timetable': '**REDACTED**', + 'type': 'therm', + 'zones': '**REDACTED**', + }), + dict({ + 'away_temp': 14, + 'hg_temp': 7, + 'id': 'b1b54a2f45795764f59d50d8', + 'name': '**REDACTED**', + 'timetable': '**REDACTED**', + 'type': 'therm', + 'zones': '**REDACTED**', + }), + ]), + 'therm_mode': 'schedule', + 'therm_setpoint_default_duration': 120, + 'timezone': 'Europe/Berlin', + }), + dict({ + 'altitude': 112, + 'coordinates': '**REDACTED**', + 'country': 'DE', + 'id': '91763b24c43d3e344f424e8c', + 'therm_mode': 'schedule', + 'therm_setpoint_default_duration': 180, + 'timezone': 'Europe/Berlin', + }), + ]), + }), + }), + 'info': dict({ + 'data': dict({ + 'auth_implementation': 'cloud', + 'token': dict({ + 'access_token': '**REDACTED**', + 'expires_in': 60, + 'refresh_token': '**REDACTED**', + 'scope': list([ + 'access_camera', + 'access_doorbell', + 'access_presence', + 'read_bubendorff', + 'read_camera', + 'read_carbonmonoxidedetector', + 'read_doorbell', + 'read_homecoach', + 'read_magellan', + 'read_mx', + 'read_presence', + 'read_smarther', + 'read_smokedetector', + 'read_station', + 'read_thermostat', + 'write_bubendorff', + 'write_camera', + 'write_magellan', + 'write_mx', + 'write_presence', + 'write_smarther', + 'write_thermostat', + ]), + 'type': 'Bearer', + }), + 'webhook_id': '**REDACTED**', + }), + 'disabled_by': None, + 'domain': 'netatmo', + 'options': dict({ + 'weather_areas': dict({ + 'Home avg': dict({ + 'area_name': 'Home avg', + 'lat_ne': '**REDACTED**', + 'lat_sw': '**REDACTED**', + 'lon_ne': '**REDACTED**', + 'lon_sw': '**REDACTED**', + 'mode': 'avg', + 'show_on_map': False, + }), + 'Home max': dict({ + 'area_name': 'Home max', + 'lat_ne': '**REDACTED**', + 'lat_sw': '**REDACTED**', + 'lon_ne': '**REDACTED**', + 'lon_sw': '**REDACTED**', + 'mode': 'max', + 'show_on_map': True, + }), + }), + }), + 'pref_disable_new_entities': False, + 'pref_disable_polling': False, + 'source': 'user', + 'title': 'Mock Title', + 'unique_id': 'netatmo', + 'version': 1, + 'webhook_registered': False, + }), + }) +# --- diff --git a/tests/components/netatmo/test_diagnostics.py b/tests/components/netatmo/test_diagnostics.py index 6c0c489be3d..0ece935abcb 100644 --- a/tests/components/netatmo/test_diagnostics.py +++ b/tests/components/netatmo/test_diagnostics.py @@ -1,7 +1,9 @@ """Test the Netatmo diagnostics.""" from unittest.mock import AsyncMock, patch -from homeassistant.components.diagnostics import REDACTED +from syrupy import SnapshotAssertion +from syrupy.filters import paths + from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component @@ -12,7 +14,10 @@ from tests.typing import ClientSessionGenerator async def test_entry_diagnostics( - hass: HomeAssistant, hass_client: ClientSessionGenerator, config_entry + hass: HomeAssistant, + hass_client: ClientSessionGenerator, + snapshot: SnapshotAssertion, + config_entry, ) -> None: """Test config entry diagnostics.""" with patch( @@ -29,79 +34,6 @@ async def test_entry_diagnostics( await hass.async_block_till_done() - result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry) - - # ignore for tests - result["info"]["data"]["token"].pop("expires_at") - result["info"].pop("entry_id") - - assert result["info"] == { - "data": { - "auth_implementation": "cloud", - "token": { - "access_token": REDACTED, - "expires_in": 60, - "refresh_token": REDACTED, - "scope": [ - "access_camera", - "access_doorbell", - "access_presence", - "read_bubendorff", - "read_camera", - "read_carbonmonoxidedetector", - "read_doorbell", - "read_homecoach", - "read_magellan", - "read_mx", - "read_presence", - "read_smarther", - "read_smokedetector", - "read_station", - "read_thermostat", - "write_bubendorff", - "write_camera", - "write_magellan", - "write_mx", - "write_presence", - "write_smarther", - "write_thermostat", - ], - "type": "Bearer", - }, - "webhook_id": REDACTED, - }, - "disabled_by": None, - "domain": "netatmo", - "options": { - "weather_areas": { - "Home avg": { - "area_name": "Home avg", - "lat_ne": REDACTED, - "lat_sw": REDACTED, - "lon_ne": REDACTED, - "lon_sw": REDACTED, - "mode": "avg", - "show_on_map": False, - }, - "Home max": { - "area_name": "Home max", - "lat_ne": REDACTED, - "lat_sw": REDACTED, - "lon_ne": REDACTED, - "lon_sw": REDACTED, - "mode": "max", - "show_on_map": True, - }, - } - }, - "pref_disable_new_entities": False, - "pref_disable_polling": False, - "source": "user", - "title": "Mock Title", - "unique_id": "netatmo", - "version": 1, - "webhook_registered": False, - } - - for home in result["data"]["account"]["homes"]: - assert home["coordinates"] == REDACTED + assert await get_diagnostics_for_config_entry( + hass, hass_client, config_entry + ) == snapshot(exclude=paths("info.data.token.expires_at", "info.entry_id"))