mirror of
https://github.com/netfun2000/hipudding-teslamate.git
synced 2026-02-27 09:44:28 +08:00
Add feature flags for MQTT and Logging
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user