Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix :ack_request in response to AsyncConnection command #810

Merged
merged 1 commit into from Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/grizzly/command_handlers/wait_report.ex
Expand Up @@ -23,7 +23,9 @@ defmodule Grizzly.CommandHandlers.WaitReport do
@spec handle_command(Command.t(), state()) ::
{:continue, state} | {:complete, Command.t()}
def handle_command(command, state) do
if state.complete_report == :any or command.name == state.complete_report do
expected? = not is_nil(command) and command.name == state.complete_report

if state.complete_report == :any or expected? do
{:complete, command}
else
{:continue, state}
Expand Down
43 changes: 43 additions & 0 deletions lib/grizzly/connections/async_connection.ex
Expand Up @@ -170,6 +170,49 @@ defmodule Grizzly.Connections.AsyncConnection do
end

defp handle_commands(zip_packet, state) do
case Command.param!(zip_packet, :flag) do
:ack_request ->
handle_ack_request(zip_packet, state)

_ ->
do_handle_commands(zip_packet, state)
end
end

defp handle_ack_request(zip_packet, state) do
%State{transport: transport} = state
header_extensions = Command.param!(zip_packet, :header_extensions)
seq_number = Command.param!(zip_packet, :seq_number)
secure = Command.param!(zip_packet, :secure)
command = Command.param!(zip_packet, :command)

more_info =
if command && command.name == :supervision_get do
true
else
false
end

{:ok, ack_response} =
ZIPPacket.new(
secure: secure,
header_extensions: header_extensions,
seq_number: seq_number,
more_info: more_info,
flag: :ack_response
)

binary = ZWave.to_binary(ack_response)
Transport.send(transport, binary)

if command != nil do
do_handle_commands(zip_packet, state)
else
state
end
end

defp do_handle_commands(zip_packet, state) do
updated_state =
case CommandList.response_for_zip_packet(state.commands, zip_packet) do
{:retry, command_runner, new_command_list} ->
Expand Down