Skip to content

Commit

Permalink
Multilevel sensor command queued when device is asleep
Browse files Browse the repository at this point in the history
Fixes SRHUB-115
  • Loading branch information
jfcloutier authored and mattludwigs committed Aug 1, 2019
1 parent ef3b3cf commit 117a2f3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
15 changes: 15 additions & 0 deletions lib/grizzly/command_class/sensor_multilevel/get.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ defmodule Grizzly.CommandClass.SensorMultilevel.Get do
| {:done, {:error, :nack_response}}
| {:done, non_neg_integer}
| {:retry, t}
| {:queued, t()}
def handle_response(
%__MODULE__{seq_number: seq_number} = command,
%Packet{
Expand Down Expand Up @@ -100,5 +101,19 @@ defmodule Grizzly.CommandClass.SensorMultilevel.Get do
{:done, {:ok, value}}
end

def handle_response(
%__MODULE__{seq_number: seq_number} = command,
%Packet{
seq_number: seq_number,
types: [:nack_response, :nack_waiting]
} = packet
) do
if Packet.sleeping_delay?(packet) do
{:queued, command}
else
{:continue, command}
end
end

def handle_response(command, _), do: {:continue, command}
end
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ defmodule Grizzly.CommandClass.SensorMultilevel.SupportedGetSensor do
| {:done, {:error, :nack_response}}
| {:done, non_neg_integer}
| {:retry, t}
| {:queued, t()}
def handle_response(
%__MODULE__{seq_number: seq_number} = command,
%Packet{
Expand Down Expand Up @@ -82,5 +83,19 @@ defmodule Grizzly.CommandClass.SensorMultilevel.SupportedGetSensor do
{:done, {:ok, value}}
end

def handle_response(
%__MODULE__{seq_number: seq_number} = command,
%Packet{
seq_number: seq_number,
types: [:nack_response, :nack_waiting]
} = packet
) do
if Packet.sleeping_delay?(packet) do
{:queued, command}
else
{:continue, command}
end
end

def handle_response(command, _), do: {:continue, command}
end
16 changes: 15 additions & 1 deletion lib/grizzly/node.ex
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ defmodule Grizzly.Node do
)

command_class

{:error, :command_queued} ->
_ =
Logger.warn(
"Unable to get command command class for #{inspect(command_class_name)} because the node (#{
inspect(zw_node.id)
}) is asleep"
)

command_class
end
end)

Expand All @@ -215,13 +225,17 @@ defmodule Grizzly.Node do
"""
@spec get_command_class_version(t(), CommandClass.name()) ::
{:ok, CommandClass.version()}
| {:error, :command_class_not_found | :timeout_get_command_class_version}
| {:error,
:command_class_not_found | :timeout_get_command_class_version | :command_queued}
def get_command_class_version(zw_node, command_class_name) do
with {:ok, cc} <- command_class(zw_node, command_class_name),
:no_version_number <- CommandClass.version(cc),
{:ok, %{version: version}} <- do_get_command_class_version(zw_node, command_class_name) do
{:ok, version}
else
{:ok, :queued, _reference} ->
{:error, :command_queued}

{:error, :not_found} ->
{:error, :command_class_not_found}

Expand Down

0 comments on commit 117a2f3

Please sign in to comment.