|
44 | 44 |
|
45 | 45 | local function playTone(device, tone_id) |
46 | 46 | 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 |
48 | 48 | 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 |
51 | 56 | if tone_id == 0xFF then |
52 | 57 | duration = tones_list[tonumber(default_tone)].duration |
53 | 58 | else |
54 | 59 | duration = tones_list[tonumber(tone_id)].duration |
55 | 60 | end |
56 | | - if playbackMode == 1 then |
57 | | - duration = device.preferences.playbackDuration |
58 | | - elseif playbackMode == 2 then |
59 | | - duration = duration * device.preferences.playbackLoop |
60 | | - end |
61 | 61 | end |
| 62 | + |
62 | 63 | log.info(string.format("Playing Tone: %s, playbackMode %s, duration %ss", tone_id, playbackMode, duration)) |
63 | 64 |
|
64 | 65 | device:send(SoundSwitch:TonePlaySet({ tone_identifier = tone_id })) |
@@ -197,7 +198,7 @@ local function tone_playing(self, device, tone_id) |
197 | 198 | device:emit_event(capabilities.chime.chime.off()) |
198 | 199 | device:emit_event(capabilities.mode.mode("Off")) |
199 | 200 | 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" } |
201 | 202 | local modeName = getModeName(tone_id, toneInfo) |
202 | 203 | device:emit_event(capabilities.alarm.alarm.both()) |
203 | 204 | device:emit_event(capabilities.chime.chime.chime()) |
|
0 commit comments