Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update profile selection logic to support plug/button devices #1799

Closed
24 changes: 24 additions & 0 deletions drivers/SmartThings/matter-switch/profiles/plug-2-button.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: plug-2-button
components:
- id: main
capabilities:
- id: switch
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: SmartPlug
- id: button
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button2
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
30 changes: 30 additions & 0 deletions drivers/SmartThings/matter-switch/profiles/plug-3-button.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: plug-3-button
components:
- id: main
capabilities:
- id: switch
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: SmartPlug
- id: button
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button2
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button3
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
36 changes: 36 additions & 0 deletions drivers/SmartThings/matter-switch/profiles/plug-4-button.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: plug-4-button
components:
- id: main
capabilities:
- id: switch
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: SmartPlug
- id: button
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button2
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button3
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button4
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
42 changes: 42 additions & 0 deletions drivers/SmartThings/matter-switch/profiles/plug-5-button.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: plug-5-button
components:
- id: main
capabilities:
- id: switch
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: SmartPlug
- id: button
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button2
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button3
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button4
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button5
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
48 changes: 48 additions & 0 deletions drivers/SmartThings/matter-switch/profiles/plug-6-button.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: plug-6-button
components:
- id: main
capabilities:
- id: switch
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: SmartPlug
- id: button
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button2
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button3
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button4
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button5
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button6
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
54 changes: 54 additions & 0 deletions drivers/SmartThings/matter-switch/profiles/plug-7-button.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: plug-7-button
components:
- id: main
capabilities:
- id: switch
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: SmartPlug
- id: button
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button2
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button3
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button4
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button5
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button6
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button7
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
60 changes: 60 additions & 0 deletions drivers/SmartThings/matter-switch/profiles/plug-8-button.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: plug-8-button
components:
- id: main
capabilities:
- id: switch
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: SmartPlug
- id: button
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button2
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button3
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button4
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button5
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button6
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button7
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
- id: button8
capabilities:
- id: button
version: 1
categories:
- name: RemoteController
31 changes: 21 additions & 10 deletions drivers/SmartThings/matter-switch/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -346,16 +346,20 @@ end
--- whether the device type for an endpoint is currently supported by a profile for
--- combination button/switch devices.
local function is_supported_combination_button_switch_device_type(device, endpoint_id)
for _, ep in ipairs(device.endpoints) do
if ep.endpoint_id == endpoint_id then
for _, dt in ipairs(ep.device_types) do
if dt.device_type_id == DIMMABLE_LIGHT_DEVICE_TYPE_ID then
return true
local switch_eps = device:get_endpoints(clusters.OnOff.ID)
local button_eps = device:get_endpoints(clusters.Switch.ID, {feature_bitmap=clusters.Switch.types.SwitchFeature.MOMENTARY_SWITCH})
if #switch_eps > 0 and #button_eps > 0 then
for _, ep in ipairs(device.endpoints) do
if ep.endpoint_id == endpoint_id then
for _, dt in ipairs(ep.device_types) do
if dt.device_type_id == DIMMABLE_LIGHT_DEVICE_TYPE_ID or dt.device_type_id == ON_OFF_PLUG_DEVICE_TYPE_ID then
return true, dt.device_type_id
end
end
end
end
end
return false
return false, nil
end

local function get_first_non_zero_endpoint(endpoints)
Expand Down Expand Up @@ -393,7 +397,8 @@ local function find_default_endpoint(device)
-- default endpoint.
if #switch_eps > 0 and #button_eps > 0 then
local main_endpoint = get_first_non_zero_endpoint(switch_eps)
if is_supported_combination_button_switch_device_type(device, main_endpoint) then
local is_supported_device_type, _ = is_supported_combination_button_switch_device_type(device, main_endpoint)
if is_supported_device_type then
return main_endpoint
else
device.log.warn("The main switch endpoint does not contain a supported device type for a component configuration with buttons")
Expand Down Expand Up @@ -571,11 +576,17 @@ local function initialize_switch(driver, device)
device:set_field(COMPONENT_TO_ENDPOINT_MAP_BUTTON, component_map, {persist = true})
end

if #button_eps > 0 and is_supported_combination_button_switch_device_type(device, main_endpoint) then
local is_supported_button_switch_device, device_type_id = is_supported_combination_button_switch_device_type(device, main_endpoint)
if is_supported_button_switch_device then
if device_type_id == DIMMABLE_LIGHT_DEVICE_TYPE_ID then
profile_name = "light-level"
else
profile_name = "plug"
end
if #button_eps == 1 then
profile_name = "light-level-button"
profile_name = profile_name .. "-button"
else
profile_name = "light-level" .. string.format("-%d-button", #button_eps)
profile_name = profile_name .. string.format("-%d-button", #button_eps)
end
device:try_update_metadata({profile = profile_name})
device:set_field(DEFERRED_CONFIGURE, true)
Expand Down
Loading
Loading