neiam
/lambent_ex
Lambent Aether 5
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
Keep a publish that is missing persist from taking Meta down
e7a4389 · Gabriel Morell · 2026-09-17 01:16
Message
{commit_body(@commit)}
Files changed
modified
lib/lambent_ex/meta.ex
+4
−4
@@ -292,7 +292,7 @@ defmodule LambentEx.Meta do
| 292 | 292 | end |
| 293 | 293 | |
| 294 | 294 | def handle_info({:machines_pub, machine}, state) do |
| 295 | − case machine[:persist] do | |
| 295 | + case machine[:persist] == true do | |
| 296 | 296 | true -> |
| 297 | 297 | {:noreply, %{state | machines: MapSet.put(state.machines, machine)}} |
| 298 | 298 |
@@ -307,7 +307,7 @@ defmodule LambentEx.Meta do
| 307 | 307 | |> Map.put(:persist, true) |
| 308 | 308 | |> Map.put( |
| 309 | 309 | :opts, |
| 310 | − machine[:opts] |> Keyword.update(:persist, true, fn _ -> true end) | |
| 310 | + (machine[:opts] || []) |> Keyword.update(:persist, true, fn _ -> true end) | |
| 311 | 311 | ) |
| 312 | 312 | ) |
| 313 | 313 | }} |
@@ -315,7 +315,7 @@ defmodule LambentEx.Meta do
| 315 | 315 | end |
| 316 | 316 | |
| 317 | 317 | def handle_info({:links_pub, link}, state) do |
| 318 | − case link[:persist] do | |
| 318 | + case link[:persist] == true do | |
| 319 | 319 | true -> |
| 320 | 320 | {:noreply, %{state | links: MapSet.put(state.links, link)}} |
| 321 | 321 |
@@ -330,7 +330,7 @@ defmodule LambentEx.Meta do
| 330 | 330 | |> Map.put(:persist, true) |
| 331 | 331 | |> Map.put( |
| 332 | 332 | :opts, |
| 333 | − link[:opts] |> Keyword.update(:persist, true, fn _ -> true end) | |
| 333 | + (link[:opts] || []) |> Keyword.update(:persist, true, fn _ -> true end) | |
| 334 | 334 | ) |
| 335 | 335 | ) |
| 336 | 336 | }} |
modified
test/lambent_ex/places_test.exs
+19
−8
@@ -7,15 +7,17 @@ defmodule LambentEx.PlacesTest do
| 7 | 7 | @pubsub LambentEx.PubSub |
| 8 | 8 | |
| 9 | 9 | setup do |
| 10 | − on_exit(fn -> | |
| 11 | − Meta.put_place_defaults(%{}) | |
| 12 | − Places.set_default("test-hall", nil) | |
| 13 | − Places.defaults() | |
| 14 | − end) | |
| 15 | − | |
| 10 | + clear_defaults() | |
| 11 | + on_exit(&clear_defaults/0) | |
| 16 | 12 | :ok |
| 17 | 13 | end |
| 18 | 14 | |
| 15 | + # through the server, so its own copy goes too | |
| 16 | + defp clear_defaults do | |
| 17 | + Places.defaults() |> Map.keys() |> Enum.each(&Places.set_default(&1, nil)) | |
| 18 | + Places.defaults() | |
| 19 | + end | |
| 20 | + | |
| 19 | 21 | defp device(mac, place, name \\ nil) do |
| 20 | 22 | %{ |
| 21 | 23 | mac => %{ |
@@ -82,7 +84,14 @@ defmodule LambentEx.PlacesTest do
| 82 | 84 | @pubsub, |
| 83 | 85 | "links_idx", |
| 84 | 86 | {:links_pub, |
| 85 | − %{name: "mine", target: "aa:bb:cc:dd:ee:03", source: "something", enabled: true}} | |
| 87 | + %{ | |
| 88 | + name: "mine", | |
| 89 | + target: "aa:bb:cc:dd:ee:03", | |
| 90 | + source: "something", | |
| 91 | + enabled: true, | |
| 92 | + persist: false, | |
| 93 | + opts: [] | |
| 94 | + }} | |
| 86 | 95 | ) |
| 87 | 96 | |
| 88 | 97 | publish(device("aa:bb:cc:dd:ee:03", "test-hall2", "taken")) |
@@ -170,7 +179,9 @@ defmodule LambentEx.PlacesTest do
| 170 | 179 | name: "test-hall6-only-one", |
| 171 | 180 | target: "aa:bb:cc:dd:ee:07", |
| 172 | 181 | source: "places-machine-5", |
| 173 | − enabled: true | |
| 182 | + enabled: true, | |
| 183 | + persist: false, | |
| 184 | + opts: [] | |
| 174 | 185 | }} |
| 175 | 186 | ) |
| 176 | 187 |
modified
test/lambent_ex_web/live/places_test.exs
+16
−2
@@ -8,14 +8,28 @@ defmodule LambentExWeb.PlacesTest do
| 8 | 8 | @pubsub LambentEx.PubSub |
| 9 | 9 | |
| 10 | 10 | setup do |
| 11 | + clear_defaults() | |
| 12 | + | |
| 11 | 13 | on_exit(fn -> |
| 12 | − Places.set_default("page-hall", nil) | |
| 13 | − Places.defaults() | |
| 14 | + clear_defaults() | |
| 15 | + # once a place has a default its devices get adopted, and those links | |
| 16 | + # would otherwise outlive the test | |
| 17 | + for name <- ["page-hall-bb01", "page-hall-bb02"] do | |
| 18 | + case Registry.lookup(:lambent_links, "link-#{name}") do | |
| 19 | + [{pid, _}] -> LambentEx.LinkSupervisor.abort_child(pid) | |
| 20 | + [] -> :ok | |
| 21 | + end | |
| 22 | + end | |
| 14 | 23 | end) |
| 15 | 24 | |
| 16 | 25 | :ok |
| 17 | 26 | end |
| 18 | 27 | |
| 28 | + defp clear_defaults do | |
| 29 | + Places.defaults() |> Map.keys() |> Enum.each(&Places.set_default(&1, nil)) | |
| 30 | + Places.defaults() | |
| 31 | + end | |
| 32 | + | |
| 19 | 33 | test "the devices page links to it", %{conn: conn} do |
| 20 | 34 | {:ok, _live, html} = live(conn, "/cfg/devices") |
| 21 | 35 | assert html =~ "/cfg/devices/places" |
Parents: 65d680a