defmodule LambentExWeb.DevicesLive.Versions do
use LambentExWeb, :live_view
require Logger
@pubsub_name LambentEx.PubSub
@impl true
def mount(_params, _session, socket) do
Phoenix.PubSub.subscribe(@pubsub_name, "scan-82667777")
{:ok, socket |> assign(:devices, %{}) |> assign(:nonew, true)}
end
@impl true
def handle_params(params, _url, socket) do
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
end
# the sweep is every few minutes, which is a long time to wait to see what a
# device you have just reflashed is running
@impl true
def handle_event("refresh", _params, socket) do
LambentEx.Scan.ESP8266x7777.refresh()
{:noreply,
socket
|> put_flash(:info, "Asking #{map_size(socket.assigns.devices)} devices what they run...")}
end
@impl true
def handle_info({:devices_pub, devices}, socket) do
n = Map.merge(socket.assigns.devices, devices)
{:noreply, socket |> assign(:devices, n)}
end
defp apply_action(socket, :index, _params) do
socket
|> assign(:page_link, "Devices")
|> assign(:page_title, "Device Versions")
|> assign(:source, nil)
end
# only the esp32rs firmware reports a version, so the legacy 8266s would just
# be a wall of unknowns
defp versioned(devices) do
devices
|> Enum.filter(fn {_k, v} -> v["type"] == "7777-flex" end)
|> Enum.sort_by(fn {k, v} -> {v["ver"] || "", k} end)
end
defp pip(map) do
case Map.get(map, "ip") do
nil -> "-"
ip -> ip |> Tuple.to_list() |> Enum.join(".")
end
end
end
neiam
/lambent_ex
Lambent Aether 5
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
1.5 KiB · text
History
9c0fc16