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

Add Confio Zigbee Device Drivers for Certification #1386

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
on:
pull_request:
types:
- opened
branches:
- 'releases/**'
11 changes: 11 additions & 0 deletions drivers/SmartThings/zigbee-switch/fingerprints.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
zigbeeManufacturer:
#Confio
- id: "Confio/CT4RZB"
deviceLabel: Confio Switch 1
manufacturer: Confio
model: CT4RZB
deviceProfileName: basic-switch
- id: "Confio/CT2ADZB"
deviceLabel: Confio Dimmer 1
manufacturer: Confio
model: CT2ADZB
deviceProfileName: on-off-level
#SMARTvill
- id: "SMARTvill/SLA06"
deviceLabel: "SMARTvill Switch 1"
Expand Down
116 changes: 116 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/confio-dimmer/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
-- Copyright 2023 SmartThings
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

local stDevice = require "st.device"
local zcl_clusters = require "st.zigbee.zcl.clusters"
local capabilities = require "st.capabilities"

local Level = zcl_clusters.Level

local FINGERPRINTS = {
{ mfr = "Confio", model = "CT2ADZB", children = 1 }
}

local function can_handle_confio_dimmer(opts, driver, device, ...)
for _, fingerprint in ipairs(FINGERPRINTS) do
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
local subdriver = require("confio-dimmer")
return true, subdriver
end
end
return false
end

local function get_children_amount(device)
for _, fingerprint in ipairs(FINGERPRINTS) do
if device:get_model() == fingerprint.model then
return fingerprint.children
end
end
end

local function find_child(parent, ep_id)
return parent:get_child_by_parent_assigned_key(string.format("%02X", ep_id))
end

local function create_child_devices(driver, device)
local children_amount = get_children_amount(device)
for i = 2, children_amount + 1, 1 do
local device_name_without_number = string.sub(device.label, 0,-2)
local name = string.format("%s%d", device_name_without_number, i)
if find_child(device, i) == nil then
local metadata = {
type = "EDGE_CHILD",
label = name,
profile = "on-off-level",
parent_device_id = device.id,
parent_assigned_child_key = string.format("%02X", i),
vendor_provided_label = name,
}
driver:try_create_device(metadata)
end
end
device:refresh()
end

local function switch_on_handler(driver, device, command)
device:send_to_component(command.component, Level.server.commands.MoveToLevelWithOnOff(device, 254))
device:emit_event(capabilities.switch.switch.on())
end

local function switch_off_handler(driver, device, command)
device:send_to_component(command.component, Level.server.commands.MoveToLevelWithOnOff(device, 1))
device:emit_event(capabilities.switch.switch.off())
end

local function switch_level_handler(driver, device, command)
local level = command.args.level
device:send_to_component(command.component, Level.server.commands.MoveToLevelWithOnOff(device, math.floor(level/100.0 * 254)))
if level == 1 or level == 100 then
device:emit_event(level == 1 and capabilities.switch.switch.off() or capabilities.switch.switch.on())
elseif level > 1 and level < 100 then
device:emit_event(capabilities.switchLevel.level(level))
device:emit_event(capabilities.switch.switch.on())
end
end

local function device_added(driver, device)
if device.network_type ~= stDevice.NETWORK_TYPE_CHILD then
create_child_devices(driver, device)
end
end

local function device_init(driver, device, event)
device:set_find_child(find_child)
end

local zigbee_confio_dimmer = {
NAME = "Zigbee Confio Dimmer",
lifecycle_handlers = {
added = device_added,
init = device_init
},
capability_handlers = {
[capabilities.switch.ID] = {
[capabilities.switch.commands.on.NAME] = switch_on_handler,
[capabilities.switch.commands.off.NAME] = switch_off_handler
},
[capabilities.switchLevel.ID] = {
[capabilities.switchLevel.commands.setLevel.NAME] = switch_level_handler
}
},
can_handle = can_handle_confio_dimmer
}

return zigbee_confio_dimmer
135 changes: 135 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/confio4r/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
-- Copyright 2023 SmartThings
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

local stDevice = require "st.device"
local zcl_clusters = require "st.zigbee.zcl.clusters"
local capabilities = require "st.capabilities"

local OnOff = zcl_clusters.OnOff

local FINGERPRINTS = {
{ mfr = "Confio", model = "CT4RZB", children = 4 }
}

local function can_handle_confio4r_switch(opts, driver, device, ...)
for _, fingerprint in ipairs(FINGERPRINTS) do
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
local subdriver = require("confio4r")
return true, subdriver
end
end
return false
end

local function get_children_amount(device)
for _, fingerprint in ipairs(FINGERPRINTS) do
if device:get_model() == fingerprint.model then
return fingerprint.children
end
end
end

