-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Thermostat Fan Mode Supported Get/Report (#902)
- Loading branch information
1 parent
8be12e3
commit de8f8aa
Showing
5 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
lib/grizzly/zwave/commands/thermostat_fan_mode_supported_get.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
defmodule Grizzly.ZWave.Commands.ThermostatFanModeSupportedGet do | ||
@moduledoc """ | ||
This command is used to request the supported modes from the device. | ||
""" | ||
|
||
@behaviour Grizzly.ZWave.Command | ||
|
||
alias Grizzly.ZWave.{Command, DecodeError} | ||
alias Grizzly.ZWave.CommandClasses.ThermostatFanMode | ||
|
||
@impl Grizzly.ZWave.Command | ||
@spec new(keyword()) :: {:ok, Command.t()} | ||
def new(params) do | ||
command = %Command{ | ||
name: :thermostat_fan_mode_supported_get, | ||
command_byte: 0x04, | ||
command_class: ThermostatFanMode, | ||
params: params, | ||
impl: __MODULE__ | ||
} | ||
|
||
{:ok, command} | ||
end | ||
|
||
@impl Grizzly.ZWave.Command | ||
@spec encode_params(Command.t()) :: binary() | ||
def encode_params(_command) do | ||
<<>> | ||
end | ||
|
||
@impl Grizzly.ZWave.Command | ||
@spec decode_params(binary()) :: {:ok, [keyword()]} | {:error, DecodeError.t()} | ||
def decode_params(_binary) do | ||
{:ok, []} | ||
end | ||
end |
58 changes: 58 additions & 0 deletions
58
lib/grizzly/zwave/commands/thermostat_fan_mode_supported_report.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
defmodule Grizzly.ZWave.Commands.ThermostatFanModeSupportedReport do | ||
@moduledoc """ | ||
This command is used to report the device's supported thermostat modes. | ||
## Parameters | ||
* `:modes` - the supported modes | ||
""" | ||
|
||
@behaviour Grizzly.ZWave.Command | ||
|
||
import Grizzly.ZWave.Encoding | ||
|
||
alias Grizzly.ZWave.{Command, DecodeError} | ||
alias Grizzly.ZWave.CommandClasses.ThermostatFanMode | ||
|
||
@type param :: {:modes, [ThermostatFanMode.mode()]} | ||
|
||
@impl Grizzly.ZWave.Command | ||
@spec new([param()]) :: {:ok, Command.t()} | ||
def new(params) do | ||
command = %Command{ | ||
name: :thermostat_fan_mode_supported_report, | ||
command_byte: 0x05, | ||
command_class: ThermostatFanMode, | ||
params: params, | ||
impl: __MODULE__ | ||
} | ||
|
||
{:ok, command} | ||
end | ||
|
||
@impl Grizzly.ZWave.Command | ||
@spec encode_params(Command.t()) :: binary() | ||
def encode_params(command) do | ||
command | ||
|> Command.param!(:modes) | ||
|> Enum.map(&ThermostatFanMode.encode_mode/1) | ||
|> encode_bitmask() | ||
end | ||
|
||
@impl Grizzly.ZWave.Command | ||
@spec decode_params(binary()) :: {:ok, [param()]} | {:error, DecodeError.t()} | ||
def decode_params(binary) do | ||
modes = | ||
binary | ||
|> decode_bitmask() | ||
|> Enum.reduce([], fn mode, modes -> | ||
case ThermostatFanMode.decode_mode(mode) do | ||
{:ok, mode} -> [mode | modes] | ||
{:error, _} -> modes | ||
end | ||
end) | ||
|> Enum.reverse() | ||
|
||
{:ok, [modes: modes]} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
test/grizzly/zwave/commands/thermostat_fan_mode_supported_report_test.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
defmodule Grizzly.ZWave.Commands.ThermostatFanModeSupportedReportTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias Grizzly.ZWave.Commands.ThermostatFanModeSupportedReport | ||
|
||
test "encodes params correctly" do | ||
modes = [:auto_low, :low, :auto_high, :auto_medium] | ||
|
||
{:ok, cmd} = ThermostatFanModeSupportedReport.new(modes: modes) | ||
|
||
expected_binary = <<0b00010111>> | ||
|
||
assert expected_binary == ThermostatFanModeSupportedReport.encode_params(cmd) | ||
end | ||
|
||
test "decodes params correctly" do | ||
binary = <<0b00010111>> | ||
|
||
assert {:ok, [modes: [:auto_low, :low, :auto_high, :auto_medium]]} == | ||
ThermostatFanModeSupportedReport.decode_params(binary) | ||
end | ||
end |