-
Notifications
You must be signed in to change notification settings - Fork 9
/
sound_switch_tone_play_report.ex
60 lines (48 loc) · 1.57 KB
/
sound_switch_tone_play_report.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
defmodule Grizzly.ZWave.Commands.SoundSwitchTonePlayReport do
@moduledoc """
This command is used to instruct a supporting node to play (or stop playing) a
tone.
## Params
* `:tone_identifier` - The tone identifier being played. If the value is 0,
no tone is currently being played OR the configured volume for the playing
tone is 0.
* `:volume` (v2) - The volume the tone is currently being played at.
"""
@behaviour Grizzly.ZWave.Command
alias Grizzly.ZWave.{Command, DecodeError}
alias Grizzly.ZWave.CommandClasses.SoundSwitch
@type param :: {:tone_identifier, 0..255}
@impl Grizzly.ZWave.Command
@spec new([param()]) :: {:ok, Command.t()}
def new(params) do
command = %Command{
name: :sound_switch_tone_play_report,
command_byte: 0x0A,
command_class: SoundSwitch,
params: params,
impl: __MODULE__
}
{:ok, command}
end
@impl Grizzly.ZWave.Command
@spec encode_params(Command.t()) :: binary()
def encode_params(command) do
tone_identifier = Command.param!(command, :tone_identifier)
volume = Command.param(command, :volume)
if is_nil(volume) do
# V1
<<tone_identifier::8>>
else
# V2
<<tone_identifier::8, volume::8>>
end
end
@impl Grizzly.ZWave.Command
@spec decode_params(binary()) :: {:ok, [param()]} | {:error, DecodeError.t()}
def decode_params(<<tone_identifier::8, volume::8>>) do
{:ok, [tone_identifier: tone_identifier, volume: volume]}
end
def decode_params(<<tone_identifier::8>>) do
{:ok, [tone_identifier: tone_identifier]}
end
end