|
| 1 | +local test = require "integration_test" |
| 2 | +local t_utils = require "integration_test.utils" |
| 3 | +local capabilities = require "st.capabilities" |
| 4 | +local zigbee_test_utils = require "integration_test.zigbee_test_utils" |
| 5 | + |
| 6 | +local remoteControlStatus = capabilities.remoteControlStatus |
| 7 | +local antiLockStatus = capabilities["stse.antiLockStatus"] |
| 8 | +test.add_package_capability("antiLockStatus.yaml") |
| 9 | +local lockCredentialInfo = capabilities["stse.lockCredentialInfo"] |
| 10 | +test.add_package_capability("lockCredentialInfo.yaml") |
| 11 | +local lockAlarm = capabilities["lockAlarm"] |
| 12 | +test.add_package_capability("lockAlarm.yaml") |
| 13 | +local Battery = capabilities.battery |
| 14 | +local BatteryLevel = capabilities.batteryLevel |
| 15 | +local Lock = capabilities.lock |
| 16 | + |
| 17 | +local PRI_CLU = 0xFCC0 |
| 18 | + |
| 19 | +local HOST_COUNT = "__host_count" |
| 20 | +local PERSIST_DATA = "__persist_area" |
| 21 | + |
| 22 | +local mock_device = test.mock_device.build_test_zigbee_device( |
| 23 | + { |
| 24 | + profile = t_utils.get_profile_definition("aqara-lock-battery.yml"), |
| 25 | + fingerprinted_endpoint_id = 0x01, |
| 26 | + zigbee_endpoints = { |
| 27 | + [1] = { |
| 28 | + id = 1, |
| 29 | + manufacturer = "Lumi", |
| 30 | + model = "aqara.lock.akr001", |
| 31 | + server_clusters = { PRI_CLU } |
| 32 | + } |
| 33 | + } |
| 34 | + } |
| 35 | +) |
| 36 | + |
| 37 | +zigbee_test_utils.prepare_zigbee_env_info() |
| 38 | +local function test_init() |
| 39 | + local SUPPORTED_ALARM_VALUES = { "damaged", "forcedOpeningAttempt", "unableToLockTheDoor", "notClosedForALongTime", |
| 40 | + "highTemperature", "attemptsExceeded" } |
| 41 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", |
| 42 | + lockAlarm.supportedAlarmValues(SUPPORTED_ALARM_VALUES, { visibility = { displayed = false } }))) |
| 43 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", |
| 44 | + Lock.supportedUnlockDirections({"fromInside", "fromOutside"}, { visibility = { displayed = false } }))) |
| 45 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", Battery.type("AA"))) |
| 46 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", BatteryLevel.type("AA"))) |
| 47 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", Battery.quantity(6))) |
| 48 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", BatteryLevel.quantity(6))) |
| 49 | + local credentialInfoData = { |
| 50 | + { credentialId = 1, credentialType = "keypad", userId = "1", userLabel = "june", userType = "host" } |
| 51 | + } |
| 52 | + mock_device:set_field(PERSIST_DATA, credentialInfoData, { persist = true }) |
| 53 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", |
| 54 | + lockCredentialInfo.credentialInfo(credentialInfoData, { visibility = { displayed = false } }))) |
| 55 | + test.mock_device.add_test_device(mock_device) |
| 56 | +end |
| 57 | +test.set_test_init_function(test_init) |
| 58 | + |
| 59 | +test.register_coroutine_test( |
| 60 | + "Handle added lifecycle - only regular user", |
| 61 | + function() |
| 62 | + mock_device:set_field(HOST_COUNT, 1, { persist = true }) |
| 63 | + test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" }) |
| 64 | + |
| 65 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", |
| 66 | + remoteControlStatus.remoteControlEnabled('true', { visibility = { displayed = false } }))) |
| 67 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", Battery.battery(100))) |
| 68 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", BatteryLevel.battery("normal"))) |
| 69 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", |
| 70 | + lockAlarm.alarm.clear({ visibility = { displayed = false } }))) |
| 71 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", |
| 72 | + antiLockStatus.antiLockStatus('unknown', { visibility = { displayed = false } }))) |
| 73 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", Lock.lock("locked"))) |
| 74 | + end |
| 75 | +) |
| 76 | + |
| 77 | +test.run_registered_tests() |
0 commit comments