Homex.Entity.Camera behaviour (homex v0.1.2)

Copy Markdown View Source

A camera entity for Homex

Implements a Homex.Entity. See module for available callbacks.

Home Assistant docs: https://www.home-assistant.io/integrations/camera.mqtt

Options

  • :name (String.t/0) - Required. the name of the entity

  • :update_interval - the interval in milliseconds in which handle_timer/1 get's called. Can also be :never to disable the timer callback The default value is 10000.

  • :retain (boolean/0) - if the last state should be retained The default value is true.

  • :enabled_by_default (boolean/0) - Flag which defines if the entity should be enabled when first added. The default value is true.

  • :encoding (String.t/0) - The encoding of the payloads received. Set to empty string to disable decoding of incoming payload. Use image_encoding to enable Base64 decoding on topic. The default value is "utf-8".

  • :image_encoding - The encoding of the image payloads received. Set to "b64" to enable base64 decoding of image payload. If not set, the image payload must be raw binary data. The default value is nil.

Overridable Functions

The following functions can be overridden in your entity:

Default Implementations

All overridable functions have safe default implementations that return the entity unchanged. You only need to override the functions you want to customize.

Example

defmodule MyCamera do
  use Homex.Entity.Camera, name: "my-camera"

  def handle_timer(entity) do
    img = Image.open!("some/path/to/image.jpg") |> Image.write!(:memory, suffix: ".jpg")
    entity |> set_image(img) |> set_attributes(%{foo: "bar"})
  end
end

Summary

Callbacks

set_attributes(entity, attributes)

@callback set_attributes(entity :: Homex.Entity.t(), attributes :: Map.t()) ::
  entity :: Homex.Entity.t()

sets the attributes

set_image(entity, image)

@callback set_image(entity :: Homex.Entity.t(), image :: binary()) ::
  entity :: Homex.Entity.t()

sets the image