# `Homex`
[🔗](https://github.com/kevinschweikert/homex/blob/v0.1.2/lib/homex.ex#L1)

## Configuration

You can configure `Homex` through a normal config entry like

```elixir
import Config

config :homex,
  broker: [host: "localhost", port: 1883],
  entities: [MyEntity]
```

The available options are documented in `Homex.Config`.

## Usage

Define a module for the type of entity you want to use. The available types are:

- `Homex.Entity.Switch`
- `Homex.Entity.Sensor`
- `Homex.Entity.Light`

```elixir
defmodule MySwitch do
  use Homex.Entity.Switch, name: "my-switch"

  def handle_on(state) do
    IO.puts("Switch turned on")
    {:noreply, state}
  end

  def handle_off(state) do
    IO.puts("Switch turned off")
    {:noreply, state}
  end
end
```

Configure broker and entities. Entities can also be added/removed at runtime with `Homex.add_entity/1` or `Homex.remove_entity/1`.

```elixir
import Config

config :homex,
  entities: [MySwitch]
```

Add `homex` to you supervision tree

```elixir
defmodule MyApp.Application do
  def start(_type, _args) do
    children =
      [
        ...,
        Homex,
        ...
      ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end
```

# `add_entities`

# `add_entity`

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `connected?`

# `publish`

# `remove_entity`

# `start_link`

---

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