|
| 1 | +-- Copyright 2025 SmartThings |
| 2 | +-- |
| 3 | +-- Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +-- you may not use this file except in compliance with the License. |
| 5 | +-- You may obtain a copy of the License at |
| 6 | +-- |
| 7 | +-- http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +-- |
| 9 | +-- Unless required by applicable law or agreed to in writing, software |
| 10 | +-- distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +-- See the License for the specific language governing permissions and |
| 13 | +-- limitations under the License. |
| 14 | + |
| 15 | +-- Mock out globals |
| 16 | +local test = require "integration_test" |
| 17 | +local clusters = require "st.zigbee.zcl.clusters" |
| 18 | +local capabilities = require "st.capabilities" |
| 19 | +local t_utils = require "integration_test.utils" |
| 20 | +local zigbee_test_utils = require "integration_test.zigbee_test_utils" |
| 21 | + |
| 22 | +local IASZone = clusters.IASZone |
| 23 | +local PowerConfiguration = clusters.PowerConfiguration |
| 24 | +local ZoneStatusAttribute = IASZone.attributes.ZoneStatus |
| 25 | + |
| 26 | +local mock_device = test.mock_device.build_test_zigbee_device( |
| 27 | + { |
| 28 | + profile = t_utils.get_profile_definition("range-extender-battery-source.yml"), |
| 29 | + zigbee_endpoints = { |
| 30 | + [0x01] = { |
| 31 | + id = 0x01, |
| 32 | + manufacturer = "frient A/S", |
| 33 | + model = "REXZB-111", |
| 34 | + server_clusters = {IASZone.ID, PowerConfiguration.ID } |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | +) |
| 39 | + |
| 40 | +zigbee_test_utils.prepare_zigbee_env_info() |
| 41 | +local function test_init() |
| 42 | + test.mock_device.add_test_device(mock_device) |
| 43 | +end |
| 44 | + |
| 45 | +test.set_test_init_function(test_init) |
| 46 | + |
| 47 | +test.register_coroutine_test( |
| 48 | + "Refresh necessary attributes", |
| 49 | + function() |
| 50 | + test.socket.zigbee:__set_channel_ordering("relaxed") |
| 51 | + test.socket.capability:__queue_receive({ mock_device.id, { capability = "refresh", component = "main", command = "refresh", args = {} } }) |
| 52 | + test.socket.zigbee:__expect_send( |
| 53 | + { |
| 54 | + mock_device.id, |
| 55 | + IASZone.attributes.ZoneStatus:read(mock_device) |
| 56 | + } |
| 57 | + ) |
| 58 | + test.socket.zigbee:__expect_send( |
| 59 | + { |
| 60 | + mock_device.id, |
| 61 | + PowerConfiguration.attributes.BatteryVoltage:read(mock_device) |
| 62 | + } |
| 63 | + ) |
| 64 | + end |
| 65 | +) |
| 66 | + |
| 67 | +test.register_coroutine_test( |
| 68 | + "lifecycles - init and doConfigure test", |
| 69 | + function() |
| 70 | + test.socket.device_lifecycle:__queue_receive({ mock_device.id, "init" }) |
| 71 | + test.wait_for_events() |
| 72 | + test.socket.device_lifecycle:__queue_receive({ mock_device.id, "doConfigure" }) |
| 73 | + |
| 74 | + test.socket.zigbee:__expect_send({ |
| 75 | + mock_device.id, |
| 76 | + PowerConfiguration.attributes.BatteryVoltage:read( mock_device ) |
| 77 | + }) |
| 78 | + |
| 79 | + test.socket.zigbee:__expect_send({ |
| 80 | + mock_device.id, |
| 81 | + IASZone.attributes.ZoneStatus:read( mock_device ) |
| 82 | + }) |
| 83 | + |
| 84 | + test.socket.zigbee:__expect_send({ |
| 85 | + mock_device.id, |
| 86 | + zigbee_test_utils.build_bind_request( |
| 87 | + mock_device, |
| 88 | + zigbee_test_utils.mock_hub_eui, |
| 89 | + PowerConfiguration.ID |
| 90 | + ) |
| 91 | + }) |
| 92 | + |
| 93 | + test.socket.zigbee:__expect_send({ |
| 94 | + mock_device.id, |
| 95 | + PowerConfiguration.attributes.BatteryVoltage:configure_reporting( |
| 96 | + mock_device, |
| 97 | + 30, |
| 98 | + 21600, |
| 99 | + 1 |
| 100 | + ) |
| 101 | + }) |
| 102 | + |
| 103 | + mock_device:expect_metadata_update({ provisioning_state = "PROVISIONED" }) |
| 104 | + |
| 105 | + end |
| 106 | +) |
| 107 | + |
| 108 | +test.register_message_test( |
| 109 | + "Power source / mains should be handled", |
| 110 | + { |
| 111 | + { |
| 112 | + channel = "zigbee", |
| 113 | + direction = "receive", |
| 114 | + message = { mock_device.id, ZoneStatusAttribute:build_test_attr_report(mock_device, 0x0001) } |
| 115 | + }, |
| 116 | + { |
| 117 | + channel = "capability", |
| 118 | + direction = "send", |
| 119 | + message = mock_device:generate_test_message("main", capabilities.powerSource.powerSource.mains()) |
| 120 | + } |
| 121 | + } |
| 122 | +) |
| 123 | + |
| 124 | +test.register_message_test( |
| 125 | + "Power source / battery should be handled", |
| 126 | + { |
| 127 | + { |
| 128 | + channel = "zigbee", |
| 129 | + direction = "receive", |
| 130 | + message = { mock_device.id, ZoneStatusAttribute:build_test_attr_report(mock_device, 0x0081) } |
| 131 | + }, |
| 132 | + { |
| 133 | + channel = "capability", |
| 134 | + direction = "send", |
| 135 | + message = mock_device:generate_test_message("main", capabilities.powerSource.powerSource.battery()) |
| 136 | + } |
| 137 | + } |
| 138 | +) |
| 139 | + |
| 140 | +test.register_message_test( |
| 141 | + "Min battery voltage report should be handled", |
| 142 | + { |
| 143 | + { |
| 144 | + channel = "zigbee", |
| 145 | + direction = "receive", |
| 146 | + message = { mock_device.id, PowerConfiguration.attributes.BatteryVoltage:build_test_attr_report(mock_device, 33) } |
| 147 | + }, |
| 148 | + { |
| 149 | + channel = "capability", |
| 150 | + direction = "send", |
| 151 | + message = mock_device:generate_test_message("main", capabilities.battery.battery(0)) |
| 152 | + } |
| 153 | + } |
| 154 | +) |
| 155 | + |
| 156 | +test.register_message_test( |
| 157 | + "Medium battery voltage report should be handled", |
| 158 | + { |
| 159 | + { |
| 160 | + channel = "zigbee", |
| 161 | + direction = "receive", |
| 162 | + message = { mock_device.id, PowerConfiguration.attributes.BatteryVoltage:build_test_attr_report(mock_device, 37) } |
| 163 | + }, |
| 164 | + { |
| 165 | + channel = "capability", |
| 166 | + direction = "send", |
| 167 | + message = mock_device:generate_test_message("main", capabilities.battery.battery(50)) |
| 168 | + } |
| 169 | + } |
| 170 | +) |
| 171 | + |
| 172 | +test.register_message_test( |
| 173 | + "Max battery voltage report should be handled", |
| 174 | + { |
| 175 | + { |
| 176 | + channel = "zigbee", |
| 177 | + direction = "receive", |
| 178 | + message = { mock_device.id, PowerConfiguration.attributes.BatteryVoltage:build_test_attr_report(mock_device, 41) } |
| 179 | + }, |
| 180 | + { |
| 181 | + channel = "capability", |
| 182 | + direction = "send", |
| 183 | + message = mock_device:generate_test_message("main", capabilities.battery.battery(100)) |
| 184 | + } |
| 185 | + } |
| 186 | +) |
| 187 | + |
| 188 | +test.run_registered_tests() |
0 commit comments