Commit from last night

This commit is contained in:
2025-08-03 13:33:21 -07:00
parent 96de648bca
commit 400270ae52
4 changed files with 80 additions and 80 deletions
@@ -5,19 +5,18 @@ defmodule DashboardWeb.HostsLive do
use DashboardWeb, :live_view
alias Phoenix.PubSub
alias Dashboard.MqttSubscriber
@pubsub_topic "systant:hosts"
@impl true
def mount(_params, _session, socket) do
if connected?(socket) do
# Subscribe to host updates
# Subscribe to host updates from MQTT
PubSub.subscribe(Dashboard.PubSub, @pubsub_topic)
end
# Get initial host data
hosts = MqttSubscriber.get_hosts()
# Start with empty hosts - will be populated by MQTT
hosts = %{}
socket =
socket
@@ -29,10 +28,13 @@ defmodule DashboardWeb.HostsLive do
@impl true
def handle_info({:host_update, hostname, host_data}, socket) do
require Logger
Logger.info("LiveView received host update for #{hostname}: #{inspect(host_data)}")
updated_hosts = Map.put(socket.assigns.hosts, hostname, host_data)
{:noreply, assign(socket, :hosts, updated_hosts)}
end
@impl true
def render(assigns) do
~H"""
@@ -95,7 +97,7 @@ defmodule DashboardWeb.HostsLive do
<div class="mt-4">
<h4 class="text-sm font-medium text-zinc-700 mb-2">Raw Data:</h4>
<pre class="text-xs bg-zinc-50 p-3 rounded border overflow-x-auto">
<%= Jason.encode!(@data, pretty: true) %>
<%= Jason.encode!(@data, pretty: true) %>
</pre>
</div>
</div>