Skip to content
Open
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
4 changes: 2 additions & 2 deletions drivers/SmartThings/zigbee-switch/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'Zigbee Switch'
packageKey: 'zigbee-switch'
name: 'Zigbee Switch Optimized'
packageKey: 'zigbee-switch-opt'
permissions:
zigbee: {}
description: "SmartThings driver for Zigbee switch devices"
Expand Down
14 changes: 14 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/aqara-light/can_handle.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
return function(opts, driver, device)
local FINGERPRINTS = {
{ mfr = "LUMI", model = "lumi.light.acn004" },
{ mfr = "Aqara", model = "lumi.light.acn014" }
}

for _, fingerprint in ipairs(FINGERPRINTS) do
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
local subdriver = require("aqara-light")
return true, subdriver
end
end
return false
end
17 changes: 1 addition & 16 deletions drivers/SmartThings/zigbee-switch/src/aqara-light/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,6 @@ local PRIVATE_CLUSTER_ID = 0xFCC0
local PRIVATE_ATTRIBUTE_ID = 0x0009
local MFG_CODE = 0x115F

local FINGERPRINTS = {
{ mfr = "LUMI", model = "lumi.light.acn004" },
{ mfr = "Aqara", model = "lumi.light.acn014" }
}

local function is_aqara_products(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("aqara-light")
return true, subdriver
end
end
return false
end

local function do_refresh(self, device)
device:send(OnOff.attributes.OnOff:read(device))
device:send(Level.attributes.CurrentLevel:read(device))
Expand Down Expand Up @@ -65,7 +50,7 @@ local aqara_light_handler = {
[capabilities.switchLevel.commands.setLevel.NAME] = set_level_handler
}
},
can_handle = is_aqara_products
can_handle = require("aqara-light.can_handle"),
}

return aqara_light_handler
10 changes: 10 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/aqara/can_handle.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
return function(opts, driver, device)
local FINGERPRINTS = require("aqara.fingerprints")
for _, fingerprint in ipairs(FINGERPRINTS) do
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
local subdriver = require("aqara")
return true, subdriver
end
end
return false
end
19 changes: 19 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/aqara/fingerprints.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
return {
{ mfr = "LUMI", model = "lumi.plug.maeu01" },
{ mfr = "LUMI", model = "lumi.plug.macn01" },
{ mfr = "LUMI", model = "lumi.switch.n0agl1" },
{ mfr = "LUMI", model = "lumi.switch.l0agl1" },
{ mfr = "LUMI", model = "lumi.switch.n0acn2" },
{ mfr = "LUMI", model = "lumi.switch.n1acn1" },
{ mfr = "LUMI", model = "lumi.switch.n2acn1" },
{ mfr = "LUMI", model = "lumi.switch.n3acn1" },
{ mfr = "LUMI", model = "lumi.switch.b1laus01" },
{ mfr = "LUMI", model = "lumi.switch.b2laus01" },
{ mfr = "LUMI", model = "lumi.switch.n1aeu1" },
{ mfr = "LUMI", model = "lumi.switch.n2aeu1" },
{ mfr = "LUMI", model = "lumi.switch.l1aeu1" },
{ mfr = "LUMI", model = "lumi.switch.l2aeu1" },
{ mfr = "LUMI", model = "lumi.switch.b1nacn01" },
{ mfr = "LUMI", model = "lumi.switch.b2nacn01" },
{ mfr = "LUMI", model = "lumi.switch.b3n01" }
}
31 changes: 1 addition & 30 deletions drivers/SmartThings/zigbee-switch/src/aqara/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@ local ELECTRIC_SWITCH_TYPE_ATTRIBUTE_ID = 0x000A
local LAST_REPORT_TIME = "LAST_REPORT_TIME"
local PRIVATE_MODE = "PRIVATE_MODE"

local FINGERPRINTS = {
{ mfr = "LUMI", model = "lumi.plug.maeu01" },
{ mfr = "LUMI", model = "lumi.plug.macn01" },
{ mfr = "LUMI", model = "lumi.switch.n0agl1" },
{ mfr = "LUMI", model = "lumi.switch.l0agl1" },
{ mfr = "LUMI", model = "lumi.switch.n0acn2" },
{ mfr = "LUMI", model = "lumi.switch.n1acn1" },
{ mfr = "LUMI", model = "lumi.switch.n2acn1" },
{ mfr = "LUMI", model = "lumi.switch.n3acn1" },
{ mfr = "LUMI", model = "lumi.switch.b1laus01" },
{ mfr = "LUMI", model = "lumi.switch.b2laus01" },
{ mfr = "LUMI", model = "lumi.switch.n1aeu1" },
{ mfr = "LUMI", model = "lumi.switch.n2aeu1" },
{ mfr = "LUMI", model = "lumi.switch.l1aeu1" },
{ mfr = "LUMI", model = "lumi.switch.l2aeu1" },
{ mfr = "LUMI", model = "lumi.switch.b1nacn01" },
{ mfr = "LUMI", model = "lumi.switch.b2nacn01" },
{ mfr = "LUMI", model = "lumi.switch.b3n01" }
}

