From 9de4c7df700e48e8832d74cf9ff084a641e2c4b8 Mon Sep 17 00:00:00 2001 From: Elin Olsson Date: Fri, 27 Dec 2024 23:36:14 +0100 Subject: [PATCH] Rename function for broadcasting extension events (#1717) Rename function to make its purpose clear. --- lib/nerves_hub/devices.ex | 4 ++-- lib/nerves_hub/extensions.ex | 12 ++++-------- lib/nerves_hub/products.ex | 4 ++-- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/nerves_hub/devices.ex b/lib/nerves_hub/devices.ex index d693d38af..9204ce2b6 100644 --- a/lib/nerves_hub/devices.ex +++ b/lib/nerves_hub/devices.ex @@ -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 @@ -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 diff --git a/lib/nerves_hub/extensions.ex b/lib/nerves_hub/extensions.ex index 3c76943af..b3b9ce2e5 100644 --- a/lib/nerves_hub/extensions.ex +++ b/lib/nerves_hub/extensions.ex @@ -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 diff --git a/lib/nerves_hub/products.ex b/lib/nerves_hub/products.ex index 89e77556e..d8ff4467a 100644 --- a/lib/nerves_hub/products.ex +++ b/lib/nerves_hub/products.ex @@ -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 @@ -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