Espex.HomeAssistantStates.Subscription (espex v0.12.0)

Copy Markdown View Source

One Home Assistant entity (or one of its attributes) the device asks Home Assistant to send the state of.

  • entity_id — the Home Assistant entity, such as "sun.sun": 1 to 255 bytes, containing a ..
  • attribute — an attribute of that entity, such as "elevation", up to 255 bytes, or nil for the entity's state.
  • once — true asks Home Assistant for the current value only, instead of every change. It is a hint to the client: espex passes every matching state to Espex.HomeAssistantStates.handle_state/3 either way.

Build one with new/1 or new!/1, which check the fields:

iex> Espex.HomeAssistantStates.Subscription.new!(entity_id: "sun.sun", attribute: "elevation")
%Espex.HomeAssistantStates.Subscription{entity_id: "sun.sun", attribute: "elevation", once: false}

A wizard input link (see Espex.Wizard.Input) is a subscription with entity_id: nil; the input's value fills it in.

Summary

Functions

Build a subscription from a keyword list, a map, or a subscription built by hand, checking each field.

Like new/1, but raises ArgumentError naming the bad field.

Types

t()

(since 0.12.0)
@type t() :: %Espex.HomeAssistantStates.Subscription{
  attribute: String.t() | nil,
  entity_id: String.t() | nil,
  once: boolean()
}

Functions

new(fields)

(since 0.12.0)
@spec new(keyword() | map() | t()) :: {:ok, t()} | {:error, :invalid_subscription}

Build a subscription from a keyword list, a map, or a subscription built by hand, checking each field.

An empty attribute is the same as nil. Returns {:error, :invalid_subscription} for an unknown key or a bad value.

new!(fields)

(since 0.12.0)
@spec new!(keyword() | map() | t()) :: t()

Like new/1, but raises ArgumentError naming the bad field.