Add Yale Smart Living diagnostics test (#98590)

* Yale test diagnostics

* clean

* From review
This commit is contained in:
G Johansson 2023-08-18 16:31:07 +02:00 committed by GitHub
parent 790523126e
commit 4096de2dad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 763 additions and 0 deletions

View file

@ -0,0 +1,64 @@
"""Fixtures for the Yale Smart Living integration."""
from __future__ import annotations
import json
from typing import Any
from unittest.mock import patch
import pytest
from yalesmartalarmclient.const import YALE_STATE_ARM_FULL
from homeassistant.components.yale_smart_alarm.const import DOMAIN
from homeassistant.config_entries import SOURCE_USER
from homeassistant.core import HomeAssistant
from tests.common import MockConfigEntry, load_fixture
ENTRY_CONFIG = {
"username": "test-username",
"password": "new-test-password",
"name": "Yale Smart Alarm",
"area_id": "1",
}
OPTIONS_CONFIG = {"lock_code_digits": 6}
@pytest.fixture
async def load_config_entry(
hass: HomeAssistant, load_json: dict[str, Any]
) -> MockConfigEntry:
"""Set up the Yale Smart Living integration in Home Assistant."""
config_entry = MockConfigEntry(
domain=DOMAIN,
source=SOURCE_USER,
data=ENTRY_CONFIG,
options=OPTIONS_CONFIG,
entry_id="1",
unique_id="username",
version=1,
)
config_entry.add_to_hass(hass)
with patch(
"homeassistant.components.yale_smart_alarm.coordinator.YaleSmartAlarmClient",
autospec=True,
) as mock_client_class:
client = mock_client_class.return_value
client.auth = None
client.lock_api = None
client.get_all.return_value = load_json
client.get_armed_status.return_value = YALE_STATE_ARM_FULL
await hass.config_entries.async_setup(config_entry.entry_id)
await hass.async_block_till_done()
return config_entry
@pytest.fixture(name="load_json", scope="session")
def load_json_from_fixture() -> dict[str, Any]:
"""Load fixture with json data and return."""
data_fixture = load_fixture("get_all.json", "yale_smart_alarm")
json_data: dict[str, Any] = json.loads(data_fixture)
return json_data

View file

@ -0,0 +1,331 @@
{
"DEVICES": [
{
"area": "1",
"no": "1",
"rf": null,
"address": "123",
"type": "device_type.door_lock",
"name": "Device1",
"status1": "device_status.lock",
"status2": null,
"status_switch": null,
"status_power": null,
"status_temp": null,
"status_humi": null,
"status_dim_level": null,
"status_lux": "",
"status_hue": null,
"status_saturation": null,
"rssi": "9",
"mac": "00:00:00:00:01",
"scene_trigger": "0",
"status_total_energy": null,
"device_id2": "",
"extension": null,
"minigw_protocol": "DM",
"minigw_syncing": "0",
"minigw_configuration_data": "02FF000001000000000000000000001E000100",
"minigw_product_data": "21020120",
"minigw_lock_status": "35",
"minigw_number_of_credentials_supported": "10",
"sresp_button_3": null,
"sresp_button_1": null,
"sresp_button_2": null,
"sresp_button_4": null,
"ipcam_trigger_by_zone1": null,
"ipcam_trigger_by_zone2": null,
"ipcam_trigger_by_zone3": null,
"ipcam_trigger_by_zone4": null,
"scene_restore": null,
"thermo_mode": null,
"thermo_setpoint": null,
"thermo_c_setpoint": null,
"thermo_setpoint_away": null,
"thermo_c_setpoint_away": null,
"thermo_fan_mode": null,
"thermo_schd_setting": null,
"group_id": null,
"group_name": null,
"bypass": "0",
"device_id": "123",
"status_temp_format": "C",
"type_no": "72",
"device_group": "002",
"status_fault": [],
"status_open": ["device_status.lock"],
"trigger_by_zone": []
}
],
"MODE": [
{
"area": "1",
"mode": "disarm"
}
],
"STATUS": {
"acfail": "main.normal",
"battery": "main.normal",
"tamper": "main.normal",
"jam": "main.normal",
"rssi": "1",
"gsm_rssi": "0",
"imei": "",
"imsi": ""
},
"CYCLE": {
"model": [
{
"area": "1",
"mode": "disarm"
}
],
"panel_status": {
"warning_snd_mute": "0"
},
"device_status": [
{
"area": "1",
"no": "1",
"rf": null,
"address": "124",
"type": "device_type.door_lock",
"name": "Device2",
"status1": "device_status.lock",
"status2": null,
"status_switch": null,
"status_power": null,
"status_temp": null,
"status_humi": null,
"status_dim_level": null,
"status_lux": "",
"status_hue": null,
"status_saturation": null,
"rssi": "9",
"mac": "00:00:00:00:02",
"scene_trigger": "0",
"status_total_energy": null,
"device_id2": "",
"extension": null,
"minigw_protocol": "DM",
"minigw_syncing": "0",
"minigw_configuration_data": "02FF000001000000000000000000001E000100",
"minigw_product_data": "21020120",
"minigw_lock_status": "35",
"minigw_number_of_credentials_supported": "10",
"sresp_button_3": null,
"sresp_button_1": null,
"sresp_button_2": null,
"sresp_button_4": null,
"ipcam_trigger_by_zone1": null,
"ipcam_trigger_by_zone2": null,
"ipcam_trigger_by_zone3": null,
"ipcam_trigger_by_zone4": null,
"scene_restore": null,
"thermo_mode": null,
"thermo_setpoint": null,
"thermo_c_setpoint": null,
"thermo_setpoint_away": null,
"thermo_c_setpoint_away": null,
"thermo_fan_mode": null,
"thermo_schd_setting": null,
"group_id": null,
"group_name": null,
"bypass": "0",
"device_id": "124",
"status_temp_format": "C",
"type_no": "72",
"device_group": "002",
"status_fault": [],
"status_open": ["device_status.lock"],
"trigger_by_zone": []
}
],
"capture_latest": null,
"report_event_latest": {
"utc_event_time": null,
"time": "1692271914",
"report_id": "1027299996",
"id": "9999",
"event_time": null,
"cid_code": "1807"
},
"alarm_event_latest": null
},
"ONLINE": "online",
"HISTORY": [
{
"report_id": "1027299996",
"cid": "18180701000",
"event_type": "1807",
"user": 0,
"area": 1,
"zone": 1,
"name": "Device1",
"type": "device_type.door_lock",
"event_time": null,
"time": "2023/08/17 11:31:54",
"status_temp_format": "C",
"cid_source": "DEVICE"
},
{
"report_id": "1027299889",
"cid": "18180201101",
"event_type": "1802",
"user": 101,
"area": 1,
"zone": 1,
"name": "Device1",
"type": "device_type.door_lock",
"event_time": null,
"time": "2023/08/17 11:31:43",
"status_temp_format": "C",
"cid_source": "DEVICE"
},
{
"report_id": "1027299587",
"cid": "18180701000",
"event_type": "1807",
"user": 0,
"area": 1,
"zone": 1,
"name": "Device1",
"type": "device_type.door_lock",
"event_time": null,
"time": "2023/08/17 11:31:11",
"status_temp_format": "C",
"cid_source": "DEVICE"
},
{
"report_id": "1027296099",
"cid": "18180101001",
"event_type": "1801",
"user": 1,
"area": 1,
"zone": 1,
"name": "Device1",
"type": "device_type.door_lock",
"event_time": null,
"time": "2023/08/17 11:24:52",
"status_temp_format": "C",
"cid_source": "DEVICE"
},
{
"report_id": "1027273782",
"cid": "18180701000",
"event_type": "1807",
"user": 0,
"area": 1,
"zone": 1,
"name": "Device1",
"type": "device_type.door_lock",
"event_time": null,
"time": "2023/08/17 10:43:21",
"status_temp_format": "C",
"cid_source": "DEVICE"
},
{
"report_id": "1027273230",
"cid": "18180201101",
"event_type": "1802",
"user": 101,
"area": 1,
"zone": 1,
"name": "Device1",
"type": "device_type.door_lock",
"event_time": null,
"time": "2023/08/17 10:42:09",
"status_temp_format": "C",
"cid_source": "DEVICE"
},
{
"report_id": "1027100172",
"cid": "18180701000",
"event_type": "1807",
"user": 0,
"area": 1,
"zone": 1,
"name": "Device1",
"type": "device_type.door_lock",
"event_time": null,
"time": "2023/08/17 05:28:57",
"status_temp_format": "C",
"cid_source": "DEVICE"
},
{
"report_id": "1027099978",
"cid": "18180101001",
"event_type": "1801",
"user": 1,
"area": 1,
"zone": 1,
"name": "Device1",
"type": "device_type.door_lock",
"event_time": null,
"time": "2023/08/17 05:28:39",
"status_temp_format": "C",
"cid_source": "DEVICE"
},
{
"report_id": "1027093266",
"cid": "18160200000",
"event_type": "1602",
"user": "",
"area": 0,
"zone": 0,
"name": "",
"type": "",
"event_time": null,
"time": "2023/08/17 05:17:12",
"status_temp_format": "C",
"cid_source": "SYSTEM"
},
{
"report_id": "1026912623",
"cid": "18180701000",
"event_type": "1807",
"user": 0,
"area": 1,
"zone": 1,
"name": "Device1",
"type": "device_type.door_lock",
"event_time": null,
"time": "2023/08/16 20:29:36",
"status_temp_format": "C",
"cid_source": "DEVICE"
}
],
"PANEL INFO": {
"mac": "00:00:00:00:10",
"report_account": "username",
"xml_version": "2",
"version": "MINIGW-MZ-1_G 1.0.1.29A,,4.1.2.6.2,00:1D:94:0B:5E:A7,10111112,ML_yamga",
"net_version": "MINIGW-MZ-1_G 1.0.1.29A",
"rf51_version": "",
"zb_version": "4.1.2.6.2",
"zw_version": "",
"SMS_Balance": "50",
"voice_balance": "0",
"name": "",
"contact": "",
"mail_address": "username@fake.com",
"phone": "UK-01902364606 / Sweden-0770373710 / Demark-89887818 / Norway-81569036",
"service_time": "UK - Mon to Fri 8:30 til 17:30 / Scandinavia - Mon to Fri 8:00 til 20:00, Sat to Sun 10:00 til 15:00",
"dealer_name": "Poland"
},
"AUTH CHECK": {
"user_id": "username",
"id": "username",
"mail_address": "username@fake.com",
"mac": "00:00:00:00:20",
"is_auth": "1",
"master": "1",
"first_login": "1",
"name": "Device1",
"token_time": "2023-08-17 16:19:20",
"agent": false,
"xml_version": "2",
"dealer_id": "605",
"dealer_group": "yale"
}
}

View file

@ -0,0 +1,344 @@
# serializer version: 1
# name: test_diagnostics
dict({
'AUTH CHECK': dict({
'agent': False,
'dealer_group': 'yale',
'dealer_id': '605',
'first_login': '1',
'id': '**REDACTED**',
'is_auth': '1',
'mac': '**REDACTED**',
'mail_address': '**REDACTED**',
'master': '1',
'name': '**REDACTED**',
'token_time': '2023-08-17 16:19:20',
'user_id': '**REDACTED**',
'xml_version': '2',
}),
'CYCLE': dict({
'alarm_event_latest': None,
'capture_latest': None,
'device_status': list([
dict({
'_state': 'locked',
'_state2': 'closed',
'address': '**REDACTED**',
'area': '1',
'bypass': '0',
'device_group': '002',
'device_id': '**REDACTED**',
'device_id2': '',
'extension': None,
'group_id': None,
'group_name': None,
'ipcam_trigger_by_zone1': None,
'ipcam_trigger_by_zone2': None,
'ipcam_trigger_by_zone3': None,
'ipcam_trigger_by_zone4': None,
'mac': '**REDACTED**',
'minigw_configuration_data': '02FF000001000000000000000000001E000100',
'minigw_lock_status': '35',
'minigw_number_of_credentials_supported': '10',
'minigw_product_data': '21020120',
'minigw_protocol': 'DM',
'minigw_syncing': '0',
'name': '**REDACTED**',
'no': '1',
'rf': None,
'rssi': '9',
'scene_restore': None,
'scene_trigger': '0',
'sresp_button_1': None,
'sresp_button_2': None,
'sresp_button_3': None,
'sresp_button_4': None,
'status1': 'device_status.lock',
'status2': None,
'status_dim_level': None,
'status_fault': list([
]),
'status_hue': None,
'status_humi': None,
'status_lux': '',
'status_open': list([
'device_status.lock',
]),
'status_power': None,
'status_saturation': None,
'status_switch': None,
'status_temp': None,
'status_temp_format': 'C',
'status_total_energy': None,
'thermo_c_setpoint': None,
'thermo_c_setpoint_away': None,
'thermo_fan_mode': None,
'thermo_mode': None,
'thermo_schd_setting': None,
'thermo_setpoint': None,
'thermo_setpoint_away': None,
'trigger_by_zone': list([
]),
'type': 'device_type.door_lock',
'type_no': '72',
}),
]),
'model': list([
dict({
'area': '1',
'mode': 'disarm',
}),
]),
'panel_status': dict({
'warning_snd_mute': '0',
}),
'report_event_latest': dict({
'cid_code': '1807',
'event_time': None,
'id': '**REDACTED**',
'report_id': '1027299996',
'time': '1692271914',
'utc_event_time': None,
}),
}),
'DEVICES': list([
dict({
'address': '**REDACTED**',
'area': '1',
'bypass': '0',
'device_group': '002',
'device_id': '**REDACTED**',
'device_id2': '',
'extension': None,
'group_id': None,
'group_name': None,
'ipcam_trigger_by_zone1': None,
'ipcam_trigger_by_zone2': None,
'ipcam_trigger_by_zone3': None,
'ipcam_trigger_by_zone4': None,
'mac': '**REDACTED**',
'minigw_configuration_data': '02FF000001000000000000000000001E000100',
'minigw_lock_status': '35',
'minigw_number_of_credentials_supported': '10',
'minigw_product_data': '21020120',
'minigw_protocol': 'DM',
'minigw_syncing': '0',
'name': '**REDACTED**',
'no': '1',
'rf': None,
'rssi': '9',
'scene_restore': None,
'scene_trigger': '0',
'sresp_button_1': None,
'sresp_button_2': None,
'sresp_button_3': None,
'sresp_button_4': None,
'status1': 'device_status.lock',
'status2': None,
'status_dim_level': None,
'status_fault': list([
]),
'status_hue': None,
'status_humi': None,
'status_lux': '',
'status_open': list([
'device_status.lock',
]),
'status_power': None,
'status_saturation': None,
'status_switch': None,
'status_temp': None,
'status_temp_format': 'C',
'status_total_energy': None,
'thermo_c_setpoint': None,
'thermo_c_setpoint_away': None,
'thermo_fan_mode': None,
'thermo_mode': None,
'thermo_schd_setting': None,
'thermo_setpoint': None,
'thermo_setpoint_away': None,
'trigger_by_zone': list([
]),
'type': 'device_type.door_lock',
'type_no': '72',
}),
]),
'HISTORY': list([
dict({
'area': 1,
'cid': '18180701000',
'cid_source': 'DEVICE',
'event_time': None,
'event_type': '1807',
'name': '**REDACTED**',
'report_id': '1027299996',
'status_temp_format': 'C',
'time': '2023/08/17 11:31:54',
'type': 'device_type.door_lock',
'user': 0,
'zone': 1,
}),
dict({
'area': 1,
'cid': '18180201101',
'cid_source': 'DEVICE',
'event_time': None,
'event_type': '1802',
'name': '**REDACTED**',
'report_id': '1027299889',
'status_temp_format': 'C',
'time': '2023/08/17 11:31:43',
'type': 'device_type.door_lock',
'user': 101,
'zone': 1,
}),
dict({
'area': 1,
'cid': '18180701000',
'cid_source': 'DEVICE',
'event_time': None,
'event_type': '1807',
'name': '**REDACTED**',
'report_id': '1027299587',
'status_temp_format': 'C',
'time': '2023/08/17 11:31:11',
'type': 'device_type.door_lock',
'user': 0,
'zone': 1,
}),
dict({
'area': 1,
'cid': '18180101001',
'cid_source': 'DEVICE',
'event_time': None,
'event_type': '1801',
'name': '**REDACTED**',
'report_id': '1027296099',
'status_temp_format': 'C',
'time': '2023/08/17 11:24:52',
'type': 'device_type.door_lock',
'user': 1,
'zone': 1,
}),
dict({
'area': 1,
'cid': '18180701000',
'cid_source': 'DEVICE',
'event_time': None,
'event_type': '1807',
'name': '**REDACTED**',
'report_id': '1027273782',
'status_temp_format': 'C',
'time': '2023/08/17 10:43:21',
'type': 'device_type.door_lock',
'user': 0,
'zone': 1,
}),
dict({
'area': 1,
'cid': '18180201101',
'cid_source': 'DEVICE',
'event_time': None,
'event_type': '1802',
'name': '**REDACTED**',
'report_id': '1027273230',
'status_temp_format': 'C',
'time': '2023/08/17 10:42:09',
'type': 'device_type.door_lock',
'user': 101,
'zone': 1,
}),
dict({
'area': 1,
'cid': '18180701000',
'cid_source': 'DEVICE',
'event_time': None,
'event_type': '1807',
'name': '**REDACTED**',
'report_id': '1027100172',
'status_temp_format': 'C',
'time': '2023/08/17 05:28:57',
'type': 'device_type.door_lock',
'user': 0,
'zone': 1,
}),
dict({
'area': 1,
'cid': '18180101001',
'cid_source': 'DEVICE',
'event_time': None,
'event_type': '1801',
'name': '**REDACTED**',
'report_id': '1027099978',
'status_temp_format': 'C',
'time': '2023/08/17 05:28:39',
'type': 'device_type.door_lock',
'user': 1,
'zone': 1,
}),
dict({
'area': 0,
'cid': '18160200000',
'cid_source': 'SYSTEM',
'event_time': None,
'event_type': '1602',
'name': '',
'report_id': '1027093266',
'status_temp_format': 'C',
'time': '2023/08/17 05:17:12',
'type': '',
'user': '',
'zone': 0,
}),
dict({
'area': 1,
'cid': '18180701000',
'cid_source': 'DEVICE',
'event_time': None,
'event_type': '1807',
'name': '**REDACTED**',
'report_id': '1026912623',
'status_temp_format': 'C',
'time': '2023/08/16 20:29:36',
'type': 'device_type.door_lock',
'user': 0,
'zone': 1,
}),
]),
'MODE': list([
dict({
'area': '1',
'mode': 'disarm',
}),
]),
'ONLINE': 'online',
'PANEL INFO': dict({
'SMS_Balance': '50',
'contact': '',
'dealer_name': 'Poland',
'mac': '**REDACTED**',
'mail_address': '**REDACTED**',
'name': '',
'net_version': 'MINIGW-MZ-1_G 1.0.1.29A',
'phone': 'UK-01902364606 / Sweden-0770373710 / Demark-89887818 / Norway-81569036',
'report_account': '**REDACTED**',
'rf51_version': '',
'service_time': 'UK - Mon to Fri 8:30 til 17:30 / Scandinavia - Mon to Fri 8:00 til 20:00, Sat to Sun 10:00 til 15:00',
'version': 'MINIGW-MZ-1_G 1.0.1.29A,,4.1.2.6.2,00:1D:94:0B:5E:A7,10111112,ML_yamga',
'voice_balance': '0',
'xml_version': '2',
'zb_version': '4.1.2.6.2',
'zw_version': '',
}),
'STATUS': dict({
'acfail': 'main.normal',
'battery': 'main.normal',
'gsm_rssi': '0',
'imei': '',
'imsi': '',
'jam': 'main.normal',
'rssi': '1',
'tamper': 'main.normal',
}),
})
# ---

View file

@ -0,0 +1,24 @@
"""Test Yale Smart Living diagnostics."""
from __future__ import annotations
from syrupy.assertion import SnapshotAssertion
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.typing import ClientSessionGenerator
async def test_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
load_config_entry: ConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test generating diagnostics for a config entry."""
entry = load_config_entry
diag = await get_diagnostics_for_config_entry(hass, hass_client, entry)
assert diag == snapshot