Skip to content

Commit

Permalink
Rename function for broadcasting extension events (#1717)
Browse files Browse the repository at this point in the history
Rename function to make its purpose clear.
  • Loading branch information
elinol authored Dec 27, 2024
1 parent 17cbd78 commit 9de4c7d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
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

0 comments on commit 9de4c7d

Please sign in to comment.