Skip to content

Commit

Permalink
Merge pull request #1 from gridpoint-com/add-update-available-property
Browse files Browse the repository at this point in the history
Add a useful properties others can subscribe to
  • Loading branch information
abelino authored May 29, 2024
2 parents 1657909 + 334d71c commit 18c2a22
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/nerves_hub_link/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ defmodule NervesHubLink.Application do
}

children = [
{PropertyTable,
name: NervesHubLink,
properties: [
{["status"], :disconnected},
{["update_available"], nil}
]},
{UpdateManager, fwup_config},
Connection,
{Socket, config}
Expand Down
3 changes: 3 additions & 0 deletions lib/nerves_hub_link/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ defmodule NervesHubLink.Connection do
"""
@spec connected() :: :ok
def connected() do
PropertyTable.put(NervesHubLink, ["status"], :connected)
Agent.update(__MODULE__, fn _ -> {:connected, current_time()} end)
end

Expand All @@ -103,6 +104,8 @@ defmodule NervesHubLink.Connection do
"""
@spec disconnected() :: :ok
def disconnected() do
PropertyTable.put(NervesHubLink, ["status"], :disconnected)

# If we are already in a disconnected state, then don't
# overwrite the existing value so we can measure from
# the first point of disconnect
Expand Down
7 changes: 6 additions & 1 deletion lib/nerves_hub_link/socket.ex
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,8 @@ defmodule NervesHubLink.Socket do
end

defp handle_join_reply(%{"firmware_url" => url} = update) when is_binary(url) do
PropertyTable.put(NervesHubLink, ["update_available"], true)

case NervesHubLinkCommon.Message.UpdateInfo.parse(update) do
{:ok, %NervesHubLinkCommon.Message.UpdateInfo{} = info} ->
UpdateManager.apply_update(info)
Expand All @@ -272,7 +274,10 @@ defmodule NervesHubLink.Socket do
end
end

defp handle_join_reply(_), do: :noop
defp handle_join_reply(_) do
PropertyTable.put(NervesHubLink, ["update_available"], false)
:noop
end

defp maybe_join_console(socket) do
if socket.assigns.remote_iex do
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ defmodule NervesHubLink.MixProject do
{:nerves_runtime, "~> 0.8"},
{:nerves_hub_link_common, "~> 0.4"},
{:nerves_hub_ca_store, "~> 1.0.0"},
{:property_table, "~> 0.2"},
{:slipstream, "~> 1.0 or ~> 0.8"},
{:x509, "~> 0.5"}
]
Expand Down

0 comments on commit 18c2a22

Please sign in to comment.