31 lines
744 B
Elixir
31 lines
744 B
Elixir
defmodule AugieWeb.PowerLive do
|
|
use Phoenix.LiveView
|
|
alias Augie.Sensor.Power
|
|
alias Phoenix.PubSub
|
|
|
|
@moduledoc false
|
|
|
|
def mount(_params, _context, socket) do
|
|
if connected?(socket), do: PubSub.subscribe(Augie.PubSub, "telemetry.power")
|
|
|
|
{:ok, assign(socket, bus_voltage: nil, shunt_voltage: nil, current: nil, power: nil)}
|
|
end
|
|
|
|
def handle_info(
|
|
%Power{
|
|
bus_voltage: bus_voltage,
|
|
shunt_voltage: shunt_voltage,
|
|
current: current,
|
|
power: power
|
|
},
|
|
socket
|
|
),
|
|
do:
|
|
{:noreply,
|
|
assign(socket,
|
|
bus_voltage: bus_voltage,
|
|
shunt_voltage: shunt_voltage,
|
|
current: current,
|
|
power: power
|
|
)}
|
|
end
|