# `Espex.Supervisor`
[🔗](https://github.com/bbangert/espex/blob/main/lib/espex/supervisor.ex#L1)

Top-level supervisor for an Espex server instance.

Starts children in `:rest_for_one` order:

  1. `Registry` (duplicate keys) — fan-out point for `Espex.push_state/2`.
  2. A cross-connection state server (internal) — holds the device
     config and adapter modules.
  3. `ThousandIsland` — TCP acceptor pool that spawns a per-client
     connection handler process (internal).
  4. An mDNS advertiser GenServer (internal) — optional, started
     only when `:mdns` is configured.

If the server child crashes, the listener and advertiser restart
too, so live connections drop rather than hold stale references.

Configuration is passed as keyword options:

    Espex.Supervisor.start_link(
      device_config: [name: "my-device"],   # or a %DeviceConfig{}
      port: 6053,                           # overrides device_config.port
      name: :my_espex,                      # supervisor registered name
      server_name: MyApp.EspexServer,       # Espex.Server registered name
      num_acceptors: 10,
      serial_proxy: MyApp.MySerialAdapter,
      zwave_proxy: MyApp.MyZWaveAdapter,
      infrared_proxy: MyApp.MyIRAdapter,
      entity_provider: MyApp.MyEntities,
      mdns: Espex.Mdns.MdnsLite
    )

Any adapter key omitted disables that feature. Pass `:mdns` with an
`Espex.Mdns` adapter module (e.g. `Espex.Mdns.MdnsLite`) to advertise
the server over mDNS; omit to skip.

# `bound_port`

```elixir
@spec bound_port(Supervisor.supervisor()) ::
  {:ok, :inet.port_number()} | {:error, term()}
```

Return the port the listener is currently bound to. Useful when
starting the server with `port: 0` (ephemeral) — typically in tests.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `registry_name`

```elixir
@spec registry_name(atom()) :: atom()
```

Return the conventional Registry name for a given server name.

# `start_link`

```elixir
@spec start_link(keyword()) :: Supervisor.on_start()
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
