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

Rename function for broadcasting extension events #1717

Merged
merged 2 commits into from
Dec 27, 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
4 changes: 2 additions & 2 deletions lib/nerves_hub/devices.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,7 @@ defmodule NervesHub.Devices do
|> Repo.update()
|> tap(fn
{:ok, _} ->
Extensions.toggle_extension(device, "attach", extension_string)
Extensions.broadcast_extension_event(device, "attach", extension_string)

_ ->
:nope
Expand All @@ -1423,7 +1423,7 @@ defmodule NervesHub.Devices do
|> Repo.update()
|> tap(fn
{:ok, _} ->
Extensions.toggle_extension(device, "detach", extension_string)
Extensions.broadcast_extension_event(device, "detach", extension_string)

_ ->
:nope
Expand Down
12 changes: 4 additions & 8 deletions lib/nerves_hub/extensions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,15 @@ defmodule NervesHub.Extensions do
:unsupported
end

def toggle_extension(target, event, extension) do
device_internal_broadcast!(target, event, %{
"extensions" => [extension]
})
end

defp device_internal_broadcast!(target, event, payload) do
def broadcast_extension_event(target, event, extension) do
Phoenix.Channel.Server.broadcast_from!(
NervesHub.PubSub,
self(),
topic(target),
event,
payload
%{
"extensions" => [extension]
}
)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/nerves_hub/products.ex
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ defmodule NervesHub.Products do
|> Repo.update()
|> tap(fn
{:ok, _} ->
Extensions.toggle_extension(product, "attach", extension_string)
Extensions.broadcast_extension_event(product, "attach", extension_string)

_ ->
:nope
Expand All @@ -292,7 +292,7 @@ defmodule NervesHub.Products do
|> Repo.update()
|> tap(fn
{:ok, _} ->
Extensions.toggle_extension(product, "detach", extension_string)
Extensions.broadcast_extension_event(product, "detach", extension_string)

_ ->
:nope
Expand Down
Loading