local preference_map = {
["stse.restorePowerState"] = {
cluster_id = PRIVATE_CLUSTER_ID,
Expand Down Expand Up @@ -137,15 +117,6 @@ local preference_map = {
},
}

local function is_aqara_products(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("aqara")
return true, subdriver
end
end
return false
end

local function private_mode_handler(driver, device, value, zb_rx)
device:set_field(PRIVATE_MODE, value.value, { persist = true })
Expand Down Expand Up @@ -286,7 +257,7 @@ local aqara_switch_handler = {
require("aqara.version"),
require("aqara.multi-switch")
},
can_handle = is_aqara_products
can_handle = require("aqara.can_handle"),
}

return aqara_switch_handler
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
return function(opts, driver, device)
local FINGERPRINTS = require("aqara.multi-switch.fingerprints")
for _, fingerprint in ipairs(FINGERPRINTS) do
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
return true, require("aqara.multi-switch")
end
end
return false
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
return {
{ mfr = "LUMI", model = "lumi.switch.n1acn1", children = 1, child_profile = "" },
{ mfr = "LUMI", model = "lumi.switch.n2acn1", children = 2, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.n3acn1", children = 3, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.b1laus01", children = 1, child_profile = "" },
{ mfr = "LUMI", model = "lumi.switch.b2laus01", children = 2, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.l2aeu1", children = 2, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.n2aeu1", children = 2, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.b2nacn01", children = 2, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.b3n01", children = 3, child_profile = "aqara-switch-child" }
}
24 changes: 2 additions & 22 deletions drivers/SmartThings/zigbee-switch/src/aqara/multi-switch/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,7 @@ local switch_utils = require "switch_utils"
local PRIVATE_CLUSTER_ID = 0xFCC0
local PRIVATE_ATTRIBUTE_ID = 0x0009
local MFG_CODE = 0x115F

local FINGERPRINTS = {
{ mfr = "LUMI", model = "lumi.switch.n1acn1", children = 1, child_profile = "" },
{ mfr = "LUMI", model = "lumi.switch.n2acn1", children = 2, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.n3acn1", children = 3, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.b1laus01", children = 1, child_profile = "" },
{ mfr = "LUMI", model = "lumi.switch.b2laus01", children = 2, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.l2aeu1", children = 2, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.n2aeu1", children = 2, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.b2nacn01", children = 2, child_profile = "aqara-switch-child" },
{ mfr = "LUMI", model = "lumi.switch.b3n01", children = 3, child_profile = "aqara-switch-child" }
}

local function is_aqara_products(opts, driver, device)
for _, fingerprint in ipairs(FINGERPRINTS) do
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
return true
end
end
return false
end
local FINGERPRINTS = require("aqara.multi-switch.fingerprints")

local function get_children_amount(device)
for _, fingerprint in ipairs(FINGERPRINTS) do
Expand Down Expand Up @@ -106,7 +86,7 @@ local aqara_multi_switch_handler = {
init = configurations.power_reconfig_wrapper(device_init),
added = device_added
},
can_handle = is_aqara_products
can_handle = require("aqara.multi-switch.can_handle"),
}

return aqara_multi_switch_handler
6 changes: 6 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/aqara/sub_drivers.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
local lazy_load = require "lazy_load_subdriver"

return {
lazy_load("aqara.multi-switch"),
lazy_load("aqara.version"),
}
10 changes: 10 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/aqara/version/can_handle.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
return function (opts, driver, device)
local PRIVATE_MODE = "PRIVATE_MODE"
local private_mode = device:get_field(PRIVATE_MODE) or 0
local res = private_mode == 1
if res then
return res, require("aqara.version")
else
return res
end
end
5 changes: 1 addition & 4 deletions drivers/SmartThings/zigbee-switch/src/aqara/version/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ local aqara_switch_version_handler = {
}
}
},
can_handle = function (opts, driver, device)
local private_mode = device:get_field(PRIVATE_MODE) or 0
return private_mode == 1
end
can_handle = require("aqara.version.can_handle")
}

return aqara_switch_version_handler
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

-- There are reports of at least one device (SONOFF 01MINIZB) which occasionally
-- reports this value as an Int8, rather than a Boolean, as per the spec
return function(opts, driver, device, zb_rx, ...)
local zcl_clusters = require "st.zigbee.zcl.clusters"
local data_types = require "st.zigbee.data_types"
local can_handle = opts.dispatcher_class == "ZigbeeMessageDispatcher" and
device:get_manufacturer() == "SONOFF" and
zb_rx.body and
zb_rx.body.zcl_body and
zb_rx.body.zcl_body.attr_records and
zb_rx.address_header.cluster.value == zcl_clusters.OnOff.ID and
zb_rx.body.zcl_body.attr_records[1].attr_id.value == zcl_clusters.OnOff.attributes.OnOff.ID and
zb_rx.body.zcl_body.attr_records[1].data_type.value ~= data_types.Boolean.ID
if can_handle then
local subdriver = require("bad_on_off_data_type")
return true, subdriver
else
return false
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,8 @@
-- limitations under the License.

