Skip to content

Commit b7a24a7

Browse files
committed
zwave-siren ZSE50 nil checks
1 parent ad0bc7c commit b7a24a7

File tree

1 file changed

+10
-9
lines changed
  • drivers/SmartThings/zwave-siren/src/zooz-zse50

1 file changed

+10
-9
lines changed

drivers/SmartThings/zwave-siren/src/zooz-zse50/init.lua

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,22 @@ end
4444

4545
local function playTone(device, tone_id)
4646
local tones_list = device:get_field("TONES_LIST")
47-
local default_tone = device:get_field("TONE_DEFAULT")
47+
local default_tone = device:get_field("TONE_DEFAULT") or 1
4848
local playbackMode = tonumber(device.preferences.playbackMode)
49-
local duration
50-
if tone_id > 0 then
49+
local duration = 0
50+
51+
if playbackMode == 1 then
52+
duration = device.preferences.playbackDuration
53+
elseif playbackMode == 2 then
54+
duration = duration * device.preferences.playbackLoop
55+
elseif tones_list ~= nil and tone_id > 0 then
5156
if tone_id == 0xFF then
5257
duration = tones_list[tonumber(default_tone)].duration
5358
else
5459
duration = tones_list[tonumber(tone_id)].duration
5560
end
56-
if playbackMode == 1 then
57-
duration = device.preferences.playbackDuration
58-
elseif playbackMode == 2 then
59-
duration = duration * device.preferences.playbackLoop
60-
end
6161
end
62+
6263
log.info(string.format("Playing Tone: %s, playbackMode %s, duration %ss", tone_id, playbackMode, duration))
6364

6465
device:send(SoundSwitch:TonePlaySet({ tone_identifier = tone_id }))
@@ -197,7 +198,7 @@ local function tone_playing(self, device, tone_id)
197198
device:emit_event(capabilities.chime.chime.off())
198199
device:emit_event(capabilities.mode.mode("Off"))
199200
else
200-
local toneInfo = tones_list[tone_id] or { name = "Unknown", duration = "0" }
201+
local toneInfo = (tones_list or {})[tone_id] or { name = "Unknown", duration = "0" }
201202
local modeName = getModeName(tone_id, toneInfo)
202203
device:emit_event(capabilities.alarm.alarm.both())
203204
device:emit_event(capabilities.chime.chime.chime())

0 commit comments

Comments
 (0)