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

Add a useful properties others can subscribe to #1

Merged
merged 1 commit into from
May 29, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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