Homex.Entity behaviour (homex v0.1.0)

View Source

Defines the behaviour and struct for an entity implementation

Summary

Callbacks

The Home Assistant component config definition

Configures the intial state for the switch

Handle a new message from the subscriptions

If an update_interval is set, this callback will be fired

The given name of the entity

The Home Assistant platform

The list of topics to subscribe to

The unique id of the entity

Functions

Gets the value from the Entity struct

Checks if the given module implements the behaviour from this module

Puts a value into the Entity struct to retrieve it later. Can be used as a key-value store for user data

Types

t()

@type t() :: %Homex.Entity{
  changes: map(),
  handlers: map(),
  keys: MapSet.t(),
  private: map(),
  values: map()
}

Callbacks

config()

@callback config() :: map()

The Home Assistant component config definition

handle_init(entity)

@callback handle_init(entity :: t()) :: entity :: t()

Configures the intial state for the switch

handle_message({}, entity)

@callback handle_message(
  {topic :: String.t(), payload :: term()},
  entity :: t()
) :: entity :: t()

Handle a new message from the subscriptions

handle_timer(entity)

@callback handle_timer(entity :: Entity.t()) :: entity :: t()

If an update_interval is set, this callback will be fired

name()

@callback name() :: String.t()

The given name of the entity

platform()

@callback platform() :: String.t()

The Home Assistant platform

subscriptions()

@callback subscriptions() :: [String.t()]

The list of topics to subscribe to

unique_id()

@callback unique_id() :: String.t()

The unique id of the entity

Functions

get_private(entity, key)

@spec get_private(t(), atom()) :: term()

Gets the value from the Entity struct

implements_behaviour?(module)

@spec implements_behaviour?(atom()) :: boolean()

Checks if the given module implements the behaviour from this module

put_private(entity, key, value)

@spec put_private(t(), atom(), term()) :: t()

Puts a value into the Entity struct to retrieve it later. Can be used as a key-value store for user data