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 whichhandle_timer/1get's called. Can also be:neverto disable the timer callback The default value is10000.:retain(boolean/0) - if the last state should be retained The default value istrue.:enabled_by_default(boolean/0) - Flag which defines if the entity should be enabled when first added. The default value istrue.: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 isnil.
Overridable Functions
The following functions can be overridden in your entity:
handle_init/1- FromHomex.Entityhandle_timer/1- FromHomex.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
@callback set_attributes(entity :: Homex.Entity.t(), attributes :: Map.t()) :: entity :: Homex.Entity.t()
sets the attributes
@callback set_image(entity :: Homex.Entity.t(), image :: binary()) :: entity :: Homex.Entity.t()
sets the image