Documentation ¶
Index ¶
- Variables
- type AttributeOption
- type ButtonEntity
- func (e *ButtonEntity) MarshalConfig() (*mqttapi.Msg, error)
- func (e *ButtonEntity) WithAttributes(options ...AttributeOption) *ButtonEntity
- func (e *ButtonEntity) WithButtonType(buttonType ButtonType) *ButtonEntity
- func (e *ButtonEntity) WithCommand(options ...CommandOption) *ButtonEntity
- func (e *ButtonEntity) WithDetails(options ...DetailsOption) *ButtonEntity
- func (e *ButtonEntity) WithPressPayload(payload string) *ButtonEntity
- type ButtonType
- type CameraEntity
- type CommandOption
- type DetailsOption
- func App(app string) DetailsOption
- func AsDiagnostic() DetailsOption
- func DefaultOriginInfo() DetailsOption
- func DeviceInfo(d *Device) DetailsOption
- func ID(id string) DetailsOption
- func Icon(icon string) DetailsOption
- func Name(name string) DetailsOption
- func NotEnabledByDefault() DetailsOption
- func OriginInfo(o *Origin) DetailsOption
- type Device
- type EncodingOption
- type EntityAttributes
- type EntityAvailability
- type EntityCommand
- type EntityDetails
- type EntityEncoding
- type EntityState
- type EntityType
- type ImageEntity
- func (e *ImageEntity) GetImageTopic() string
- func (e *ImageEntity) MarshalConfig() (*mqttapi.Msg, error)
- func (e *ImageEntity) WithAttributes(options ...AttributeOption) *ImageEntity
- func (e *ImageEntity) WithContentType(contentType string) *ImageEntity
- func (e *ImageEntity) WithDetails(options ...DetailsOption) *ImageEntity
- func (e *ImageEntity) WithEncoding(options ...EncodingOption) *ImageEntity
- func (e *ImageEntity) WithMode(mode ImageMode) *ImageEntity
- func (e *ImageEntity) WithURLTemplate(template string) *ImageEntity
- type ImageMode
- type NumberEntity
- func (e *NumberEntity[T]) MarshalConfig() (*mqttapi.Msg, error)
- func (e *NumberEntity[T]) OptimisticMode() *NumberEntity[T]
- func (e *NumberEntity[T]) WithAttributes(options ...AttributeOption) *NumberEntity[T]
- func (e *NumberEntity[T]) WithCommand(options ...CommandOption) *NumberEntity[T]
- func (e *NumberEntity[T]) WithDetails(options ...DetailsOption) *NumberEntity[T]
- func (e *NumberEntity[T]) WithMax(max T) *NumberEntity[T]
- func (e *NumberEntity[T]) WithMin(min T) *NumberEntity[T]
- func (e *NumberEntity[T]) WithMode(mode NumberMode) *NumberEntity[T]
- func (e *NumberEntity[T]) WithResetPayload(payload string) *NumberEntity[T]
- func (e *NumberEntity[T]) WithState(options ...StateOption) *NumberEntity[T]
- func (e *NumberEntity[T]) WithStep(step T) *NumberEntity[T]
- type NumberMode
- type Origin
- type SensorEntity
- func (e *SensorEntity) ForcedUpdates() *SensorEntity
- func (e *SensorEntity) MarshalConfig() (*mqttapi.Msg, error)
- func (e *SensorEntity) WithAttributes(options ...AttributeOption) *SensorEntity
- func (e *SensorEntity) WithDetails(options ...DetailsOption) *SensorEntity
- func (e *SensorEntity) WithLastResetValueTemplate(template string) *SensorEntity
- func (e *SensorEntity) WithState(options ...StateOption) *SensorEntity
- func (e *SensorEntity) WithStateExpiry(expiry time.Duration) *SensorEntity
- type StateOption
- func DeviceClass(class string) StateOption
- func StateCallback(callback func(args ...any) (json.RawMessage, error)) StateOption
- func StateClassMeasurement() StateOption
- func StateClassTotal() StateOption
- func StateClassTotalIncreasing() StateOption
- func SuggestedPrecision(p uint) StateOption
- func Units(u string) StateOption
- func ValueTemplate(t string) StateOption
- type SwitchEntity
- func (e *SwitchEntity) MarshalConfig() (*mqttapi.Msg, error)
- func (e *SwitchEntity) OptimisticMode() *SwitchEntity
- func (e *SwitchEntity) WithAttributes(options ...AttributeOption) *SwitchEntity
- func (e *SwitchEntity) WithCommand(options ...CommandOption) *SwitchEntity
- func (e *SwitchEntity) WithDetails(options ...DetailsOption) *SwitchEntity
- func (e *SwitchEntity) WithOffPayload(payload string) *SwitchEntity
- func (e *SwitchEntity) WithOnPayload(payload string) *SwitchEntity
- func (e *SwitchEntity) WithState(options ...StateOption) *SwitchEntity
- func (e *SwitchEntity) WithStateOff(payload string) *SwitchEntity
- func (e *SwitchEntity) WithStateOn(payload string) *SwitchEntity
- type TextEntity
- func (e *TextEntity) MarshalConfig() (*mqttapi.Msg, error)
- func (e *TextEntity) WithAttributes(options ...AttributeOption) *TextEntity
- func (e *TextEntity) WithCommand(options ...CommandOption) *TextEntity
- func (e *TextEntity) WithDetails(options ...DetailsOption) *TextEntity
- func (e *TextEntity) WithMax(max int) *TextEntity
- func (e *TextEntity) WithMin(min int) *TextEntity
- func (e *TextEntity) WithMode(mode TextEntityMode) *TextEntity
- func (e *TextEntity) WithPattern(pattern string) *TextEntity
- func (e *TextEntity) WithState(options ...StateOption) *TextEntity
- type TextEntityMode
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoStateCallback = errors.New("no state callback function") ErrNoCommandCallback = errors.New("no command callback function") )
var HomeAssistantTopic = "homeassistant"
HomeAssistantTopic is the prefix applied to all entity topics by default. Typically, this defaults to "homeassistant". It is exposed by this package such that it can be overridden as necessary.
Functions ¶
This section is empty.
Types ¶
type AttributeOption ¶
type AttributeOption func(*EntityAttributes) *EntityAttributes
func AttributesCallback ¶
func AttributesCallback(c func(args ...any) (json.RawMessage, error)) AttributeOption
WithAttributesCallback will add the passed in function as the callback action to be run whenever the attributes of the entity are needed. If this callback is to be used, then the WithAttributesTopic() builder function should also be called to set-up the attributes topic.
func AttributesTemplate ¶
func AttributesTemplate(t string) AttributeOption
WithAttributesTemplate configures the passed in template to be used to extract the value of the attributes in Home Assistant.
type ButtonEntity ¶
type ButtonEntity struct { *EntityDetails *EntityCommand *EntityAttributes ButtonType string `json:"device_class,omitempty"` PayloadPress string `json:"payload_press,omitempty"` }
ButtonEntity represents an entity which can perform some action or event in response to being "pushed". For more details, see https://www.home-assistant.io/integrations/button.mqtt/
func NewButtonEntity ¶
func NewButtonEntity() *ButtonEntity
func (*ButtonEntity) MarshalConfig ¶
func (e *ButtonEntity) MarshalConfig() (*mqttapi.Msg, error)
func (*ButtonEntity) WithAttributes ¶
func (e *ButtonEntity) WithAttributes(options ...AttributeOption) *ButtonEntity
func (*ButtonEntity) WithButtonType ¶
func (e *ButtonEntity) WithButtonType(buttonType ButtonType) *ButtonEntity
WithButtonType sets the type of button, defining how it gets displayed in Home Assistant. See also: https://www.home-assistant.io/integrations/button/#device-class
func (*ButtonEntity) WithCommand ¶
func (e *ButtonEntity) WithCommand(options ...CommandOption) *ButtonEntity
func (*ButtonEntity) WithDetails ¶
func (e *ButtonEntity) WithDetails(options ...DetailsOption) *ButtonEntity
func (*ButtonEntity) WithPressPayload ¶
func (e *ButtonEntity) WithPressPayload(payload string) *ButtonEntity
WithPressPayload sets the payload to send to trigger the button. Defaults to PRESS.
type ButtonType ¶
type ButtonType int
const ( ButtonTypeNone ButtonType = iota // ButtonTypeIdentify // identify ButtonTypeRestart // restart ButtonTypeUpdate // update )
func (ButtonType) String ¶
func (i ButtonType) String() string
type CameraEntity ¶
type CameraEntity struct { *EntityDetails *EntityAttributes *EntityEncoding Topic string `json:"topic" validate:"required"` }
CameraEntity represents an entity which sends image files through MQTT. For more details, see https://www.home-assistant.io/integrations/camera.mqtt/
func NewCameraEntity ¶
func NewCameraEntity() *CameraEntity
func (*CameraEntity) MarshalConfig ¶
func (e *CameraEntity) MarshalConfig() (*mqttapi.Msg, error)
func (*CameraEntity) WithAttributes ¶
func (e *CameraEntity) WithAttributes(options ...AttributeOption) *CameraEntity
func (*CameraEntity) WithDetails ¶
func (e *CameraEntity) WithDetails(options ...DetailsOption) *CameraEntity
func (*CameraEntity) WithEncoding ¶
func (e *CameraEntity) WithEncoding(options ...EncodingOption) *CameraEntity
type CommandOption ¶
type CommandOption func(*EntityCommand) *EntityCommand
func CommandCallback ¶
func CommandCallback(callback func(p *paho.Publish)) CommandOption
type DetailsOption ¶
type DetailsOption func(*EntityDetails) *EntityDetails
func AsDiagnostic ¶
func AsDiagnostic() DetailsOption
AsDiagnostic ensures that the entity will appear as a diagnostic entity in Home Assistant.
func DefaultOriginInfo ¶
func DefaultOriginInfo() DetailsOption
DefaultOriginInfo adds a pre-filled origin that references go-hass-agent to the entity config.
func DeviceInfo ¶
func DeviceInfo(d *Device) DetailsOption
WithDeviceInfo adds the passed in device info to the entity config.
func ID ¶
func ID(id string) DetailsOption
ID assigns the passed in name to the entity. It will format the value to be appropriate for an entity name.
func Icon ¶
func Icon(icon string) DetailsOption
Icon assigns the passed in icon string to the entity.
func NotEnabledByDefault ¶
func NotEnabledByDefault() DetailsOption
NotEnabledByDefault ensures that the entity will not be enabled by default when first added to Home Assistant.
func OriginInfo ¶
func OriginInfo(o *Origin) DetailsOption
WithOriginInfo adds the passed in origin info to the entity config.
type Device ¶
type Device struct { Name string `json:"name"` Manufacturer string `json:"manufacturer,omitempty"` Model string `json:"model,omitempty"` HWVersion string `json:"hw_version,omitempty"` SWVersion string `json:"sw_version,omitempty"` URL string `json:"configuration_url,omitempty"` SuggestedArea string `json:"suggested_area,omitempty"` Identifiers []string `json:"identifiers"` Connections []string `json:"connections,omitempty"` }
Device contains information about the device an entity is a part of to tie it into the device registry in Home Assistant.
type EncodingOption ¶
type EncodingOption func(*EntityEncoding) *EntityEncoding
func WithBase64ImageEncoding ¶
func WithBase64ImageEncoding() EncodingOption
func WithEncoding ¶
func WithEncoding(encoding string) EncodingOption
WithEncoding sets the encoding of the payloads.
func WithImageEncoding ¶
func WithImageEncoding(encoding string) EncodingOption
WithImageEncoding sets the image encoding of the payloads. By default, an entity publishes images as raw binary data on the topic.
type EntityAttributes ¶
type EntityAttributes struct { // AttributesTopic defines the MQTT topic subscribed to receive a JSON // dictionary payload and then set as sensor attributes. Implies force_update // of the current sensor state when a message is received on this topic. AttributesTopic string `json:"json_attributes_topic,omitempty" validate:"required"` AttributesTemplate string `json:"json_attributes_template,omitempty"` // contains filtered or unexported fields }
EntityAttributes are the fields that can be used for entities that have additional attributes.
func WithAttributesOptions ¶
func WithAttributesOptions(options ...AttributeOption) *EntityAttributes
func (*EntityAttributes) MarshalAttributes ¶
func (e *EntityAttributes) MarshalAttributes(args ...any) (*mqttapi.Msg, error)
MarshalAttributes will generate an *mqtt.Msg for the attributes of an entity, that can be used for updating the entity's attributes.
type EntityAvailability ¶
type EntityAvailability struct { AvailabilityTopic string `json:"availability_topic,omitempty" validate:"required"` AvailabilityTemplate string `json:"availability_template,omitempty"` PayloadAvailable string `json:"payload_available,omitempty"` PayloadNotAvailable string `json:"payload_not_available,omitempty"` }
type EntityCommand ¶
type EntityCommand struct { CommandTopic string `json:"command_topic" validate:"required"` // contains filtered or unexported fields }
func WithCommandOptions ¶
func WithCommandOptions(options ...CommandOption) *EntityCommand
func (*EntityCommand) MarshalSubscription ¶
func (e *EntityCommand) MarshalSubscription() (*mqttapi.Subscription, error)
MarshallSubscription will generate an *mqtt.Subscription for a given entity, which can be used to subscribe to an entity's command topic and execute a callback on messages.
type EntityDetails ¶
type EntityDetails struct { Origin *Origin `json:"origin,omitempty"` Device *Device `json:"device,omitempty"` UniqueID string `json:"unique_id" validate:"required"` Name string `json:"name" validate:"required"` Category string `json:"entity_category,omitempty"` Icon string `json:"icon,omitempty" validate:"omitempty,startswith=mdi:"` Enabled bool `json:"enabled_by_default"` // contains filtered or unexported fields }
func WithDetails ¶
func WithDetails(entityType EntityType, options ...DetailsOption) *EntityDetails
WithDetails will assign all of the passed in details options to the entity. Additionally, it will convieniently set the origin info of the entity to "Go Hass Anything" where no custom origin is desired.
type EntityEncoding ¶
type EntityEncoding struct { Encoding string `json:"encoding,omitempty"` ImageEncoding string `json:"image_encoding,omitempty"` }
func WithEncodingOptions ¶
func WithEncodingOptions(options ...EncodingOption) *EntityEncoding
type EntityState ¶
type EntityState struct { // StateTopic is the MQTT topic subscribed to receive state updates. A “None” payload resets // to an unknown state. An empty payload is ignored. StateTopic string `json:"state_topic" validate:"required"` ValueTemplate string `json:"value_template"` UnitOfMeasurement string `json:"unit_of_measurement,omitempty"` StateClass string `json:"state_class,omitempty"` DeviceClass string `json:"device_lass,omitempty"` SuggestedPrecision uint `json:"suggested_display_precision,omitempty"` // contains filtered or unexported fields }
EntityState represents all the fields that can be used for an entity that has a state.
func WithStateOptions ¶
func WithStateOptions(options ...StateOption) *EntityState
WithStateOptions will assign all of the passed in options to the EntityState. It will also generate an appropriate state topic using the given entity ID and type.
func (*EntityState) MarshalState ¶
func (e *EntityState) MarshalState(args ...any) (*mqttapi.Msg, error)
MarshalState will generate an *mqtt.Msg for a given entity, that can be used to publish the entity's state to the MQTT bus.
type EntityType ¶
type EntityType int
EntityType is an iota that represents the type of entity (i.e., Switch or Sensor).
const ( Unknown EntityType = iota // unknown // An entity with some kind of value, numeric or string. Sensor // sensor // An entity with a boolean value. BinarySensor // binary_sensor // An entity that changes state when activated. Button // button // An entity that is a number (float or int) with a range of values. Number // number // An entity that changes state between ON and OFF. Switch // switch // An entity that can show/set a string of text. Text // text // Any entity that can send images. Camera // camera // Any entity that can send images. Image // image )
func (EntityType) String ¶
func (i EntityType) String() string
type ImageEntity ¶
type ImageEntity struct { *EntityDetails *EntityAttributes *EntityEncoding ImageTopic string `json:"image_topic,omitempty" validate:"required_without=URLTopic"` ContentType string `json:"content_type,omitempty"` URLTopic string `json:"url_topic,omitempty" validate:"required_without=ImageTopic"` URLTemplate string `json:"url_template,omitempty"` // contains filtered or unexported fields }
ImageEntity represents an entity which sends image files through MQTT. For more details, see https://www.home-assistant.io/integrations/image.mqtt/
func NewImageEntity ¶
func NewImageEntity() *ImageEntity
func (*ImageEntity) GetImageTopic ¶
func (e *ImageEntity) GetImageTopic() string
func (*ImageEntity) MarshalConfig ¶
func (e *ImageEntity) MarshalConfig() (*mqttapi.Msg, error)
func (*ImageEntity) WithAttributes ¶
func (e *ImageEntity) WithAttributes(options ...AttributeOption) *ImageEntity
func (*ImageEntity) WithContentType ¶
func (e *ImageEntity) WithContentType(contentType string) *ImageEntity
WithContentType defines what kind of image format the message body is using. For example, `image/png` or `image/jpeg`. The default is `image/jpeg`.
func (*ImageEntity) WithDetails ¶
func (e *ImageEntity) WithDetails(options ...DetailsOption) *ImageEntity
func (*ImageEntity) WithEncoding ¶
func (e *ImageEntity) WithEncoding(options ...EncodingOption) *ImageEntity
func (*ImageEntity) WithMode ¶
func (e *ImageEntity) WithMode(mode ImageMode) *ImageEntity
WithMode defines how the image entity operates:
For ModeImage, every time a message under the image_topic in the configuration is received, the image displayed in Home Assistant will also be updated. Messages received on image_topic should contain the full contents of an image file, for example, a JPEG image, without any additional encoding or metadata.
For ModeURL, the image topic defines an image URL for a new picture to show. The URL can be extracted from the payload by setting a template with WithURLTemplate.
func (*ImageEntity) WithURLTemplate ¶
func (e *ImageEntity) WithURLTemplate(template string) *ImageEntity
WithURLTemplate defines a template to use to extract the URL to the image from the response received. See https://www.home-assistant.io/docs/configuration/templating/#using-templates-with-the-mqtt-integration for template configuration.
type ImageMode ¶
type ImageMode int
ImageMode reflects how this image entity is handled by Home Assistant.
type NumberEntity ¶
type NumberEntity[T constraints.Ordered] struct { Min T `json:"min,omitempty"` Max T `json:"max,omitempty"` Step T `json:"step,omitempty"` *EntityDetails *EntityState *EntityCommand *EntityAttributes Mode string `json:"mode,omitempty"` ResetPayload string `json:"payload_reset,omitempty"` Optimistic bool `json:"optimistic,omitempty"` }
NumberEntity represents an entity that is a number that has a given range of values and can be set to any value in that range, with a precision by the given step. For more details, see https://www.home-assistant.io/integrations/number.mqtt/
func NewNumberEntity ¶
func NewNumberEntity[T constraints.Ordered]() *NumberEntity[T]
func (*NumberEntity[T]) MarshalConfig ¶
func (e *NumberEntity[T]) MarshalConfig() (*mqttapi.Msg, error)
func (*NumberEntity[T]) OptimisticMode ¶
func (e *NumberEntity[T]) OptimisticMode() *NumberEntity[T]
OptimisticMode ensures the number entity works in optimistic mode.
func (*NumberEntity[T]) WithAttributes ¶
func (e *NumberEntity[T]) WithAttributes(options ...AttributeOption) *NumberEntity[T]
func (*NumberEntity[T]) WithCommand ¶
func (e *NumberEntity[T]) WithCommand(options ...CommandOption) *NumberEntity[T]
func (*NumberEntity[T]) WithDetails ¶
func (e *NumberEntity[T]) WithDetails(options ...DetailsOption) *NumberEntity[T]
func (*NumberEntity[T]) WithMax ¶
func (e *NumberEntity[T]) WithMax(max T) *NumberEntity[T]
WithMax sets the maximum value for the number entity state.
func (*NumberEntity[T]) WithMin ¶
func (e *NumberEntity[T]) WithMin(min T) *NumberEntity[T]
WithMin sets the minimum value for the number entity state.
func (*NumberEntity[T]) WithMode ¶
func (e *NumberEntity[T]) WithMode(mode NumberMode) *NumberEntity[T]
WithMode controls how the number should be displayed in the Home Assistant UI. Can be set to NumberBox or NumberSlide to force a display mode. Default is NumberAuto which will let Home Assistant decide.
func (*NumberEntity[T]) WithResetPayload ¶
func (e *NumberEntity[T]) WithResetPayload(payload string) *NumberEntity[T]
WithResetPayload defines a special payload that resets the state to unknown when received on the state_topic.
func (*NumberEntity[T]) WithState ¶
func (e *NumberEntity[T]) WithState(options ...StateOption) *NumberEntity[T]
func (*NumberEntity[T]) WithStep ¶
func (e *NumberEntity[T]) WithStep(step T) *NumberEntity[T]
WithStep sets the step value. For entities with float value, smallest step accepted by Home Assistant 0.001.
type NumberMode ¶
type NumberMode int
NumberMode reflects how this number entity is displayed in Home Assistant. It can be either automatically chosen or explicitly set to display as a slider or box.
const ( // NumberAuto will tell Home Assistant to automatically select how the number is displayed. NumberAuto NumberMode = 0 // auto // NumberBox will tell Home Assistant to display this number as a box. NumberBox NumberMode = 1 // box // NumberSlider will tell Home Assistant to display this number as a slider. NumberSlider NumberMode = 2 // slider )
func (NumberMode) String ¶
func (i NumberMode) String() string
type Origin ¶
type Origin struct { Name string `json:"name"` Version string `json:"sw_version,omitempty"` URL string `json:"support_url,omitempty"` }
Origin contains information about the app that is responsible for the entity. It is used by Home Assistant for logging and display purposes.
type SensorEntity ¶
type SensorEntity struct { *EntityAttributes *EntityState *EntityDetails LastResetValueTemplate string `json:"last_reset_value_template,omitempty"` StateExpiry int `json:"expire_after,omitempty" validate:"omitempty,gte=0"` ForceUpdate bool `json:"force_update,omitempty"` // contains filtered or unexported fields }
SensorEntity represents an entity which has some kind of value. For more details, see https://www.home-assistant.io/integrations/sensor.mqtt/
func NewBinarySensorEntity ¶
func NewBinarySensorEntity() *SensorEntity
func NewSensorEntity ¶
func NewSensorEntity() *SensorEntity
func (*SensorEntity) ForcedUpdates ¶
func (e *SensorEntity) ForcedUpdates() *SensorEntity
ForcedUpdates sends update events even if the value hasn’t changed. Useful if you want to have meaningful value graphs in history.
func (*SensorEntity) MarshalConfig ¶
func (e *SensorEntity) MarshalConfig() (*mqttapi.Msg, error)
func (*SensorEntity) WithAttributes ¶
func (e *SensorEntity) WithAttributes(options ...AttributeOption) *SensorEntity
func (*SensorEntity) WithDetails ¶
func (e *SensorEntity) WithDetails(options ...DetailsOption) *SensorEntity
func (*SensorEntity) WithLastResetValueTemplate ¶
func (e *SensorEntity) WithLastResetValueTemplate(template string) *SensorEntity
WithLastResetValueTemplate defines a template to extract the last_reset. When last_reset_value_template is set, the state_class option must be total. Available variables: entity_id. The entity_id can be used to reference the entity’s attributes.
func (*SensorEntity) WithState ¶
func (e *SensorEntity) WithState(options ...StateOption) *SensorEntity
func (*SensorEntity) WithStateExpiry ¶
func (e *SensorEntity) WithStateExpiry(expiry time.Duration) *SensorEntity
WithStateExpiry defines the number of seconds after the sensor’s state expires, if it’s not updated. After expiry, the sensor’s state becomes "unavailable".
type StateOption ¶
type StateOption func(*EntityState) *EntityState
StateOption is used to add functionality to the entity state, such as defining the state callback function or setting the state units.
func DeviceClass ¶
func DeviceClass(class string) StateOption
DeviceClass configures the Device Class of the entity. Device classes are specific to the type of entity.
func StateCallback ¶
func StateCallback(callback func(args ...any) (json.RawMessage, error)) StateOption
StateCallback will add the passed in function as the callback action to be run whenever the state of the entity is needed. It might not be useful to use this where you have a single state that represents many entities. In such cases, it would be better to manually send the state in your own code.
func StateClassMeasurement ¶
func StateClassMeasurement() StateOption
StateClassMeasurement configures the State Class for the entity to be "measurement".
func StateClassTotal ¶
func StateClassTotal() StateOption
StateClassTotal configures the State Class for the entity to be "total".
func StateClassTotalIncreasing ¶
func StateClassTotalIncreasing() StateOption
StateClassTotalIncreasing configures the State Class for the entity to be "total_increasing".
func SuggestedPrecision ¶
func SuggestedPrecision(p uint) StateOption
SuggestedPrecision defines the number of decimals which should be used in the sensor’s state after rounding. Only relevant to set for sensors with a numeric state.
func Units ¶
func Units(u string) StateOption
Units adds a unit of measurement to the entity. Only relevant to set for sensors with a numeric state.
func ValueTemplate ¶
func ValueTemplate(t string) StateOption
ValueTemplate configures the passed in string to be the template to be used to extract the value of the entity in Home Assistant.
type SwitchEntity ¶
type SwitchEntity struct { *EntityDetails *EntityCommand *EntityState *EntityAttributes PayloadOn string `json:"payload_on,omitempty"` PayloadOff string `json:"payload_off,omitempty"` StateOn string `json:"state_on,omitempty"` StateOff string `json:"state_off,omitempty"` Optimistic bool `json:"optimistic,omitempty"` }
SwitchEntity represents an entity that can be turned on or off. For more details see https://www.home-assistant.io/integrations/switch.mqtt/
func NewSwitchEntity ¶
func NewSwitchEntity() *SwitchEntity
func (*SwitchEntity) MarshalConfig ¶
func (e *SwitchEntity) MarshalConfig() (*mqttapi.Msg, error)
func (*SwitchEntity) OptimisticMode ¶
func (e *SwitchEntity) OptimisticMode() *SwitchEntity
OptimisticMode ensures the switch works in optimistic mode.
func (*SwitchEntity) WithAttributes ¶
func (e *SwitchEntity) WithAttributes(options ...AttributeOption) *SwitchEntity
func (*SwitchEntity) WithCommand ¶
func (e *SwitchEntity) WithCommand(options ...CommandOption) *SwitchEntity
func (*SwitchEntity) WithDetails ¶
func (e *SwitchEntity) WithDetails(options ...DetailsOption) *SwitchEntity
func (*SwitchEntity) WithOffPayload ¶
func (e *SwitchEntity) WithOffPayload(payload string) *SwitchEntity
WithOffPayload sets the payload that represents off state. If specified, will be used for both comparing to the value in the state_topic (see value_template and state_off for details) and sending as off command to the command_topic. Defaults to OFF.
func (*SwitchEntity) WithOnPayload ¶
func (e *SwitchEntity) WithOnPayload(payload string) *SwitchEntity
WithOnPayload sets the payload that represents on state. If specified, will be used for both comparing to the value in the state_topic (see value_template and state_on for details) and sending as on command to the command_topic. Defaults to ON.
func (*SwitchEntity) WithState ¶
func (e *SwitchEntity) WithState(options ...StateOption) *SwitchEntity
func (*SwitchEntity) WithStateOff ¶
func (e *SwitchEntity) WithStateOff(payload string) *SwitchEntity
WithStateOff sets the payload that represents the off state. Used when value that represents off state in the state_topic is different from value that should be sent to the command_topic to turn the device off.
Default: payload_off if defined, else OFF
func (*SwitchEntity) WithStateOn ¶
func (e *SwitchEntity) WithStateOn(payload string) *SwitchEntity
WithStateOn sets the payload that represents the on state. Used when value that represents on state in the state_topic is different from value that should be sent to the command_topic to turn the device on.
Default: payload_on if defined, else ON
type TextEntity ¶
type TextEntity struct { *EntityDetails *EntityCommand *EntityAttributes *EntityState Mode string `json:"mode,omitempty"` Pattern string `json:"pattern,omitempty"` Min int `json:"min,omitempty" validate:"min=0"` Max int `json:"max,omitempty" validate:"max=255"` }
TextEntity represents an entity that can display a string of text and set the string remotely. For more details see https://www.home-assistant.io/integrations/text.mqtt/
func NewTextEntity ¶
func NewTextEntity() *TextEntity
func (*TextEntity) MarshalConfig ¶
func (e *TextEntity) MarshalConfig() (*mqttapi.Msg, error)
func (*TextEntity) WithAttributes ¶
func (e *TextEntity) WithAttributes(options ...AttributeOption) *TextEntity
func (*TextEntity) WithCommand ¶
func (e *TextEntity) WithCommand(options ...CommandOption) *TextEntity
func (*TextEntity) WithDetails ¶
func (e *TextEntity) WithDetails(options ...DetailsOption) *TextEntity
func (*TextEntity) WithMax ¶
func (e *TextEntity) WithMax(max int) *TextEntity
WithMax will set the maximum size of a text being set or received (maximum is 255).
func (*TextEntity) WithMin ¶
func (e *TextEntity) WithMin(min int) *TextEntity
WithMin will set the minimum size of a text being set or received.
func (*TextEntity) WithMode ¶
func (e *TextEntity) WithMode(mode TextEntityMode) *TextEntity
WithMode sets the mode of the text entity. Must be either PlainText or Password.
func (*TextEntity) WithPattern ¶
func (e *TextEntity) WithPattern(pattern string) *TextEntity
WithPattern sets a valid regular expression the text being set or received must match with.
func (*TextEntity) WithState ¶
func (e *TextEntity) WithState(options ...StateOption) *TextEntity
type TextEntityMode ¶
type TextEntityMode int
const ( PlainText TextEntityMode = iota // text Password // password )
func (TextEntityMode) String ¶
func (i TextEntityMode) String() string