|
| 1 | +-- Copyright 2026 SmartThings, Inc. |
| 2 | +-- Licensed under the Apache License, Version 2.0 |
| 3 | + |
| 4 | +local test = require "integration_test" |
| 5 | +local clusters = require "st.zigbee.zcl.clusters" |
| 6 | +local capabilities = require "st.capabilities" |
| 7 | +local t_utils = require "integration_test.utils" |
| 8 | +local zigbee_test_utils = require "integration_test.zigbee_test_utils" |
| 9 | + |
| 10 | +local IASZone = clusters.IASZone |
| 11 | + |
| 12 | +local mock_device = test.mock_device.build_test_zigbee_device( |
| 13 | + { profile = t_utils.get_profile_definition("smoke-battery-tamper-no-fw-update.yml"), |
| 14 | + zigbee_endpoints = { |
| 15 | + [0x01] = { |
| 16 | + id = 0x01, |
| 17 | + manufacturer = "MultIR", |
| 18 | + model = "MIR-SM200", |
| 19 | + server_clusters = { 0x0001,0x0020, 0x0500, 0x0502 } |
| 20 | + } |
| 21 | + } |
| 22 | + } |
| 23 | +) |
| 24 | + |
| 25 | +zigbee_test_utils.prepare_zigbee_env_info() |
| 26 | + |
| 27 | +local function test_init() |
| 28 | + test.mock_device.add_test_device(mock_device) |
| 29 | +end |
| 30 | + |
| 31 | +test.set_test_init_function(test_init) |
| 32 | + |
| 33 | +test.register_coroutine_test( |
| 34 | + "Handle added lifecycle", |
| 35 | + function() |
| 36 | + test.socket.zigbee:__set_channel_ordering("relaxed") |
| 37 | + test.socket.capability:__set_channel_ordering("relaxed") |
| 38 | + test.socket.device_lifecycle:__queue_receive({ mock_device.id, "added" }) |
| 39 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", |
| 40 | + capabilities.battery.battery(100))) |
| 41 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", |
| 42 | + capabilities.smokeDetector.smoke.clear())) |
| 43 | + test.socket.capability:__expect_send(mock_device:generate_test_message("main", |
| 44 | + capabilities.tamperAlert.tamper.clear())) |
| 45 | + end, |
| 46 | + { |
| 47 | + min_api_version = 19 |
| 48 | + } |
| 49 | +) |
| 50 | + |
| 51 | +test.register_message_test( |
| 52 | + "Reported ZoneStatus should be handled: smoke/clear tamper/clear", |
| 53 | + { |
| 54 | + { |
| 55 | + channel = "zigbee", |
| 56 | + direction = "receive", |
| 57 | + message = { mock_device.id, IASZone.attributes.ZoneStatus:build_test_attr_report(mock_device, 0x0000) } |
| 58 | + }, |
| 59 | + { |
| 60 | + channel = "capability", |
| 61 | + direction = "send", |
| 62 | + message = mock_device:generate_test_message("main", capabilities.smokeDetector.smoke.clear()) |
| 63 | + }, |
| 64 | + { |
| 65 | + channel = "capability", |
| 66 | + direction = "send", |
| 67 | + message = mock_device:generate_test_message("main", capabilities.tamperAlert.tamper.clear()) |
| 68 | + } |
| 69 | + }, |
| 70 | + { |
| 71 | + min_api_version = 19 |
| 72 | + } |
| 73 | +) |
| 74 | + |
| 75 | +test.register_message_test( |
| 76 | + "Reported ZoneStatus should be handled: smoke/detected tamper/detected", |
| 77 | + { |
| 78 | + { |
| 79 | + channel = "zigbee", |
| 80 | + direction = "receive", |
| 81 | + message = { mock_device.id, IASZone.attributes.ZoneStatus:build_test_attr_report(mock_device, 0x0005) } |
| 82 | + }, |
| 83 | + { |
| 84 | + channel = "capability", |
| 85 | + direction = "send", |
| 86 | + message = mock_device:generate_test_message("main", capabilities.smokeDetector.smoke.detected()) |
| 87 | + }, |
| 88 | + { |
| 89 | + channel = "capability", |
| 90 | + direction = "send", |
| 91 | + message = mock_device:generate_test_message("main", capabilities.tamperAlert.tamper.detected()) |
| 92 | + } |
| 93 | + }, |
| 94 | + { |
| 95 | + min_api_version = 19 |
| 96 | + } |
| 97 | +) |
| 98 | + |
| 99 | +test.register_message_test( |
| 100 | + "Reported ZoneStatus should be handled: smoke/tested tamper/detected", |
| 101 | + { |
| 102 | + { |
| 103 | + channel = "zigbee", |
| 104 | + direction = "receive", |
| 105 | + message = { mock_device.id, IASZone.attributes.ZoneStatus:build_test_attr_report(mock_device, 0x0006) } |
| 106 | + }, |
| 107 | + { |
| 108 | + channel = "capability", |
| 109 | + direction = "send", |
| 110 | + message = mock_device:generate_test_message("main", capabilities.smokeDetector.smoke.tested()) |
| 111 | + }, |
| 112 | + { |
| 113 | + channel = "capability", |
| 114 | + direction = "send", |
| 115 | + message = mock_device:generate_test_message("main", capabilities.tamperAlert.tamper.detected()) |
| 116 | + } |
| 117 | + }, |
| 118 | + { |
| 119 | + min_api_version = 19 |
| 120 | + } |
| 121 | +) |
| 122 | + |
| 123 | +test.register_message_test( |
| 124 | + "ZoneStatusChangeNotification should be handled: smoke/detected tamper/detected", |
| 125 | + { |
| 126 | + { |
| 127 | + channel = "zigbee", |
| 128 | + direction = "receive", |
| 129 | + message = { mock_device.id, IASZone.client.commands.ZoneStatusChangeNotification.build_test_rx(mock_device, 0x0005, 0x00) } |
| 130 | + }, |
| 131 | + { |
| 132 | + channel = "capability", |
| 133 | + direction = "send", |
| 134 | + message = mock_device:generate_test_message("main", capabilities.smokeDetector.smoke.detected()) |
| 135 | + }, |
| 136 | + { |
| 137 | + channel = "capability", |
| 138 | + direction = "send", |
| 139 | + message = mock_device:generate_test_message("main", capabilities.tamperAlert.tamper.detected()) |
| 140 | + } |
| 141 | + }, |
| 142 | + { |
| 143 | + min_api_version = 19 |
| 144 | + } |
| 145 | +) |
| 146 | + |
| 147 | +test.register_message_test( |
| 148 | + "ZoneStatusChangeNotification should be handled: smoke/tested tamper/detected", |
| 149 | + { |
| 150 | + { |
| 151 | + channel = "zigbee", |
| 152 | + direction = "receive", |
| 153 | + message = { mock_device.id, IASZone.client.commands.ZoneStatusChangeNotification.build_test_rx(mock_device, 0x0006, 0x00) } |
| 154 | + }, |
| 155 | + { |
| 156 | + channel = "capability", |
| 157 | + direction = "send", |
| 158 | + message = mock_device:generate_test_message("main", capabilities.smokeDetector.smoke.tested()) |
| 159 | + }, |
| 160 | + { |
| 161 | + channel = "capability", |
| 162 | + direction = "send", |
| 163 | + message = mock_device:generate_test_message("main", capabilities.tamperAlert.tamper.detected()) |
| 164 | + } |
| 165 | + }, |
| 166 | + { |
| 167 | + min_api_version = 19 |
| 168 | + } |
| 169 | +) |
| 170 | + |
| 171 | +test.register_message_test( |
| 172 | + "ZoneStatusChangeNotification should be handled: smoke/clear tamper/clear", |
| 173 | + { |
| 174 | + { |
| 175 | + channel = "zigbee", |
| 176 | + direction = "receive", |
| 177 | + message = { mock_device.id, IASZone.client.commands.ZoneStatusChangeNotification.build_test_rx(mock_device, 0x0000, 0x00) } |
| 178 | + }, |
| 179 | + { |
| 180 | + channel = "capability", |
| 181 | + direction = "send", |
| 182 | + message = mock_device:generate_test_message("main", capabilities.smokeDetector.smoke.clear()) |
| 183 | + }, |
| 184 | + { |
| 185 | + channel = "capability", |
| 186 | + direction = "send", |
| 187 | + message = mock_device:generate_test_message("main", capabilities.tamperAlert.tamper.clear()) |
| 188 | + } |
| 189 | + }, |
| 190 | + { |
| 191 | + min_api_version = 19 |
| 192 | + } |
| 193 | +) |
| 194 | + |
| 195 | +test.run_registered_tests() |
0 commit comments