diff --git a/config/releases.exs b/config/releases.exs index fa3cd5dd..498ee975 100644 --- a/config/releases.exs +++ b/config/releases.exs @@ -5,7 +5,7 @@ config :teslamate, TeslaMate.Repo, password: System.fetch_env!("DATABASE_PASS"), database: System.fetch_env!("DATABASE_NAME"), hostname: System.fetch_env!("DATABASE_HOST"), - pool_size: 15 + pool_size: System.get_env("DATABASE_POOL_SIZE", "15") |> String.to_integer() config :teslamate, TeslaMateWeb.Endpoint, http: [:inet6, port: System.get_env("PORT", "4000")], @@ -19,28 +19,27 @@ config :teslamate, :tesla_auth, username: System.fetch_env!("TESLA_USERNAME"), password: System.fetch_env!("TESLA_PASSWORD") -config :teslamate, :mqtt, - host: System.fetch_env!("MQTT_HOST"), - username: System.fetch_env!("MQTT_USERNAME"), - password: System.fetch_env!("MQTT_PASSWORD") +if System.get_env("DISABLE_MQTT") != "true" do + config :teslamate, :mqtt, + host: System.fetch_env!("MQTT_HOST"), + username: System.fetch_env!("MQTT_USERNAME"), + password: System.fetch_env!("MQTT_PASSWORD") +end config :logger, - backends: [LoggerTelegramBackend, :console], level: :info, - handle_otp_reports: true, - handle_sasl_reports: false, - compile_time_purge_level: :info + compile_time_purge_matching: [[level_lower_than: :info]] config :logger, :console, format: "$time $metadata[$level] $message\n", metadata: [] -config :logger, :telegram, - level: :error, - chat_id: System.fetch_env!("CHAT_ID"), - token: System.fetch_env!("TOKEN") +if System.get_env("ENABLE_LOGGER_TELEGRAM") == "true" do + config :logger, + backends: [LoggerTelegramBackend, :console] -config :teslamate, :mqtt, - host: System.fetch_env!("MQTT_HOST"), - username: System.fetch_env!("MQTT_USERNAME"), - password: System.fetch_env!("MQTT_PASSWORD") + config :logger, :telegram, + level: :error, + chat_id: System.fetch_env!("CHAT_ID"), + token: System.fetch_env!("TOKEN") +end diff --git a/lib/teslamate/api.ex b/lib/teslamate/api.ex index 8e62e2a5..a42b7bd9 100644 --- a/lib/teslamate/api.ex +++ b/lib/teslamate/api.ex @@ -39,7 +39,8 @@ defmodule TeslaMate.Api do # Callbacks @impl true - def init(opts) do + def init(_opts) do + opts = Application.fetch_env!(:teslamate, :tesla_auth) username = Keyword.fetch!(opts, :username) password = Keyword.fetch!(opts, :password) diff --git a/lib/teslamate/application.ex b/lib/teslamate/application.ex index 2d0cf8a4..3da0e3e6 100644 --- a/lib/teslamate/application.ex +++ b/lib/teslamate/application.ex @@ -1,21 +1,18 @@ defmodule TeslaMate.Application do - # See https://hexdocs.pm/elixir/Application.html - # for more information on OTP Applications @moduledoc false use Application def start(_type, _args) do - children = [ + [ TeslaMate.Repo, TeslaMateWeb.Endpoint, - TeslaMateWeb.Presence, - {TeslaMate.Api, auth()}, + TeslaMate.Api, TeslaMate.Vehicles, - TeslaMate.Mqtt + if(enable_mqtt, do: TeslaMate.Mqtt) ] - - Supervisor.start_link(children, strategy: :one_for_one, name: TeslaMate.Supervisor) + |> Enum.reject(&is_nil/1) + |> Supervisor.start_link(strategy: :one_for_one, name: TeslaMate.Supervisor) end # Tell Phoenix to update the endpoint configuration @@ -25,8 +22,5 @@ defmodule TeslaMate.Application do :ok end - # TODO move into Api (get_lazy) - defp auth do - Application.get_env(:teslamate, :tesla_auth) - end + defp enable_mqtt, do: !is_nil(Application.get_env(:teslamate, :mqtt)) end