diff --git a/lib/geo_therminator/pump_api/auth/server.ex b/lib/geo_therminator/pump_api/auth/server.ex
index ccbfd79..95f28ea 100644
--- a/lib/geo_therminator/pump_api/auth/server.ex
+++ b/lib/geo_therminator/pump_api/auth/server.ex
@@ -75,7 +75,7 @@ defmodule GeoTherminator.PumpAPI.Auth.Server do
schedule_token_check()
if diff < @token_check_diff do
- Logger.debug("Renewing auth token since #{diff} < #{@token_check_diff}")
+ Logger.info("Renewing auth token since #{diff} < #{@token_check_diff}")
case init_state(state.username, state.password) do
{:ok, new_state} -> {:noreply, new_state}
diff --git a/lib/geo_therminator_web/live/components/main_view.ex b/lib/geo_therminator_web/live/components/main_view.ex
index 4547638..8e9e0b1 100644
--- a/lib/geo_therminator_web/live/components/main_view.ex
+++ b/lib/geo_therminator_web/live/components/main_view.ex
@@ -11,6 +11,9 @@ defmodule GeoTherminatorWeb.Components.MainView do
@impl true
def update(assigns, socket) do
+ priority_set =
+ Device.OpStat.record(assigns.opstat, :priority) |> elem(1) |> Map.keys() |> MapSet.new()
+
{:ok,
assign(socket,
set_temp: Device.Status.record(assigns.status, :heating_effect),
@@ -45,7 +48,7 @@ defmodule GeoTherminatorWeb.Components.MainView do
Device.RegisterCollection.record(assigns.registers, :outdoor_temp),
:value
),
- priority: Device.OpStat.record(assigns.opstat, :priority)
+ priority_set: priority_set
)}
end
end
diff --git a/lib/geo_therminator_web/live/components/main_view.html.heex b/lib/geo_therminator_web/live/components/main_view.html.heex
index 4cca2ba..63c2c37 100644
--- a/lib/geo_therminator_web/live/components/main_view.html.heex
+++ b/lib/geo_therminator_web/live/components/main_view.html.heex
@@ -86,7 +86,7 @@
pointer-events="none"
/>
- <%= if @priority == :heating do %>
+ <%= if MapSet.member?(@priority_set, :heating) do %>
<% end %>
- <%= if @priority == :hot_water do %>
+ <%= if MapSet.member?(@priority_set, :hot_water) do %>
DateTimeFromISO8601Result =
pub external fn from_unix(Int) -> Result(DateTime, #(Atom, Atom)) =
"Elixir.DateTime" "from_unix"
+
+pub external fn utc_now() -> DateTime =
+ "Elixir.DateTime" "utc_now"
+
+pub external fn to_unix(DateTime) -> Int =
+ "Elixir.DateTime" "to_unix"
diff --git a/src/pump_api/auth/api.gleam b/src/pump_api/auth/api.gleam
index 88652c8..23101bf 100644
--- a/src/pump_api/auth/api.gleam
+++ b/src/pump_api/auth/api.gleam
@@ -17,15 +17,19 @@ pub fn auth(username: String, password: String) -> Result(User, ApiError) {
try tokens =
b2c.authenticate(username, password)
|> result.map_error(fn(err) { AuthError(inner: err) })
- try access_token_expires_in =
- date_time.from_unix(tokens.access_token_expires_in)
+ try access_token_expiry =
+ date_time.from_unix(
+ date_time.to_unix(date_time.utc_now()) + tokens.access_token_expires_in,
+ )
|> result.replace_error(InvalidData(
msg: "Access token expiry could not be converted into DateTime: " <> string.inspect(
tokens.access_token_expires_in,
),
))
- try refresh_token_expires_in =
- date_time.from_unix(tokens.refresh_token_expires_in)
+ try refresh_token_expiry =
+ date_time.from_unix(
+ date_time.to_unix(date_time.utc_now()) + tokens.refresh_token_expires_in,
+ )
|> result.replace_error(InvalidData(
msg: "Refresh token expiry could not be converted into DateTime: " <> string.inspect(
tokens.refresh_token_expires_in,
@@ -34,9 +38,9 @@ pub fn auth(username: String, password: String) -> Result(User, ApiError) {
Ok(User(tokens: Tokens(
access_token: tokens.access_token,
- access_token_expiry: access_token_expires_in,
+ access_token_expiry: access_token_expiry,
refresh_token: tokens.refresh_token,
- refresh_token_expiry: refresh_token_expires_in,
+ refresh_token_expiry: refresh_token_expiry,
)))
}
diff --git a/src/pump_api/device/api.gleam b/src/pump_api/device/api.gleam
index bf791b0..423566a 100644
--- a/src/pump_api/device/api.gleam
+++ b/src/pump_api/device/api.gleam
@@ -275,8 +275,8 @@ fn opstat_bitmask_map(register: Register) {
let #(int, priority) = mapping
case band(register.value, int) {
- 0 -> set.insert(output, priority)
- _ -> priority_set
+ 0 -> output
+ _ -> set.insert(output, priority)
}
},
)