-
Notifications
You must be signed in to change notification settings - Fork 9
/
sensor_multilevel_supported_scale_get.ex
46 lines (37 loc) · 1.35 KB
/
sensor_multilevel_supported_scale_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
defmodule Grizzly.ZWave.Commands.SensorMultilevelSupportedScaleGet do
@moduledoc """
This module implements command SENSOR_MULTILEVEL_SUPPORTED_SCALE_GET of command class COMMAND_CLASS_SENSOR_MULTILEVEL.
This command is used to retrieve the supported scales of the specific sensor type from the Multilevel Sensor device.
Params: * `:sensor_type` - `one of :temperature or :illuminance or :power or :humidity`
"""
@behaviour Grizzly.ZWave.Command
alias Grizzly.ZWave.{Command, DecodeError}
alias Grizzly.ZWave.CommandClasses.SensorMultilevel
@type param :: {:sensor_type, atom()}
@impl Grizzly.ZWave.Command
def new(params) do
command = %Command{
name: :sensor_multilevel_supported_scale_get,
command_byte: 0x03,
command_class: SensorMultilevel,
params: params,
impl: __MODULE__
}
{:ok, command}
end
@impl Grizzly.ZWave.Command
def encode_params(command) do
sensor_type = Command.param(command, :sensor_type)
sensor_type_byte = SensorMultilevel.encode_sensor_type(sensor_type)
<<sensor_type_byte>>
end
@impl Grizzly.ZWave.Command
def decode_params(<<sensor_type_byte>>) do
with {:ok, sensor_type} <- SensorMultilevel.decode_sensor_type(sensor_type_byte) do
{:ok, [sensor_type: sensor_type]}
else
{:error, %DecodeError{}} = error ->
error
end
end
end