Hassock.Registries (hassock v0.3.0)

Copy Markdown View Source

Fetch Home Assistant's floor, area, device, entity and label registries.

Each function sends the matching config/*_registry/list command through Hassock.Connection.command/4 and decodes the items into structs. Options: :timeout in ms (default 30 s; the entity registry of a large install is several MB).

list_entities/2 uses config/entity_registry/list, which returns full entries including hidden_by and disabled_by. HA's frontend uses the compact config/entity_registry/list_for_display instead: it abbreviates keys and leaves out disabled entities and some fields. Call it with Hassock.command/4 if you need it.

To keep the registries current, subscribe to their update events (Hassock.Protocol.registry_event_types/0) or use Hassock.RegistryCache.

Summary

Functions

Decode one registry item of kind into its struct.

The key that identifies an item of kind.

The registry kinds, in dependency order (floors before areas, ...).

List one registry by kind.

List all devices.

List all entity registry entries.

Types

kind()

@type kind() :: :floor | :area | :device | :entity | :label

Functions

decode(atom, map)

@spec decode(kind(), map()) :: struct()

Decode one registry item of kind into its struct.

id(arg1)

@spec id(struct()) :: String.t()

The key that identifies an item of kind.

kinds()

@spec kinds() :: [kind()]

The registry kinds, in dependency order (floors before areas, ...).

list(conn, kind, opts \\ [])

@spec list(GenServer.server(), kind(), keyword()) ::
  {:ok, [struct()]}
  | {:error, Hassock.Connection.command_error() | {:unexpected_result, term()}}

List one registry by kind.

list_areas(conn, opts \\ [])

@spec list_areas(GenServer.server(), keyword()) ::
  {:ok, [Hassock.Area.t()]} | {:error, Hassock.Connection.command_error()}

List all areas.

list_devices(conn, opts \\ [])

@spec list_devices(GenServer.server(), keyword()) ::
  {:ok, [Hassock.Device.t()]} | {:error, Hassock.Connection.command_error()}

List all devices.

list_entities(conn, opts \\ [])

@spec list_entities(GenServer.server(), keyword()) ::
  {:ok, [Hassock.EntityEntry.t()]}
  | {:error, Hassock.Connection.command_error()}

List all entity registry entries.

list_floors(conn, opts \\ [])

@spec list_floors(GenServer.server(), keyword()) ::
  {:ok, [Hassock.Floor.t()]} | {:error, Hassock.Connection.command_error()}

List all floors.

list_labels(conn, opts \\ [])

@spec list_labels(GenServer.server(), keyword()) ::
  {:ok, [Hassock.Label.t()]} | {:error, Hassock.Connection.command_error()}

List all labels.