|
| 1 | +-- Copyright 2026 SmartThings, Inc. |
| 2 | +-- Licensed under the Apache License, Version 2.0 |
| 3 | + |
| 4 | +-- Mock out globals |
| 5 | +local capabilities = require "st.capabilities" |
| 6 | +local clusters = require "st.zigbee.zcl.clusters" |
| 7 | +local t_utils = require "integration_test.utils" |
| 8 | +local test = require "integration_test" |
| 9 | +local zigbee_test_utils = require "integration_test.zigbee_test_utils" |
| 10 | + |
| 11 | +local IASZone = clusters.IASZone |
| 12 | + |
| 13 | +local button_attr = capabilities.button.button |
| 14 | +local PRIVATE_CMD_ID = 0xF1 |
| 15 | + |
| 16 | +local mock_device = test.mock_device.build_test_zigbee_device( |
| 17 | + { |
| 18 | + profile = t_utils.get_profile_definition("one-button-battery.yml"), |
| 19 | + zigbee_endpoints = { |
| 20 | + [1] = { |
| 21 | + id = 1, |
| 22 | + manufacturer = "MultIR", |
| 23 | + model = "MIR-SO100", |
| 24 | + server_clusters = {0x0000, 0x0001, 0x0003, 0x0020, 0x0500, 0x0B05} |
| 25 | + } |
| 26 | + } |
| 27 | + } |
| 28 | +) |
| 29 | + |
| 30 | +zigbee_test_utils.prepare_zigbee_env_info() |
| 31 | +local function test_init() |
| 32 | + test.mock_device.add_test_device(mock_device)end |
| 33 | + |
| 34 | +test.set_test_init_function(test_init) |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | +test.register_coroutine_test( |
| 39 | + "added lifecycle event", |
| 40 | + function() |
| 41 | + -- The initial button pushed event should be send during the device's first time onboarding |
| 42 | + test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" }) |
| 43 | + test.socket.capability:__set_channel_ordering("relaxed") |
| 44 | + test.socket.capability:__expect_send( |
| 45 | + mock_device:generate_test_message( |
| 46 | + "main", |
| 47 | + capabilities.button.supportedButtonValues({ "pushed","double","held" }, { visibility = { displayed = false } }) |
| 48 | + ) |
| 49 | + ) |
| 50 | + test.socket.capability:__expect_send( |
| 51 | + mock_device:generate_test_message( |
| 52 | + "main", |
| 53 | + capabilities.button.numberOfButtons({ value = 1 }, { visibility = { displayed = false } }) |
| 54 | + ) |
| 55 | + ) |
| 56 | + test.socket.capability:__expect_send({ |
| 57 | + mock_device.id, |
| 58 | + { |
| 59 | + capability_id = "button", component_id = "main", |
| 60 | + attribute_id = "button", state = { value = "pushed" } |
| 61 | + } |
| 62 | + }) |
| 63 | + -- Avoid sending the initial button pushed event after driver switch-over, as the switch-over event itself re-triggers the added lifecycle. |
| 64 | + test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" }) |
| 65 | + test.socket.capability:__set_channel_ordering("relaxed") |
| 66 | + test.socket.capability:__expect_send( |
| 67 | + mock_device:generate_test_message( |
| 68 | + "main", |
| 69 | + capabilities.button.supportedButtonValues({ "pushed","double","held" }, { visibility = { displayed = false } }) |
| 70 | + ) |
| 71 | + ) |
| 72 | + test.socket.capability:__expect_send( |
| 73 | + mock_device:generate_test_message( |
| 74 | + "main", |
| 75 | + capabilities.button.numberOfButtons({ value = 1 }, { visibility = { displayed = false } }) |
| 76 | + ) |
| 77 | + ) |
| 78 | + end, |
| 79 | + { |
| 80 | + min_api_version = 19 |
| 81 | + } |
| 82 | +) |
| 83 | + |
| 84 | +test.register_message_test( |
| 85 | + "IASZone cmd 0xF1 0x00 are handled", |
| 86 | + { |
| 87 | + { |
| 88 | + channel = "zigbee", |
| 89 | + direction = "receive", |
| 90 | + message = { mock_device.id, zigbee_test_utils.build_custom_command_id(mock_device, IASZone.ID, PRIVATE_CMD_ID, 0x0000, "\x00", 0x01) } |
| 91 | + }, |
| 92 | + { |
| 93 | + channel = "capability", |
| 94 | + direction = "send", |
| 95 | + message = mock_device:generate_test_message("main", capabilities.button.button.pushed({state_change = true})) |
| 96 | + } |
| 97 | + } |
| 98 | +) |
| 99 | + |
| 100 | +test.register_message_test( |
| 101 | + "IASZone cmd 0xF1 0x01 are handled", |
| 102 | + { |
| 103 | + { |
| 104 | + channel = "zigbee", |
| 105 | + direction = "receive", |
| 106 | + message = { mock_device.id, zigbee_test_utils.build_custom_command_id(mock_device, IASZone.ID, PRIVATE_CMD_ID, 0x0000, "\x01", 0x01) } |
| 107 | + }, |
| 108 | + { |
| 109 | + channel = "capability", |
| 110 | + direction = "send", |
| 111 | + message = mock_device:generate_test_message("main", capabilities.button.button.double({state_change = true})) |
| 112 | + } |
| 113 | + } |
| 114 | +) |
| 115 | + |
| 116 | +test.register_message_test( |
| 117 | + "IASZone cmd 0xF1 0x01 are handled", |
| 118 | + { |
| 119 | + { |
| 120 | + channel = "zigbee", |
| 121 | + direction = "receive", |
| 122 | + message = { mock_device.id, zigbee_test_utils.build_custom_command_id(mock_device, IASZone.ID, PRIVATE_CMD_ID, 0x0000, "\x80", 0x01) } |
| 123 | + }, |
| 124 | + { |
| 125 | + channel = "capability", |
| 126 | + direction = "send", |
| 127 | + message = mock_device:generate_test_message("main", capabilities.button.button.held({state_change = true})) |
| 128 | + } |
| 129 | + } |
| 130 | +) |
| 131 | + |
| 132 | +test.run_registered_tests() |
0 commit comments