Overview
Package vacuum is Home Assistant's vacuum domain: its types and its MQTT discovery config.
Entity controls one vacuum entity over HTTP or MQTT. Device serves one over MQTT.
The MQTT vacuum state topic carries a JSON document and is not decoded yet.
Home Assistant documents the domain here:
Integration: https://www.home-assistant.io/integrations/vacuum/
MQTT discovery: https://www.home-assistant.io/integrations/vacuum.mqtt/
Entity model (developers): https://contributors.home-assistant.io/core/entities/vacuum/
Control
// client is an *api.Client or a connected *mqtt.Client
target := vacuum.Get(client, "my_vacuum")
state, err := target.State(ctx)
err = target.CleanArea(ctx)Serve
// mqttClient is a connected *mqtt.Client
device, err := vacuum.NewDevice(ctx, mqttClient, "my-vacuum",
vacuum.WithName("My vacuum"),
)
Commands
What each Entity method does on each transport. MQTT publishes to the topic the entity's discovery config names in that option.
| Method | Over HTTP, calls | Over MQTT, publishes to |
|---|---|---|
SetFanSpeed |
vacuum.set_fan_speed |
set_fan_speed_topic |
CleanArea |
vacuum.clean_area |
not available |
CleanSpot |
vacuum.clean_spot |
command_topic |
Locate |
vacuum.locate |
command_topic |
Pause |
vacuum.pause |
command_topic |
ReturnToBase |
vacuum.return_to_base |
command_topic |
Start |
vacuum.start |
command_topic |
Stop |
vacuum.stop |
command_topic |
Services without a method
Call these with the REST or WebSocket client.
| Service | Why |
|---|---|
vacuum.send_command | needs required parameters; not offered yet |
Control
type Entity struct
Entity controls one vacuum 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 vacuum entity with the given id: an entity id over HTTP (the "vacuum." 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 vacuum entity the transport can see: all of Home Assistant's over HTTP, the discovered ones over MQTT.
func (e *Entity) CleanArea(ctx context.Context, options ...entity.ServiceOption) error
CleanArea calls vacuum.clean_area. It has no MQTT equivalent. Core describes the service: Tells a vacuum cleaner to clean one or more areas.
func (e *Entity) CleanSpot(ctx context.Context) error
CleanSpot calls vacuum.clean_spot, or publishes payload_clean_spot to command_topic. Core describes the service: Tells a vacuum cleaner to do a spot clean-up.
func (e *Entity) Locate(ctx context.Context) error
Locate calls vacuum.locate, or publishes payload_locate to command_topic. Core describes the service: Locates a vacuum cleaner.
func (e *Entity) Pause(ctx context.Context) error
Pause calls vacuum.pause, or publishes payload_pause to command_topic. Core describes the service: Pauses a vacuum cleaner's current task.
func (e *Entity) ReturnToBase(ctx context.Context) error
ReturnToBase calls vacuum.return_to_base, or publishes payload_return_to_base to command_topic. Core describes the service: Sends a vacuum cleaner back to its dock.
func (e *Entity) SetFanSpeed(ctx context.Context, fanSpeed string) error
SetFanSpeed calls vacuum.set_fan_speed, or publishes to set_fan_speed_topic. Core describes the service: Sets the fan speed of a vacuum cleaner.
func (e *Entity) Start(ctx context.Context) error
Start calls vacuum.start, or publishes payload_start to command_topic. Core describes the service: Starts or resumes a vacuum cleaner's cleaning task.
func (e *Entity) Stop(ctx context.Context) error
Stop calls vacuum.stop, or publishes payload_stop to command_topic. Core describes the service: Stops a vacuum cleaner's current task.
type State = entity.State[Attributes]
State is a snapshot of one vacuum entity.
func CleaningAreaId(value []string) entity.ServiceOption
CleaningAreaId sets the "cleaning_area_id" service data field.
Serve over MQTT
type Device struct
Device is one vacuum entity served by this process over MQTT. Close, Delete and ReportAvailability come from the embedded mqtt.Device.
Commands from Home Assistant arrive through the On*Command callbacks. A callback's ctx is cancelled when the client closes; an error it returns goes to the client's error path (mqtt.WithLogger, mqtt.WithOnError).
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 vacuum 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>/vacuum/<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.
func (d *Device) OnCleanSpotCommand(fn func(ctx context.Context) error)
OnCleanSpotCommand registers the callback for Home Assistant requesting clean_spot.
func (d *Device) OnFanSpeedCommand(fn func(ctx context.Context, fanSpeed string) error)
OnFanSpeedCommand registers the callback for Home Assistant requesting a change of fan_speed.
func (d *Device) OnLocateCommand(fn func(ctx context.Context) error)
OnLocateCommand registers the callback for Home Assistant requesting locate.
func (d *Device) OnPauseCommand(fn func(ctx context.Context) error)
OnPauseCommand registers the callback for Home Assistant requesting pause.
func (d *Device) OnReturnToBaseCommand(fn func(ctx context.Context) error)
OnReturnToBaseCommand registers the callback for Home Assistant requesting return_to_base.
func (d *Device) OnStartCommand(fn func(ctx context.Context) error)
OnStartCommand registers the callback for Home Assistant requesting start.
func (d *Device) OnStopCommand(fn func(ctx context.Context) error)
OnStopCommand registers the callback for Home Assistant requesting stop.
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 vacuum entity, under the names Home Assistant publishes them with.
See: https://www.home-assistant.io/integrations/vacuum/
| Field | Type | Wire key | Description |
|---|---|---|---|
FanSpeed | *string | fan_speed | |
FanSpeedList | []string | fan_speed_list | Over MQTT it comes from the fan_speed_list option. |
SupportedFeatures | Feature | supported_features | A set of Feature flags. |
Activity
type Activity string
Activity is core's VacuumActivity.
| Constant | Value |
|---|---|
ActivityUnknown | "Unknown" |
ActivityCleaning | "cleaning" |
ActivityDocked | "docked" |
ActivityIdle | "idle" |
ActivityPaused | "paused" |
ActivityReturning | "returning" |
ActivityError | "error" |
func ActivityFromString(s string) Activity
ActivityFromString returns the Activity spelled s, by its value or by the name of core's member, and ActivityUnknown for anything else.
func (v *Activity) UnmarshalJSON(data []byte) error
UnmarshalJSON reads any spelling ActivityFromString accepts.
Feature
type Feature uint64
Feature is a set of vacuum supported features, with the values of core's VacuumEntityFeature: the supported_features attribute decodes into it.
| Constant | Value |
|---|---|
FeatureUnknown | 0 |
FeatureTurnOn | 1 << 0 |
FeatureTurnOff | 1 << 1 |
FeaturePause | 1 << 2 |
FeatureStop | 1 << 3 |
FeatureReturnHome | 1 << 4 |
FeatureFanSpeed | 1 << 5 |
FeatureStatus | 1 << 7 |
FeatureSendCommand | 1 << 8 |
FeatureLocate | 1 << 9 |
FeatureCleanSpot | 1 << 10 |
FeatureMap | 1 << 11 |
FeatureState | 1 << 12 |
FeatureStart | 1 << 13 |
FeatureCleanArea | 1 << 14 |
func FeatureFromString(s string) Feature
FeatureFromString returns the Feature spelled s, by its value or by the name of core's member, and FeatureUnknown for anything else.
type Segment struct
Segment is core's Segment.
See: https://www.home-assistant.io/integrations/vacuum/
| Field | Type | Wire key | Description |
|---|---|---|---|
Group | *string | group | |
Id | string | id | |
Name | string | name |
MQTT discovery config
type Config struct
Config is the MQTT discovery config of vacuum.
See: https://www.home-assistant.io/integrations/vacuum.mqtt/
| Field | Type | Wire key | Description |
|---|---|---|---|
Availability | []ha.MQTTAvailability | availability | |
AvailabilityMode | *string | availability_mode | Allowed: "all", "any", "latest". Default: "latest" |
AvailabilityTemplate | *ha.Template | availability_template | |
AvailabilityTopic | *string | availability_topic | Topic to receive the availability payload on. NewDevice defaults it to <base>/availability. |
CleanSegmentsCommandTemplate | *ha.Template | clean_segments_command_template | |
CleanSegmentsCommandTopic | *string | clean_segments_command_topic | The library does not use it: not offered yet; adding it is additive. |
CommandTopic | *string | command_topic | Entity.CleanSpot publishes to it. Entity.Locate publishes to it. Entity.Pause publishes to it. Entity.ReturnToBase publishes to it. Entity.Start publishes to it. Entity.Stop publishes to it. Device.OnCleanSpotCommand receives what is published to it. Device.OnLocateCommand receives what is published to it. Device.OnPauseCommand receives what is published to it. Device.OnReturnToBaseCommand receives what is published to it. Device.OnStartCommand receives what is published to it. Device.OnStopCommand receives what is published to it. NewDevice defaults it to <base>/clean_spot/set. |
DefaultEntityId | *string | default_entity_id | |
Device | *ha.MQTTDeviceDetails | device | |
EnabledByDefault | *bool | enabled_by_default | Default: true |
Encoding | *string | encoding | Default: "utf-8" |
EntityCategory | *string | entity_category | Allowed: "config", "diagnostic". |
EntityPicture | *string | entity_picture | An URL to a picture to be assigned. |
FanSpeedList | []string | fan_speed_list | Over MQTT, Entity reports it as the "fan_speed_list" attribute. |
Group | []string | group | |
Icon | *ha.Icon | icon | |
JsonAttributesTemplate | *ha.Template | json_attributes_template | |
JsonAttributesTopic | *string | json_attributes_topic | The library does not use it: extra attributes in a JSON document, which is not offered yet. |
MessageExpiryInterval | *map[string]any | message_expiry_interval | Retention time interval for published message. |
Name | *string | name | |
Origin | *ha.DeviceOrigin | origin | |
PayloadAvailable | *string | payload_available | The payload that indicates the device is available (defaults to 'online'). Default: "online" |
PayloadCleanSpot | *string | payload_clean_spot | Entity.CleanSpot publishes it. Device.OnCleanSpotCommand matches the received payload against it. Default: "clean_spot" |
PayloadLocate | *string | payload_locate | Entity.Locate publishes it. Device.OnLocateCommand matches the received payload against it. Default: "locate" |
PayloadNotAvailable | *string | payload_not_available | The payload that indicates the device is not available (defaults to 'offline'). Default: "offline" |
PayloadPause | *string | payload_pause | Entity.Pause publishes it. Device.OnPauseCommand matches the received payload against it. Default: "pause" |
PayloadReturnToBase | *string | payload_return_to_base | Entity.ReturnToBase publishes it. Device.OnReturnToBaseCommand matches the received payload against it. Default: "return_to_base" |
PayloadStart | *string | payload_start | Entity.Start publishes it. Device.OnStartCommand matches the received payload against it. Default: "start" |
PayloadStop | *string | payload_stop | Entity.Stop publishes it. Device.OnStopCommand matches the received payload against it. Default: "stop" |
Qos | *int | qos | Default: 0 |
Retain | *bool | retain | Default: false |
SendCommandTopic | *string | send_command_topic | The library does not use it: not offered yet; adding it is additive. |
SetFanSpeedTopic | *string | set_fan_speed_topic | Entity.SetFanSpeed publishes to it. Device.OnFanSpeedCommand receives what is published to it. NewDevice defaults it to <base>/set_fan_speed/set. |
StateTopic | *string | state_topic | The library does not use it: carries a JSON document, which is not decoded yet. |
SupportedFeatures | []string | supported_features | The features that the entity supports. Allowed: "start", "pause", "stop", "return_home", "fan_speed", "status", "send_command", "locate", "clean_spot". Default: [ "start", "stop", "return_home", "clean_spot" ] |
UniqueId | *string | unique_id | |
VisibleByDefault | *bool | visible_by_default | Default: true |
func (*Config) IsMQTTDiscoverySchema()
IsMQTTDiscoverySchema marks Config as a discovery payload (ha.MQTTDiscoverySchema).