local function find_child(parent, ep_id)
return parent:get_child_by_parent_assigned_key(string.format("%02X", ep_id))
end

local function create_child_devices(driver, device)
local children_amount = get_children_amount(device)
for i = 2, children_amount + 1, 1 do
local device_name_without_number = string.sub(device.label, 0, -2)
local name
if i == 5 then
name = string.format("%sAll OnOff", device_name_without_number)
else
name = string.format("%s%d", device_name_without_number, i)
end
if find_child(device, i) == nil then
local metadata = {
type = "EDGE_CHILD",
label = name,
profile = "basic-switch",
parent_device_id = device.id,
parent_assigned_child_key = string.format("%02X", i),
vendor_provided_label = name,
}
driver:try_create_device(metadata)
end
end
device:refresh()
end


local function switch_All_On_Off_handler(driver, device, command)
local ep_num = 1
if command == "All On" then
device:send(OnOff.server.commands.On(device):to_endpoint(ep_num))
device:send(OnOff.server.commands.On(device):to_endpoint(ep_num+1))
device:send(OnOff.server.commands.On(device):to_endpoint(ep_num+2))
device:send(OnOff.server.commands.On(device):to_endpoint(ep_num+3))
device:emit_event(capabilities.switch.switch.on())
else
device:send(OnOff.server.commands.Off(device):to_endpoint(ep_num))
device:send(OnOff.server.commands.Off(device):to_endpoint(ep_num+1))
device:send(OnOff.server.commands.Off(device):to_endpoint(ep_num+2))
device:send(OnOff.server.commands.Off(device):to_endpoint(ep_num+3))
device:emit_event(capabilities.switch.switch.off())
end
end

local function switch_on_handler(driver, device, command)
device:send_to_component(command.component, zcl_clusters.OnOff.server.commands.On(device))
device:emit_event(capabilities.switch.switch.on())
local str = tostring(device)
local value_in_brackets = str:match("%[([%d%w]+)%]")
if value_in_brackets == "05" then
switch_All_On_Off_handler(driver, device, "All On")
end
end

local function switch_off_handler(driver, device, command)
device:send_to_component(command.component, zcl_clusters.OnOff.server.commands.Off(device))
device:emit_event(capabilities.switch.switch.off())
local str = tostring(device)
local value_in_brackets = str:match("%[([%d%w]+)%]")
if value_in_brackets == "05" then
switch_All_On_Off_handler(driver, device, "All Off")
end
end

local function device_added(driver, device)
if device.network_type ~= stDevice.NETWORK_TYPE_CHILD then
create_child_devices(driver, device)
end
end

local function device_init(driver, device, event)
device:set_find_child(find_child)
end

local Confio4rSwitch = {
NAME = "Zigbee Confio4r Switch",
lifecycle_handlers = {
added = device_added,
init = device_init
},
capability_handlers = {
[capabilities.switch.ID] = {
[capabilities.switch.commands.on.NAME] = switch_on_handler,
[capabilities.switch.commands.off.NAME] = switch_off_handler
}
},
can_handle = can_handle_confio4r_switch
}

return Confio4rSwitch
4 changes: 3 additions & 1 deletion drivers/SmartThings/zigbee-switch/src/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ local zigbee_switch_driver_template = {
lazy_load_if_possible("ge-link-bulb"),
lazy_load_if_possible("bad_on_off_data_type"),
lazy_load_if_possible("robb"),
lazy_load_if_possible("wallhero")
lazy_load_if_possible("wallhero"),
lazy_load_if_possible("confio4r"),
lazy_load_if_possible("confio-dimmer")
},
lifecycle_handlers = {
init = device_init,
Expand Down
10 changes: 10 additions & 0 deletions drivers/SmartThings/zigbee-window-treatment/fingerprints.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
zigbeeManufacturer:
- id: "Confio/CTCCZB"
deviceLabel: Confio Single Curtain
manufacturer: Confio
model: CTCCZB
deviceProfileName: window-treatment-confio
- id: "Confio/CT2CCZB"
deviceLabel: Confio Dual Curtain 1
manufacturer: Confio
model: CT2CCZB
deviceProfileName: window-treatment-confio
- id: "Vimar/xx594-roller-shutter"
deviceLabel: Vimar Smart Roller Shutter
manufacturer: Vimar
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: window-treatment-confio
components:
- id: main
capabilities:
- id: windowShade
version: 1
- id: windowShadeLevel
version: 1
- id: firmwareUpdate
version: 1
- id: refresh
version: 1
categories:
- name: Blind
preferences:
- name: "profileType"
title: "Child Profile Type"
description: "Child Profile Type: DO NOT CHANGE"
required: true
preferenceType: enumeration
definition:
options:
"shadeLevel": "window-treatment-confio"
default: "shadeLevel"
Loading
Loading