local zcl_clusters = require "st.zigbee.zcl.clusters"
local data_types = require "st.zigbee.data_types"
local capabilities = require "st.capabilities"

-- There are reports of at least one device (SONOFF 01MINIZB) which occasionally
-- reports this value as an Int8, rather than a Boolean, as per the spec
local function incorrect_data_type_detected(opts, driver, device, zb_rx, ...)
local can_handle = opts.dispatcher_class == "ZigbeeMessageDispatcher" and
device:get_manufacturer() == "SONOFF" and
zb_rx.body and
zb_rx.body.zcl_body and
zb_rx.body.zcl_body.attr_records and
zb_rx.address_header.cluster.value == zcl_clusters.OnOff.ID and
zb_rx.body.zcl_body.attr_records[1].attr_id.value == zcl_clusters.OnOff.attributes.OnOff.ID and
zb_rx.body.zcl_body.attr_records[1].data_type.value ~= data_types.Boolean.ID
if can_handle then
local subdriver = require("bad_on_off_data_type")
return true, subdriver
else
return false
end
end

local function on_off_attr_handler(driver, device, value, zb_rx)
local attr = capabilities.switch.switch
device:emit_event_for_endpoint(zb_rx.address_header.src_endpoint.value, value.value == 0 and attr.off() or attr.on())
Expand All @@ -49,7 +29,7 @@ local bad_on_off_data_type = {
}
}
},
can_handle = incorrect_data_type_detected
can_handle = require("bad_on_off_data_type.can_handle"),
}

return bad_on_off_data_type
14 changes: 14 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/ezex/can_handle.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
return function(opts, driver, device)
local ZIGBEE_METERING_SWITCH_FINGERPRINTS = {
{ model = "E240-KR116Z-HA" }
}

for _, fingerprint in ipairs(ZIGBEE_METERING_SWITCH_FINGERPRINTS) do
if device:get_model() == fingerprint.model then
local subdriver = require("ezex")
return true, subdriver
end
end

return false
end
17 changes: 1 addition & 16 deletions drivers/SmartThings/zigbee-switch/src/ezex/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@
local zigbee_constants = require "st.zigbee.constants"
local configurations = require "configurations"

local ZIGBEE_METERING_SWITCH_FINGERPRINTS = {
{ model = "E240-KR116Z-HA" }
}

local is_zigbee_ezex_switch = function(opts, driver, device)
for _, fingerprint in ipairs(ZIGBEE_METERING_SWITCH_FINGERPRINTS) do
if device:get_model() == fingerprint.model then
local subdriver = require("ezex")
return true, subdriver
end
end

return false
end

local do_init = function(self, device)
device:set_field(zigbee_constants.SIMPLE_METERING_DIVISOR_KEY, 1000000, {persist = true})
device:set_field(zigbee_constants.ELECTRICAL_MEASUREMENT_DIVISOR_KEY, 1000, {persist = true})
Expand All @@ -40,7 +25,7 @@ local ezex_switch_handler = {
lifecycle_handlers = {
init = configurations.power_reconfig_wrapper(do_init)
},
can_handle = is_zigbee_ezex_switch
can_handle = require("ezex.can_handle"),
}

return ezex_switch_handler
11 changes: 11 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/frient/can_handle.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Function to determine if the driver can handle this device
return function(opts, driver, device, ...)
local FRIENT_SMART_PLUG_FINGERPRINTS = require("frient.fingerprints")
for _, fingerprint in ipairs(FRIENT_SMART_PLUG_FINGERPRINTS) do
if device:get_manufacturer() == fingerprint.mfr and device:get_model() == fingerprint.model then
local subdriver = require("frient")
return true, subdriver
end
end
return false
end
14 changes: 14 additions & 0 deletions drivers/SmartThings/zigbee-switch/src/frient/fingerprints.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
return {
{ mfr = "frient A/S", model = "SPLZB-131" },
{ mfr = "frient A/S", model = "SPLZB-132" },
{ mfr = "frient A/S", model = "SPLZB-134" },
{ mfr = "frient A/S", model = "SPLZB-137" },
{ mfr = "frient A/S", model = "SPLZB-141" },
{ mfr = "frient A/S", model = "SPLZB-142" },
{ mfr = "frient A/S", model = "SPLZB-144" },
{ mfr = "frient A/S", model = "SPLZB-147" },
{ mfr = "frient A/S", model = "SMRZB-143" },
{ mfr = "frient A/S", model = "SMRZB-153" },
{ mfr = "frient A/S", model = "SMRZB-332" },
{ mfr = "frient A/S", model = "SMRZB-342" },
}
Loading