/
date_report.ex
48 lines (37 loc) · 1.06 KB
/
date_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
defmodule Grizzly.ZWave.Commands.DateReport do
@moduledoc """
This command is used to advertise the current date adjusted according to the local time zone and
Daylight Saving Time.
Params:
* `:year` - the year (required)
* `:month` - the month (required)
* `:day` - the day (required)
"""
@behaviour Grizzly.ZWave.Command
alias Grizzly.ZWave.Command
alias Grizzly.ZWave.CommandClasses.Time
@type param :: {:year, integer()} | {:month, 1..12} | {:day, 1..31}
@impl true
@spec new([param()]) :: {:ok, Command.t()}
def new(params) do
command = %Command{
name: :date_report,
command_byte: 0x04,
command_class: Time,
params: params,
impl: __MODULE__
}
{:ok, command}
end
@impl true
def encode_params(command) do
year = Command.param!(command, :year)
month = Command.param!(command, :month)
day = Command.param!(command, :day)
<<year::16, month, day>>
end
@impl true
def decode_params(<<year::16, month, day>>) do
{:ok, [year: year, month: month, day: day]}
end
end