Fix auth errors and display errors
This commit is contained in:
parent
d7a05f3b1f
commit
82bb4ff253
6 changed files with 25 additions and 12 deletions
|
@ -75,7 +75,7 @@ defmodule GeoTherminator.PumpAPI.Auth.Server do
|
||||||
schedule_token_check()
|
schedule_token_check()
|
||||||
|
|
||||||
if diff < @token_check_diff do
|
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
|
case init_state(state.username, state.password) do
|
||||||
{:ok, new_state} -> {:noreply, new_state}
|
{:ok, new_state} -> {:noreply, new_state}
|
||||||
|
|
|
@ -11,6 +11,9 @@ defmodule GeoTherminatorWeb.Components.MainView do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def update(assigns, socket) do
|
def update(assigns, socket) do
|
||||||
|
priority_set =
|
||||||
|
Device.OpStat.record(assigns.opstat, :priority) |> elem(1) |> Map.keys() |> MapSet.new()
|
||||||
|
|
||||||
{:ok,
|
{:ok,
|
||||||
assign(socket,
|
assign(socket,
|
||||||
set_temp: Device.Status.record(assigns.status, :heating_effect),
|
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),
|
Device.RegisterCollection.record(assigns.registers, :outdoor_temp),
|
||||||
:value
|
:value
|
||||||
),
|
),
|
||||||
priority: Device.OpStat.record(assigns.opstat, :priority)
|
priority_set: priority_set
|
||||||
)}
|
)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -86,7 +86,7 @@
|
||||||
pointer-events="none"
|
pointer-events="none"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<%= if @priority == :heating do %>
|
<%= if MapSet.member?(@priority_set, :heating) do %>
|
||||||
<ellipse
|
<ellipse
|
||||||
cx="172"
|
cx="172"
|
||||||
cy="289"
|
cy="289"
|
||||||
|
@ -98,7 +98,7 @@
|
||||||
/>
|
/>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= if @priority == :hot_water do %>
|
<%= if MapSet.member?(@priority_set, :hot_water) do %>
|
||||||
<ellipse
|
<ellipse
|
||||||
cx="100"
|
cx="100"
|
||||||
cy="169"
|
cy="169"
|
||||||
|
|
|
@ -37,3 +37,9 @@ pub external fn from_iso8601(String) -> DateTimeFromISO8601Result =
|
||||||
|
|
||||||
pub external fn from_unix(Int) -> Result(DateTime, #(Atom, Atom)) =
|
pub external fn from_unix(Int) -> Result(DateTime, #(Atom, Atom)) =
|
||||||
"Elixir.DateTime" "from_unix"
|
"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"
|
||||||
|
|
|
@ -17,15 +17,19 @@ pub fn auth(username: String, password: String) -> Result(User, ApiError) {
|
||||||
try tokens =
|
try tokens =
|
||||||
b2c.authenticate(username, password)
|
b2c.authenticate(username, password)
|
||||||
|> result.map_error(fn(err) { AuthError(inner: err) })
|
|> result.map_error(fn(err) { AuthError(inner: err) })
|
||||||
try access_token_expires_in =
|
try access_token_expiry =
|
||||||
date_time.from_unix(tokens.access_token_expires_in)
|
date_time.from_unix(
|
||||||
|
date_time.to_unix(date_time.utc_now()) + tokens.access_token_expires_in,
|
||||||
|
)
|
||||||
|> result.replace_error(InvalidData(
|
|> result.replace_error(InvalidData(
|
||||||
msg: "Access token expiry could not be converted into DateTime: " <> string.inspect(
|
msg: "Access token expiry could not be converted into DateTime: " <> string.inspect(
|
||||||
tokens.access_token_expires_in,
|
tokens.access_token_expires_in,
|
||||||
),
|
),
|
||||||
))
|
))
|
||||||
try refresh_token_expires_in =
|
try refresh_token_expiry =
|
||||||
date_time.from_unix(tokens.refresh_token_expires_in)
|
date_time.from_unix(
|
||||||
|
date_time.to_unix(date_time.utc_now()) + tokens.refresh_token_expires_in,
|
||||||
|
)
|
||||||
|> result.replace_error(InvalidData(
|
|> result.replace_error(InvalidData(
|
||||||
msg: "Refresh token expiry could not be converted into DateTime: " <> string.inspect(
|
msg: "Refresh token expiry could not be converted into DateTime: " <> string.inspect(
|
||||||
tokens.refresh_token_expires_in,
|
tokens.refresh_token_expires_in,
|
||||||
|
@ -34,9 +38,9 @@ pub fn auth(username: String, password: String) -> Result(User, ApiError) {
|
||||||
|
|
||||||
Ok(User(tokens: Tokens(
|
Ok(User(tokens: Tokens(
|
||||||
access_token: tokens.access_token,
|
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: tokens.refresh_token,
|
||||||
refresh_token_expiry: refresh_token_expires_in,
|
refresh_token_expiry: refresh_token_expiry,
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -275,8 +275,8 @@ fn opstat_bitmask_map(register: Register) {
|
||||||
let #(int, priority) = mapping
|
let #(int, priority) = mapping
|
||||||
|
|
||||||
case band(register.value, int) {
|
case band(register.value, int) {
|
||||||
0 -> set.insert(output, priority)
|
0 -> output
|
||||||
_ -> priority_set
|
_ -> set.insert(output, priority)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue