mirror of
https://github.com/teslamate-org/teslamate.git
synced 2026-01-24 21:06:08 +08:00
22 lines
437 B
Elixir
22 lines
437 B
Elixir
defmodule TeslaMate.Mqtt.PubSub do
|
|
use Supervisor
|
|
|
|
alias __MODULE__.VehicleSubscriber
|
|
alias TeslaMate.Vehicles
|
|
|
|
# API
|
|
|
|
def start_link(opts) do
|
|
Supervisor.start_link(__MODULE__, opts, name: __MODULE__)
|
|
end
|
|
|
|
@impl true
|
|
def init(opts) do
|
|
children =
|
|
Vehicles.list()
|
|
|> Enum.map(&{VehicleSubscriber, Keyword.merge(opts, car_id: &1.car.id)})
|
|
|
|
Supervisor.init(children, strategy: :one_for_one)
|
|
end
|
|
end
|