/
alarm_event_supported_get.ex
50 lines (41 loc) · 1.21 KB
/
alarm_event_supported_get.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
defmodule Grizzly.ZWave.Commands.AlarmEventSupportedGet do
@moduledoc """
This command is used to request the supported Notifications for a specified
Notification Type.
Params:
* `:type` - a type of notification
"""
@behaviour Grizzly.ZWave.Command
alias Grizzly.ZWave.{Command, DecodeError, Notifications}
alias Grizzly.ZWave.CommandClasses.Alarm
@type param :: {:type, atom()}
@impl true
def new(params) do
command = %Command{
name: :alarm_event_supported_get,
command_byte: 0x01,
command_class: Alarm,
params: params,
impl: __MODULE__
}
{:ok, command}
end
@impl true
@spec encode_params(Command.t()) :: binary()
def encode_params(command) do
type = Command.param!(command, :type)
type_byte = Notifications.type_to_byte(type)
<<type_byte>>
end
@impl true
@spec decode_params(binary()) :: {:ok, [param()]} | {:error, DecodeError.t()}
def decode_params(<<type_byte>>) do
with {:ok, type} <- Notifications.type_from_byte(type_byte) do
{:ok, [type: type]}
else
{:error, :invalid_type_byte} ->
{:error,
%DecodeError{value: type_byte, param: :type, command: :alarm_event_supported_get}}
end
end
end