image

Go types for Home Assistant's image domain: control over HTTP and MQTT, serve over MQTT discovery.

Control: HTTP Control: MQTT Serve a device Discovery config
import "github.com/taumatix/homeassistant-go/domains/image"

Overview

Package image is Home Assistant's image domain: its types and its MQTT discovery config.

Entity controls one image entity over HTTP or MQTT. Device serves one over MQTT.

Home Assistant documents the domain here:

Integration: https://www.home-assistant.io/integrations/image/

MQTT discovery: https://www.home-assistant.io/integrations/image.mqtt/

Entity model (developers): https://contributors.home-assistant.io/core/entities/image/

Control

// client is an *api.Client or a connected *mqtt.Client
target := image.Get(client, "my_image")
state, err := target.State(ctx)
err = target.Snapshot(ctx)

Serve

// mqttClient is a connected *mqtt.Client
device, err := image.NewDevice(ctx, mqttClient, "my-image",
	image.WithName("My image"),
)

Commands

What each Entity method does on each transport. MQTT publishes to the topic the entity's discovery config names in that option.

MethodOver HTTP, callsOver MQTT, publishes to
Snapshot image.snapshot not available

Control

type Entity struct

Entity controls one image entity over HTTP (api.Client) or MQTT (mqtt.Client). State and Subscribe come from the embedded Handle.

Embeds entity.Handle[Attributes], whose methods it has too.

func Get(transport entity.Transport, id string) *Entity

Get returns the image entity with the given id: an entity id over HTTP (the "image." prefix may be omitted), a discovery object path or unique id over MQTT. It does no I/O.

func List(ctx context.Context, transport entity.Transport) ([]*Entity, error)

List returns every image entity the transport can see: all of Home Assistant's over HTTP, the discovered ones over MQTT.

func (e *Entity) Snapshot(ctx context.Context, options ...entity.ServiceOption) error

Snapshot calls image.snapshot. It has no MQTT equivalent. Core describes the service: Takes a snapshot from an image.

type State = entity.State[Attributes]

State is a snapshot of one image entity.

func Filename(value string) entity.ServiceOption

Filename sets the "filename" service data field.

Serve over MQTT

type Device struct

Device is one image entity served by this process over MQTT. Close, Delete and ReportAvailability come from the embedded mqtt.Device.

Embeds *mqtt.Device, whose methods it has too.

func NewDevice(ctx context.Context, client *mqtt.Client, objectID string, options ...DeviceOption) (*Device, error)

NewDevice announces a image entity through MQTT discovery and returns the device serving it. objectID may carry one "node_id/" prefix. Command, state and availability topics default to <topic root>/image/<objectID>/... and the options can override them. The client must be connected.

func (d *Device) Config() Config

Config returns the discovery config announced to Home Assistant.

type DeviceOption func(config *Config)

DeviceOption customizes the discovery config of a device before it is announced. Options run before the default topics are derived, so a topic they set is kept.

func WithConfig(fn func(config *Config)) DeviceOption

WithConfig applies fn to the discovery config for adjustments not covered by the other options.

func WithDeviceDetails(details ha.MQTTDeviceDetails) DeviceOption

WithDeviceDetails ties the entity to a device in the Home Assistant device registry.

func WithName(name string) DeviceOption

WithName sets the friendly name announced to Home Assistant.

State and values

type Attributes struct

Attributes are the state attributes of a image entity, under the names Home Assistant publishes them with.

See: https://www.home-assistant.io/integrations/image/

FieldTypeWire keyDescription
AccessTokenstringaccess_token

MQTT discovery config

type Config struct

Config is the MQTT discovery config of image.

See: https://www.home-assistant.io/integrations/image.mqtt/

FieldTypeWire keyDescription
Availability[]ha.MQTTAvailabilityavailability
AvailabilityMode*stringavailability_mode

Allowed: "all", "any", "latest".

Default: "latest"

AvailabilityTemplate*ha.Templateavailability_template
AvailabilityTopic*stringavailability_topic

Topic to receive the availability payload on. NewDevice defaults it to <base>/availability.

ContentType*stringcontent_type

The content type or the image data that is received at the image topic.

DefaultEntityId*stringdefault_entity_id
Device*ha.MQTTDeviceDetailsdevice
EnabledByDefault*boolenabled_by_default

Default: true

Encoding*stringencoding

Default: "utf-8"

EntityCategory*stringentity_category

Allowed: "config", "diagnostic".

EntityPicture*stringentity_picture

An URL to a picture to be assigned.

Group[]stringgroup
Icon*ha.Iconicon
ImageEncoding*stringimage_encoding

Select the encoding of the received image data. Allowed: "b64", "raw".

ImageTopic*stringimage_topic

The library does not use it: carries image bytes or their URL, which have no state representation.

JsonAttributesTemplate*ha.Templatejson_attributes_template
JsonAttributesTopic*stringjson_attributes_topic

The library does not use it: extra attributes in a JSON document, which is not offered yet.

MessageExpiryInterval*map[string]anymessage_expiry_interval

Retention time interval for published message.

Name*stringname
Origin*ha.DeviceOriginorigin
PayloadAvailable*stringpayload_available

The payload that indicates the device is available (defaults to 'online').

Default: "online"

PayloadNotAvailable*stringpayload_not_available

The payload that indicates the device is not available (defaults to 'offline').

Default: "offline"

Qos*intqos

Default: 0

UniqueId*stringunique_id
UrlTemplate*ha.Templateurl_template
UrlTopic*stringurl_topic

NewDevice defaults it to <base>/url unless image_topic is set. The library does not use it: carries image bytes or their URL, which have no state representation.

VisibleByDefault*boolvisible_by_default

Default: true

func (*Config) IsMQTTDiscoverySchema()

IsMQTTDiscoverySchema marks Config as a discovery payload (ha.MQTTDiscoverySchema).