Skip to content

Commit 2aa9869

Browse files
committed
add switch-fan profile
1 parent 08ea8eb commit 2aa9869

File tree

3 files changed

+93
-5
lines changed

3 files changed

+93
-5
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: switch-fan
2+
components:
3+
- id: main
4+
capabilities:
5+
- id: switch
6+
version: 1
7+
- id: fanMode
8+
version: 1
9+
- id: fanSpeedPercent
10+
version: 1
11+
- id: firmwareUpdate
12+
version: 1
13+
- id: refresh
14+
version: 1
15+
categories:
16+
- name: Switch

drivers/SmartThings/matter-switch/src/test/test_matter_light_fan.lua

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,44 @@ local mock_device = test.mock_device.build_test_matter_device({
6565
}
6666
})
6767

68+
local mock_device_switch = test.mock_device.build_test_matter_device({
69+
label = "Matter Switch",
70+
profile = t_utils.get_profile_definition("switch-fan.yml"),
71+
manufacturer_info = {
72+
vendor_id = 0x0000,
73+
product_id = 0x0000,
74+
},
75+
endpoints = {
76+
{
77+
endpoint_id = 0,
78+
clusters = {
79+
{cluster_id = clusters.Basic.ID, cluster_type = "SERVER"},
80+
},
81+
device_types = {
82+
{device_type_id = 0x0016, device_type_revision = 1} -- RootNode
83+
}
84+
},
85+
{
86+
endpoint_id = mock_device_ep1,
87+
clusters = {
88+
{cluster_id = clusters.OnOff.ID, cluster_type = "SERVER"},
89+
},
90+
device_types = {
91+
{device_type_id = 0x010A, device_type_revision = 2} -- On Off Plugin Unit
92+
}
93+
},
94+
{
95+
endpoint_id = mock_device_ep2,
96+
clusters = {
97+
{cluster_id = clusters.FanControl.ID, cluster_type = "SERVER", feature_map = 15},
98+
},
99+
device_types = {
100+
{device_type_id = 0x002B, device_type_revision = 1,} -- Fan
101+
}
102+
}
103+
}
104+
})
105+
68106
local CLUSTER_SUBSCRIBE_LIST ={
69107
clusters.OnOff.attributes.OnOff,
70108
clusters.LevelControl.attributes.CurrentLevel,
@@ -83,6 +121,13 @@ local CLUSTER_SUBSCRIBE_LIST ={
83121
clusters.FanControl.attributes.PercentCurrent,
84122
}
85123

124+
local SWITCH_CLUSTER_SUBSCRIBE_LIST ={
125+
clusters.OnOff.attributes.OnOff,
126+
clusters.FanControl.attributes.FanModeSequence,
127+
clusters.FanControl.attributes.FanMode,
128+
clusters.FanControl.attributes.PercentCurrent,
129+
}
130+
86131
local function test_init()
87132
test.disable_startup_messages()
88133
test.mock_device.add_test_device(mock_device)
@@ -104,6 +149,31 @@ end
104149

105150
test.set_test_init_function(test_init)
106151

152+
local function test_init_switch()
153+
test.disable_startup_messages()
154+
test.mock_device.add_test_device(mock_device_switch)
155+
local subscribe_request = SWITCH_CLUSTER_SUBSCRIBE_LIST[1]:subscribe(mock_device_switch)
156+
for i, clus in ipairs(SWITCH_CLUSTER_SUBSCRIBE_LIST) do
157+
if i > 1 then subscribe_request:merge(clus:subscribe(mock_device_switch)) end
158+
end
159+
160+
test.socket.device_lifecycle:__queue_receive({ mock_device_switch.id, "added" })
161+
test.socket.matter:__expect_send({mock_device_switch.id, subscribe_request})
162+
163+
test.socket.device_lifecycle:__queue_receive({ mock_device_switch.id, "init" })
164+
test.socket.matter:__expect_send({mock_device_switch.id, subscribe_request})
165+
166+
test.socket.device_lifecycle:__queue_receive({ mock_device_switch.id, "doConfigure" })
167+
mock_device_switch:expect_metadata_update({ profile = "switch-fan" })
168+
mock_device_switch:expect_metadata_update({ provisioning_state = "PROVISIONED" })
169+
end
170+
171+
test.register_message_test(
172+
"On Off Plug In Unit + Fan should profile as switch-fan",
173+
{},
174+
{ test_init = test_init_switch }
175+
)
176+
107177
test.register_coroutine_test(
108178
"Switch capability should send the appropriate commands", function()
109179
test.socket.capability:__queue_receive(

drivers/SmartThings/matter-switch/src/utils/device_configuration.lua

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,13 @@ function DeviceConfiguration.match_profile(driver, device)
177177
if switch_utils.tbl_contains(server_onoff_ep_ids, default_endpoint_id) then
178178
updated_profile = SwitchDeviceConfiguration.assign_profile_for_onoff_ep(device, default_endpoint_id)
179179
local generic_profile = function(s) return string.find(updated_profile or "", s, 1, true) end
180-
if generic_profile("plug-binary") or generic_profile("plug-level") then
180+
if (generic_profile("plug-binary") or generic_profile("light-binary")) and #device:get_endpoints(clusters.FanControl.ID) > 0 then
181+
updated_profile = "switch-fan"
182+
elseif generic_profile("light-color-level") and #device:get_endpoints(clusters.FanControl.ID) > 0 then
183+
updated_profile = "light-color-level-fan"
184+
elseif generic_profile("light-level") and #device:get_endpoints(clusters.OccupancySensing.ID) > 0 then
185+
updated_profile = "light-level-motion"
186+
elseif generic_profile("plug-binary") or generic_profile("plug-level") then
181187
if switch_utils.check_switch_category_vendor_overrides(device) then
182188
updated_profile = string.gsub(updated_profile, "plug", "switch")
183189
else
@@ -186,10 +192,6 @@ function DeviceConfiguration.match_profile(driver, device)
186192
if #embedded_cluster_utils.get_endpoints(device, clusters.ElectricalEnergyMeasurement.ID) > 0 then electrical_tags = electrical_tags .. "-energy-powerConsumption" end
187193
if electrical_tags ~= "" then updated_profile = string.gsub(updated_profile, "-binary", "") .. electrical_tags end
188194
end
189-
elseif generic_profile("light-color-level") and #device:get_endpoints(clusters.FanControl.ID) > 0 then
190-
updated_profile = "light-color-level-fan"
191-
elseif generic_profile("light-level") and #device:get_endpoints(clusters.OccupancySensing.ID) > 0 then
192-
updated_profile = "light-level-motion"
193195
elseif generic_profile("light-level-colorTemperature") or generic_profile("light-color-level") then
194196
-- ignore attempts to dynamically profile light-level-colorTemperature and light-color-level devices for now, since
195197
-- these may lose fingerprinted Kelvin ranges when dynamically profiled.

0 commit comments

Comments
 (0)