This repository has been archived on 2024-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
augie/webapp/lib/augie_web/live/power_live.ex

32 lines
744 B
Elixir
Raw Normal View History

2020-05-14 22:05:26 +12:00
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