mirror of
https://github.com/netfun2000/hipudding-teslamate.git
synced 2026-02-27 09:44:28 +08:00
Add Dialyzer
This commit is contained in:
@@ -0,0 +1 @@
|
||||
[]
|
||||
+4
-1
@@ -57,4 +57,7 @@ config/*.env
|
||||
/.project
|
||||
|
||||
# Mac files
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
|
||||
/priv/plts/*.plt
|
||||
/priv/plts/*.plt.hash
|
||||
|
||||
@@ -2,11 +2,12 @@ defmodule TeslaMate.Convert do
|
||||
@km_factor 0.62137119223733
|
||||
@km_factor_d Decimal.from_float(@km_factor)
|
||||
@ft_factor 3.28084
|
||||
@ft_factor_d Decimal.from_float(@ft_factor)
|
||||
|
||||
alias Decimal, as: D
|
||||
|
||||
def mph_to_kmh(nil), do: nil
|
||||
def mph_to_kmh(mph = %D{}), do: mph |> D.div(@km_factor) |> D.round()
|
||||
def mph_to_kmh(mph = %D{}), do: mph |> D.div(@km_factor_d) |> D.round()
|
||||
def mph_to_kmh(mph), do: round(mph / @km_factor)
|
||||
|
||||
def miles_to_km(nil, _precision), do: nil
|
||||
@@ -20,11 +21,11 @@ defmodule TeslaMate.Convert do
|
||||
def km_to_miles(km, precision), do: Float.round(km * @km_factor, precision)
|
||||
|
||||
def m_to_ft(nil), do: nil
|
||||
def m_to_ft(m = %D{}), do: D.mult(m, @ft_factor)
|
||||
def m_to_ft(m = %D{}), do: D.mult(m, @ft_factor_d)
|
||||
def m_to_ft(m), do: m * @ft_factor
|
||||
|
||||
def ft_to_m(nil), do: nil
|
||||
def ft_to_m(ft = %D{}), do: D.div(ft, @ft_factor)
|
||||
def ft_to_m(ft = %D{}), do: D.div(ft, @ft_factor_d)
|
||||
def ft_to_m(ft), do: ft / @ft_factor
|
||||
|
||||
def celsius_to_fahrenheit(nil, _precision), do: nil
|
||||
|
||||
@@ -568,10 +568,7 @@ defmodule TeslaMate.Log do
|
||||
}}
|
||||
when is_number(minutes) ->
|
||||
cost = Decimal.mult(minutes, cost_per_minute)
|
||||
|
||||
if match?(%Decimal{}, cost) or match?(%Decimal{}, session_fee) do
|
||||
Decimal.add(session_fee || 0, cost || 0)
|
||||
end
|
||||
Decimal.add(session_fee || 0, cost)
|
||||
|
||||
{_, _} ->
|
||||
nil
|
||||
|
||||
@@ -15,7 +15,7 @@ defmodule TeslaMate.Repair do
|
||||
# API
|
||||
|
||||
def start_link(opts) do
|
||||
GenServer.start_link(__MODULE__, opts, name: __MODULE__, fullsweep_after: 10)
|
||||
GenServer.start_link(__MODULE__, opts, name: __MODULE__)
|
||||
end
|
||||
|
||||
def trigger_run do
|
||||
|
||||
@@ -7,7 +7,7 @@ defmodule TeslaMate.Updater do
|
||||
@version Mix.Project.config()[:version]
|
||||
@name __MODULE__
|
||||
|
||||
adapter Tesla.Adapter.Finch, name: TeslaMate.HTTP
|
||||
adapter Tesla.Adapter.Finch, name: TeslaMate.HTTP, receive_timeout: 30_000
|
||||
|
||||
plug Tesla.Middleware.BaseUrl, "https://api.github.com"
|
||||
plug Tesla.Middleware.Headers, [{"user-agent", "TeslaMate/#{@version}"}]
|
||||
@@ -85,7 +85,7 @@ defmodule TeslaMate.Updater do
|
||||
## Private
|
||||
|
||||
defp fetch_release do
|
||||
case get("/repos/adriankumpf/teslamate/releases/latest", receive_timeout: 30_000) do
|
||||
case get("/repos/adriankumpf/teslamate/releases/latest") do
|
||||
{:ok, %Tesla.Env{status: 200, body: body}} ->
|
||||
parse_release(body)
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ defmodule TeslaMate.Vehicles.Vehicle do
|
||||
{%Vehicle{drive_state: %Drive{timestamp: now}},
|
||||
%Data{last_response: %Vehicle{drive_state: %Drive{timestamp: last}}}}
|
||||
when is_number(now) and is_number(last) and now < last ->
|
||||
drive_states = %{now: vehicle.drive_state, last: data.last_response.drive_state}
|
||||
drive_states = [now: vehicle.drive_state, last: data.last_response.drive_state]
|
||||
|
||||
Logger.warning(
|
||||
"Discarded stale fetch result: #{inspect(drive_states, pretty: true)}",
|
||||
|
||||
@@ -12,6 +12,7 @@ defmodule TeslaMate.MixProject do
|
||||
aliases: aliases(),
|
||||
releases: releases(),
|
||||
deps: deps(),
|
||||
dialyzer: dialyzer(),
|
||||
test_coverage: [tool: ExCoveralls],
|
||||
preferred_cli_env: [
|
||||
coveralls: :test,
|
||||
@@ -64,7 +65,8 @@ defmodule TeslaMate.MixProject do
|
||||
{:websockex, "~> 0.4"},
|
||||
{:cloak_ecto, "~> 1.2"},
|
||||
# Necessary until v1.1.7+ is released
|
||||
{:ssl_verify_fun, "~> 1.1.0", manager: :rebar3, override: true}
|
||||
{:ssl_verify_fun, "~> 1.1.0", manager: :rebar3, override: true},
|
||||
{:dialyxir, "~> 1.3", only: [:dev], runtime: false}
|
||||
]
|
||||
end
|
||||
|
||||
@@ -79,6 +81,17 @@ defmodule TeslaMate.MixProject do
|
||||
]
|
||||
end
|
||||
|
||||
defp dialyzer do
|
||||
[
|
||||
plt_file: {:no_warn, "priv/plts/dialyzer.plt"},
|
||||
plt_core_path: "priv/plts/",
|
||||
plt_add_apps: [:mix, :ex_unit],
|
||||
plt_ignore_apps: [],
|
||||
ignore_warnings: ".dialyzer_ignore.exs",
|
||||
list_unused_filters: true
|
||||
]
|
||||
end
|
||||
|
||||
defp releases do
|
||||
[
|
||||
teslamate: [
|
||||
|
||||
@@ -10,8 +10,10 @@
|
||||
"cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"},
|
||||
"db_connection": {:hex, :db_connection, "2.5.0", "bb6d4f30d35ded97b29fe80d8bd6f928a1912ca1ff110831edcd238a1973652c", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c92d5ba26cd69ead1ff7582dbb860adeedfff39774105a4f1c92cbb654b55aa2"},
|
||||
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
|
||||
"dialyxir": {:hex, :dialyxir, "1.3.0", "fd1672f0922b7648ff9ce7b1b26fcf0ef56dda964a459892ad15f6b4410b5284", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "00b2a4bcd6aa8db9dcb0b38c1225b7277dca9bc370b6438715667071a304696f"},
|
||||
"ecto": {:hex, :ecto, "3.10.2", "6b887160281a61aa16843e47735b8a266caa437f80588c3ab80a8a960e6abe37", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "6a895778f0d7648a4b34b486af59a1c8009041fbdf2b17f1ac215eb829c60235"},
|
||||
"ecto_sql": {:hex, :ecto_sql, "3.10.1", "6ea6b3036a0b0ca94c2a02613fd9f742614b5cfe494c41af2e6571bb034dd94c", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.10.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 0.17.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "f6a25bdbbd695f12c8171eaff0851fa4c8e72eec1e98c7364402dda9ce11c56b"},
|
||||
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
|
||||
"ex_cldr": {:hex, :ex_cldr, "2.37.1", "6091fa719a7a96f9abee7aba186e63a906d504d08039cc8f0c683a0e71ee1bd7", [:mix], [{:cldr_utils, "~> 2.21", [hex: :cldr_utils, repo: "hexpm", optional: false]}, {:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:gettext, "~> 0.19", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: true]}], "hexpm", "5d60c3288454bc966e404ea4f59531f7dbb570d7e927dce62f0ab8466713bf78"},
|
||||
"ex_cldr_plugs": {:hex, :ex_cldr_plugs, "1.3.0", "72a2064cb36c390dd0b212e8a172f643d455c8d362ee9c4bda29a96b42204df6", [:mix], [{:ex_cldr, "~> 2.37", [hex: :ex_cldr, repo: "hexpm", optional: false]}, {:gettext, "~> 0.19", [hex: :gettext, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "699a98543ea14a7c849fae768041c40f49aa611aa55866025d227796e4858bff"},
|
||||
"excoveralls": {:hex, :excoveralls, "0.16.1", "0bd42ed05c7d2f4d180331a20113ec537be509da31fed5c8f7047ce59ee5a7c5", [:mix], [{:hackney, "~> 1.16", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "dae763468e2008cf7075a64cb1249c97cb4bc71e236c5c2b5e5cdf1cfa2bf138"},
|
||||
|
||||
@@ -38,9 +38,8 @@ defmodule TeslaMate.Vehicles.Vehicle.ChargingSyncTest do
|
||||
|
||||
refute_receive _
|
||||
end) =~
|
||||
~r"""
|
||||
\[warn.*\] Invalid charge data: %{ideal_battery_range_km: \[\"can't be blank\"\]}
|
||||
\[warn.*\] Invalid charge data: %{ideal_battery_range_km: \[\"can't be blank\"\]}
|
||||
"""
|
||||
[warning] Invalid charge data: %{ideal_battery_range_km: [\"can't be blank\"]}
|
||||
"""
|
||||
end
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ defmodule TeslaMate.Vehicles.Vehicle.ChargingTest do
|
||||
end
|
||||
|
||||
@tag :capture_log
|
||||
test "transisitions into asleep state", %{test: name} do
|
||||
test "transitions into asleep state", %{test: name} do
|
||||
now_ts = DateTime.utc_now() |> DateTime.to_unix(:millisecond)
|
||||
|
||||
events = [
|
||||
|
||||
@@ -234,21 +234,7 @@ defmodule TeslaMate.Vehicles.Vehicle.StreamingTest do
|
||||
assert_receive :continue?
|
||||
refute_receive _
|
||||
end) =~ """
|
||||
Discarded stale fetch result: %{
|
||||
last: %TeslaApi.Vehicle.State.Drive{
|
||||
gps_as_of: nil,
|
||||
heading: 120,
|
||||
latitude: 42.1,
|
||||
longitude: 42.0,
|
||||
native_latitude: nil,
|
||||
native_location_supported: nil,
|
||||
native_longitude: nil,
|
||||
native_type: nil,
|
||||
power: 0,
|
||||
shift_state: \"D\",
|
||||
speed: 0,
|
||||
timestamp: #{DateTime.to_unix(d1, :millisecond)}
|
||||
},
|
||||
Discarded stale fetch result: [
|
||||
now: %TeslaApi.Vehicle.State.Drive{
|
||||
gps_as_of: nil,
|
||||
heading: nil,
|
||||
@@ -262,8 +248,22 @@ defmodule TeslaMate.Vehicles.Vehicle.StreamingTest do
|
||||
shift_state: \"P\",
|
||||
speed: 0,
|
||||
timestamp: #{now_ts}
|
||||
},
|
||||
last: %TeslaApi.Vehicle.State.Drive{
|
||||
gps_as_of: nil,
|
||||
heading: 120,
|
||||
latitude: 42.1,
|
||||
longitude: 42.0,
|
||||
native_latitude: nil,
|
||||
native_location_supported: nil,
|
||||
native_longitude: nil,
|
||||
native_type: nil,
|
||||
power: 0,
|
||||
shift_state: \"D\",
|
||||
speed: 0,
|
||||
timestamp: #{DateTime.to_unix(d1, :millisecond)}
|
||||
}
|
||||
}
|
||||
]
|
||||
"""
|
||||
|
||||
send(:"api_#{name}", :continue)
|
||||
|
||||
@@ -7,7 +7,7 @@ defmodule TeslaMateWeb.CarLive.Indextest do
|
||||
|
||||
describe "base URL" do
|
||||
@tag :signed_in
|
||||
test "initiall sets the base URL", %{conn: conn} do
|
||||
test "sets the base URL", %{conn: conn} do
|
||||
:ok = start_vehicles([{:ok, online_event()}])
|
||||
|
||||
assert %GlobalSettings{base_url: nil} = Settings.get_global_settings!()
|
||||
|
||||
@@ -369,7 +369,7 @@ defmodule TeslaMateWeb.GeoFenceLiveTest do
|
||||
describe "grafana URL" do
|
||||
alias TeslaMate.Settings.GlobalSettings
|
||||
|
||||
test "initiall sets the base URL", %{conn: conn} do
|
||||
test "sets the base URL", %{conn: conn} do
|
||||
assert %GlobalSettings{grafana_url: nil} = Settings.get_global_settings!()
|
||||
|
||||
assert {:ok, _parent_view, _html} =
|
||||
|
||||
Reference in New Issue
Block a user