Skip to content

Commit

Permalink
Merge pull request #751 from SmartThingsCommunity/bugfix/BUG-7770
Browse files Browse the repository at this point in the history
BUG-7770 Use Basic sets for Fibaro Single Switch
  • Loading branch information
greens authored Jun 5, 2023
2 parents beba748 + b193cfe commit 019c340
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
18 changes: 18 additions & 0 deletions drivers/SmartThings/zwave-switch/src/fibaro-single-switch/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
-- See the License for the specific language governing permissions and
-- limitations under the License.

local capabilities = require "st.capabilities"
local ButtonDefaults = require "st.zwave.defaults.button"
local EnergyMeterDefaults = require "st.zwave.defaults.energyMeter"
local PowerMeterDefaults = require "st.zwave.defaults.powerMeter"
Expand All @@ -24,6 +25,8 @@ local CentralScene = (require "st.zwave.CommandClass.CentralScene")({ version=1
local Meter = (require "st.zwave.CommandClass.Meter")({ version=3 })
--- @type st.zwave.CommandClass.SwitchBinary
local SwitchBinary = (require "st.zwave.CommandClass.SwitchBinary")({ version = 2 })
--- @type st.zwave.CommandClass.Basic
local Basic = (require "st.zwave.CommandClass.Basic")({ version=1 })

local FIBARO_SINGLE_SWITCH_FINGERPRINTS = {
{mfr = 0x010F, prod = 0x0403, model = 0x1000}, -- Fibaro Switch
Expand All @@ -46,6 +49,15 @@ local function central_scene_notification_handler(self, device, cmd)
end
end

-- Device appears to not handle SwitchMultilevel commands despite reporting that the CC
-- is supported. DTH uses basic so that is replicated here. For similar behavior see the
-- Aeotec Smart Switch driver
local function switch_handler_factory(value)
return function(driver, device, cmd)
device:send(Basic:Set({value=value}))
end
end

local function meter_report_handler(self, device, cmd)
if cmd.src_channel == nil or cmd.src_channel == 0 then
if cmd.args.scale == Meter.scale.electric_meter.KILOWATT_HOURS then
Expand Down Expand Up @@ -75,6 +87,12 @@ local fibaro_single_switch = {
[SwitchBinary.REPORT] = switch_binary_report_handler
}
},
capability_handlers = {
[capabilities.switch.ID] = {
[capabilities.switch.commands.on.NAME] = switch_handler_factory(0xFF),
[capabilities.switch.commands.off.NAME] = switch_handler_factory(0x00),
}
},
can_handle = can_handle_fibaro_single_switch,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ local CentralScene = (require "st.zwave.CommandClass.CentralScene")({version=1})
local Configuration = (require "st.zwave.CommandClass.Configuration")({version=1})
local Meter = (require "st.zwave.CommandClass.Meter")({version=3})
local SwitchBinary = (require "st.zwave.CommandClass.SwitchBinary")({version=2})
local Basic = (require "st.zwave.CommandClass.Basic")({ version=1 })

-- supported comand classes
local sensor_endpoints = {
Expand Down Expand Up @@ -48,6 +49,42 @@ local function test_init()
end
test.set_test_init_function(test_init)

test.register_coroutine_test(
"Device should use Basic SETs despite supporting Switch Multilevel (on)",
function ()
test.socket.capability:__queue_receive({
mock_device.id,
{ capability = "switch", command = "on", args = {}}
})
test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
mock_device,
Basic:Set({
value = 0xFF
})
)
)
end
)

test.register_coroutine_test(
"Device should use Basic SETs despite supporting Switch Multilevel (off)",
function ()
test.socket.capability:__queue_receive({
mock_device.id,
{ capability = "switch", command = "off", args = {}}
})
test.socket.zwave:__expect_send(
zw_test_utils.zwave_test_build_send_command(
mock_device,
Basic:Set({
value = 0x00
})
)
)
end
)

test.register_message_test(
"Switch Binary report ON_ENABLE should be handled",
{
Expand Down Expand Up @@ -425,7 +462,7 @@ test.register_message_test(
)

test.register_message_test(
"Energy meter report from source channel 2 should be discarded",
"Energy meter report from source channel 2 should be discarded",
{
{
channel = "zwave",
Expand Down

0 comments on commit 019c340

Please sign in to comment.