Documentation ¶
Index ¶
- Variables
- func FormatID(s string) string
- func FormatName(s string) string
- func NewEntity(app, name, id string) *entity
- type BinarySensorEntity
- func (e BinarySensorEntity) AsDiagnostic() *entity
- func (e BinarySensorEntity) GetTopics() *Topics
- func (e BinarySensorEntity) MarshalAttributes(args ...any) (*mqttapi.Msg, error)
- func (e BinarySensorEntity) MarshalConfig() (*mqttapi.Msg, error)
- func (e BinarySensorEntity) MarshalState(args ...any) (*mqttapi.Msg, error)
- func (e BinarySensorEntity) MarshalSubscription() (*mqttapi.Subscription, error)
- func (e BinarySensorEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e BinarySensorEntity) WithAttributesTemplate(t string) *entity
- func (e BinarySensorEntity) WithCommandCallback(c func(p *paho.Publish)) *entity
- func (e BinarySensorEntity) WithDefaultOriginInfo() *entity
- func (e BinarySensorEntity) WithDeviceClass(d string) *entity
- func (e BinarySensorEntity) WithDeviceInfo(d *Device) *entity
- func (e BinarySensorEntity) WithIcon(i string) *entity
- func (e BinarySensorEntity) WithNodeID(id string) *entity
- func (e BinarySensorEntity) WithOriginInfo(o *Origin) *entity
- func (e BinarySensorEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e BinarySensorEntity) WithStateClassMeasurement() *entity
- func (e BinarySensorEntity) WithStateClassTotal() *entity
- func (e BinarySensorEntity) WithStateClassTotalIncreasing() *entity
- func (e BinarySensorEntity) WithStateExpiry(i int) *entity
- func (e BinarySensorEntity) WithUnits(u string) *entity
- func (e BinarySensorEntity) WithValueTemplate(t string) *entity
- type ButtonEntity
- func (e ButtonEntity) AsDiagnostic() *entity
- func (e ButtonEntity) GetTopics() *Topics
- func (e ButtonEntity) MarshalAttributes(args ...any) (*mqttapi.Msg, error)
- func (e ButtonEntity) MarshalConfig() (*mqttapi.Msg, error)
- func (e ButtonEntity) MarshalState(args ...any) (*mqttapi.Msg, error)
- func (e ButtonEntity) MarshalSubscription() (*mqttapi.Subscription, error)
- func (e ButtonEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e ButtonEntity) WithAttributesTemplate(t string) *entity
- func (e ButtonEntity) WithCommandCallback(c func(p *paho.Publish)) *entity
- func (e ButtonEntity) WithDefaultOriginInfo() *entity
- func (e ButtonEntity) WithDeviceClass(d string) *entity
- func (e ButtonEntity) WithDeviceInfo(d *Device) *entity
- func (e ButtonEntity) WithIcon(i string) *entity
- func (e ButtonEntity) WithNodeID(id string) *entity
- func (e ButtonEntity) WithOriginInfo(o *Origin) *entity
- func (e ButtonEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e ButtonEntity) WithStateClassMeasurement() *entity
- func (e ButtonEntity) WithStateClassTotal() *entity
- func (e ButtonEntity) WithStateClassTotalIncreasing() *entity
- func (e ButtonEntity) WithStateExpiry(i int) *entity
- func (e ButtonEntity) WithUnits(u string) *entity
- func (e ButtonEntity) WithValueTemplate(t string) *entity
- type CameraEntity
- func (e CameraEntity) AsDiagnostic() *entity
- func (e CameraEntity) GetTopics() *Topics
- func (e CameraEntity) MarshalAttributes(args ...any) (*mqttapi.Msg, error)
- func (entity *CameraEntity) MarshalConfig() (*mqttapi.Msg, error)
- func (e CameraEntity) MarshalState(args ...any) (*mqttapi.Msg, error)
- func (e CameraEntity) MarshalSubscription() (*mqttapi.Subscription, error)
- func (e CameraEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e CameraEntity) WithAttributesTemplate(t string) *entity
- func (e CameraEntity) WithCommandCallback(c func(p *paho.Publish)) *entity
- func (e CameraEntity) WithDefaultOriginInfo() *entity
- func (e CameraEntity) WithDeviceClass(d string) *entity
- func (e CameraEntity) WithDeviceInfo(d *Device) *entity
- func (entity *CameraEntity) WithEncoding(encoding string) *CameraEntity
- func (e CameraEntity) WithIcon(i string) *entity
- func (entity *CameraEntity) WithImageEncoding(encoding string) *CameraEntity
- func (e CameraEntity) WithNodeID(id string) *entity
- func (e CameraEntity) WithOriginInfo(o *Origin) *entity
- func (e CameraEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e CameraEntity) WithStateClassMeasurement() *entity
- func (e CameraEntity) WithStateClassTotal() *entity
- func (e CameraEntity) WithStateClassTotalIncreasing() *entity
- func (e CameraEntity) WithStateExpiry(i int) *entity
- func (e CameraEntity) WithUnits(u string) *entity
- func (e CameraEntity) WithValueTemplate(t string) *entity
- type Device
- type EntityConstraint
- type EntityType
- type ImageEntity
- func (e ImageEntity) AsDiagnostic() *entity
- func (entity *ImageEntity) GetImageTopic() string
- func (e ImageEntity) GetTopics() *Topics
- func (e ImageEntity) MarshalAttributes(args ...any) (*mqttapi.Msg, error)
- func (entity *ImageEntity) MarshalConfig() (*mqttapi.Msg, error)
- func (e ImageEntity) MarshalState(args ...any) (*mqttapi.Msg, error)
- func (e ImageEntity) MarshalSubscription() (*mqttapi.Subscription, error)
- func (e ImageEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e ImageEntity) WithAttributesTemplate(t string) *entity
- func (e ImageEntity) WithCommandCallback(c func(p *paho.Publish)) *entity
- func (entity *ImageEntity) WithContentType(ctype string) *ImageEntity
- func (e ImageEntity) WithDefaultOriginInfo() *entity
- func (e ImageEntity) WithDeviceClass(d string) *entity
- func (e ImageEntity) WithDeviceInfo(d *Device) *entity
- func (entity *ImageEntity) WithEncoding(encoding string) *ImageEntity
- func (e ImageEntity) WithIcon(i string) *entity
- func (entity *ImageEntity) WithImageEncoding(encoding string) *ImageEntity
- func (e ImageEntity) WithNodeID(id string) *entity
- func (e ImageEntity) WithOriginInfo(o *Origin) *entity
- func (e ImageEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e ImageEntity) WithStateClassMeasurement() *entity
- func (e ImageEntity) WithStateClassTotal() *entity
- func (e ImageEntity) WithStateClassTotalIncreasing() *entity
- func (e ImageEntity) WithStateExpiry(i int) *entity
- func (entity *ImageEntity) WithURLTemplate(template string) *ImageEntity
- func (e ImageEntity) WithUnits(u string) *entity
- func (e ImageEntity) WithValueTemplate(t string) *entity
- type ImageMode
- type NumberEntity
- func (e NumberEntity) AsDiagnostic() *entity
- func (e NumberEntity) GetTopics() *Topics
- func (e NumberEntity) MarshalAttributes(args ...any) (*mqttapi.Msg, error)
- func (e *NumberEntity[T]) MarshalConfig() (*mqttapi.Msg, error)
- func (e NumberEntity) MarshalState(args ...any) (*mqttapi.Msg, error)
- func (e NumberEntity) MarshalSubscription() (*mqttapi.Subscription, error)
- func (e NumberEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e NumberEntity) WithAttributesTemplate(t string) *entity
- func (e NumberEntity) WithCommandCallback(c func(p *paho.Publish)) *entity
- func (e NumberEntity) WithDefaultOriginInfo() *entity
- func (e NumberEntity) WithDeviceClass(d string) *entity
- func (e NumberEntity) WithDeviceInfo(d *Device) *entity
- func (e NumberEntity) WithIcon(i string) *entity
- func (e NumberEntity) WithNodeID(id string) *entity
- func (e NumberEntity) WithOriginInfo(o *Origin) *entity
- func (e NumberEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e NumberEntity) WithStateClassMeasurement() *entity
- func (e NumberEntity) WithStateClassTotal() *entity
- func (e NumberEntity) WithStateClassTotalIncreasing() *entity
- func (e NumberEntity) WithStateExpiry(i int) *entity
- func (e NumberEntity) WithUnits(u string) *entity
- func (e NumberEntity) WithValueTemplate(t string) *entity
- type NumberMode
- type Origin
- type SensorEntity
- func (e SensorEntity) AsDiagnostic() *entity
- func (e SensorEntity) GetTopics() *Topics
- func (e SensorEntity) MarshalAttributes(args ...any) (*mqttapi.Msg, error)
- func (e SensorEntity) MarshalConfig() (*mqttapi.Msg, error)
- func (e SensorEntity) MarshalState(args ...any) (*mqttapi.Msg, error)
- func (e SensorEntity) MarshalSubscription() (*mqttapi.Subscription, error)
- func (e SensorEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e SensorEntity) WithAttributesTemplate(t string) *entity
- func (e SensorEntity) WithCommandCallback(c func(p *paho.Publish)) *entity
- func (e SensorEntity) WithDefaultOriginInfo() *entity
- func (e SensorEntity) WithDeviceClass(d string) *entity
- func (e SensorEntity) WithDeviceInfo(d *Device) *entity
- func (e SensorEntity) WithIcon(i string) *entity
- func (e SensorEntity) WithNodeID(id string) *entity
- func (e SensorEntity) WithOriginInfo(o *Origin) *entity
- func (e SensorEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e SensorEntity) WithStateClassMeasurement() *entity
- func (e SensorEntity) WithStateClassTotal() *entity
- func (e SensorEntity) WithStateClassTotalIncreasing() *entity
- func (e SensorEntity) WithStateExpiry(i int) *entity
- func (e SensorEntity) WithUnits(u string) *entity
- func (e SensorEntity) WithValueTemplate(t string) *entity
- type SwitchEntity
- func (e SwitchEntity) AsDiagnostic() *entity
- func (e *SwitchEntity) AsTypeOutlet() *SwitchEntity
- func (e *SwitchEntity) AsTypeSwitch() *SwitchEntity
- func (e SwitchEntity) GetTopics() *Topics
- func (e SwitchEntity) MarshalAttributes(args ...any) (*mqttapi.Msg, error)
- func (e *SwitchEntity) MarshalConfig() (*mqttapi.Msg, error)
- func (e SwitchEntity) MarshalState(args ...any) (*mqttapi.Msg, error)
- func (e SwitchEntity) MarshalSubscription() (*mqttapi.Subscription, error)
- func (e SwitchEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e SwitchEntity) WithAttributesTemplate(t string) *entity
- func (e SwitchEntity) WithCommandCallback(c func(p *paho.Publish)) *entity
- func (e SwitchEntity) WithDefaultOriginInfo() *entity
- func (e SwitchEntity) WithDeviceClass(d string) *entity
- func (e SwitchEntity) WithDeviceInfo(d *Device) *entity
- func (e SwitchEntity) WithIcon(i string) *entity
- func (e SwitchEntity) WithNodeID(id string) *entity
- func (e SwitchEntity) WithOriginInfo(o *Origin) *entity
- func (e SwitchEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e SwitchEntity) WithStateClassMeasurement() *entity
- func (e SwitchEntity) WithStateClassTotal() *entity
- func (e SwitchEntity) WithStateClassTotalIncreasing() *entity
- func (e SwitchEntity) WithStateExpiry(i int) *entity
- func (e SwitchEntity) WithUnits(u string) *entity
- func (e SwitchEntity) WithValueTemplate(t string) *entity
- type TextEntity
- func (e TextEntity) AsDiagnostic() *entity
- func (e *TextEntity) AsPassword() *TextEntity
- func (e *TextEntity) AsPlainText() *TextEntity
- func (e TextEntity) GetTopics() *Topics
- func (e TextEntity) MarshalAttributes(args ...any) (*mqttapi.Msg, error)
- func (e *TextEntity) MarshalConfig() (*mqttapi.Msg, error)
- func (e TextEntity) MarshalState(args ...any) (*mqttapi.Msg, error)
- func (e TextEntity) MarshalSubscription() (*mqttapi.Subscription, error)
- func (e TextEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e TextEntity) WithAttributesTemplate(t string) *entity
- func (e TextEntity) WithCommandCallback(c func(p *paho.Publish)) *entity
- func (e TextEntity) WithDefaultOriginInfo() *entity
- func (e TextEntity) WithDeviceClass(d string) *entity
- func (e TextEntity) WithDeviceInfo(d *Device) *entity
- func (e TextEntity) WithIcon(i string) *entity
- func (e TextEntity) WithNodeID(id string) *entity
- func (e TextEntity) WithOriginInfo(o *Origin) *entity
- func (e TextEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
- func (e TextEntity) WithStateClassMeasurement() *entity
- func (e TextEntity) WithStateClassTotal() *entity
- func (e TextEntity) WithStateClassTotalIncreasing() *entity
- func (e TextEntity) WithStateExpiry(i int) *entity
- func (e TextEntity) WithUnits(u string) *entity
- func (e TextEntity) WithValueTemplate(t string) *entity
- type TextEntityMode
- type Topics
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 ¶
func FormatID ¶
FormatID will take a string s and format it as snake_case. The new string is then an appropriate format to be used as a unique ID in Home Assistant.
func FormatName ¶
FormatName will take a string s and format it with appropriate spacing between words and capitalised the first letter of each word. For example someString becomes Some String. The new string is then an appropriate format to be used as a name in Home Assistant.
Types ¶
type BinarySensorEntity ¶
type BinarySensorEntity struct {
// contains filtered or unexported fields
}
BinarySensorEntity represents an entity which has a boolean state. For more details, see https://www.home-assistant.io/integrations/binary_sensor.mqtt/
func AsBinarySensor ¶
func AsBinarySensor(entity *entity) *BinarySensorEntity
AsBinarySensor converts the given entity into a BinarySensorEntity. Additional builders can potentially be applied to customise it further.
func (BinarySensorEntity) AsDiagnostic ¶
func (e BinarySensorEntity) AsDiagnostic() *entity
AsDiagnostic will mark this entity as a diagnostic entity in Home Assistant.
func (BinarySensorEntity) GetTopics ¶
func (e BinarySensorEntity) GetTopics() *Topics
GetTopics returns a Topic struct containing the topics configured for this entity. If an entity does not have a particular topic (due to not having some functionality), the topic value will be an empty string.
func (BinarySensorEntity) MarshalAttributes ¶
MarshalAttributes will generate an *mqtt.Msg for the attributes of an entity, that can be used for updating the entity's attributes.
func (BinarySensorEntity) MarshalConfig ¶
func (BinarySensorEntity) MarshalState ¶
MarshalState will generate an *mqtt.Msg for a given entity, that can be used to publish the entity's state to the MQTT bus.
func (BinarySensorEntity) MarshalSubscription ¶
func (e BinarySensorEntity) 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.
func (BinarySensorEntity) WithAttributesCallback ¶
func (e BinarySensorEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
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 (BinarySensorEntity) WithAttributesTemplate ¶
func (e BinarySensorEntity) WithAttributesTemplate(t string) *entity
WithAttributesTemplate configures the passed in template to be used to extract the value of the attributes in Home Assistant.
func (BinarySensorEntity) WithCommandCallback ¶
WithCommandCallback will add the passed in function as the callback action to be run when a message is received on the command topic of the entity. It doesn't make sense to add this for entities that don't have a command topic, like regular sensors.
func (BinarySensorEntity) WithDefaultOriginInfo ¶
func (e BinarySensorEntity) WithDefaultOriginInfo() *entity
WithOriginInfo adds a pre-filled origin that references go-hass-agent to the entity config.
func (BinarySensorEntity) WithDeviceClass ¶
func (e BinarySensorEntity) WithDeviceClass(d string) *entity
WithDeviceClass configures the Device Class for the entity.
func (BinarySensorEntity) WithDeviceInfo ¶
func (e BinarySensorEntity) WithDeviceInfo(d *Device) *entity
WithDeviceInfo adds the passed in device info to the entity config.
func (BinarySensorEntity) WithIcon ¶
func (e BinarySensorEntity) WithIcon(i string) *entity
WithIcon adds an icon to the entity.
func (BinarySensorEntity) WithNodeID ¶
func (e BinarySensorEntity) WithNodeID(id string) *entity
WithNodeID adds an additional section to the topics of the entity in MQTT. It can be used to help structure various entities being provided.
func (BinarySensorEntity) WithOriginInfo ¶
func (e BinarySensorEntity) WithOriginInfo(o *Origin) *entity
WithOriginInfo adds the passed in origin info to the entity config.
func (BinarySensorEntity) WithStateCallback ¶
func (e BinarySensorEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
WithStateCallback will add the passed in function as the callback action to be run whenever the state of the entity is needed. It doesn't make sense to add this for entities that don't report a state, like buttons. 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 (BinarySensorEntity) WithStateClassMeasurement ¶
func (e BinarySensorEntity) WithStateClassMeasurement() *entity
WithStateClassMeasurement configures the State Class for the entity to be "measurement".
func (BinarySensorEntity) WithStateClassTotal ¶
func (e BinarySensorEntity) WithStateClassTotal() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total".
func (BinarySensorEntity) WithStateClassTotalIncreasing ¶
func (e BinarySensorEntity) WithStateClassTotalIncreasing() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total_increasing".
func (BinarySensorEntity) WithStateExpiry ¶
func (e BinarySensorEntity) WithStateExpiry(i int) *entity
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".
func (BinarySensorEntity) WithUnits ¶
func (e BinarySensorEntity) WithUnits(u string) *entity
WithUnits adds a unit of measurement to the entity.
func (BinarySensorEntity) WithValueTemplate ¶
func (e BinarySensorEntity) WithValueTemplate(t string) *entity
WithValueTemplate configures the passed in template to be used to extract the value of the entity in Home Assistant.
type ButtonEntity ¶
type ButtonEntity struct {
// contains filtered or unexported fields
}
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 AsButton ¶
func AsButton(entity *entity) *ButtonEntity
AsButton converts the given entity into a ButtonEntity. Additional builders can potentially be applied to customise it further.
func (ButtonEntity) AsDiagnostic ¶
func (e ButtonEntity) AsDiagnostic() *entity
AsDiagnostic will mark this entity as a diagnostic entity in Home Assistant.
func (ButtonEntity) GetTopics ¶
func (e ButtonEntity) GetTopics() *Topics
GetTopics returns a Topic struct containing the topics configured for this entity. If an entity does not have a particular topic (due to not having some functionality), the topic value will be an empty string.
func (ButtonEntity) MarshalAttributes ¶
MarshalAttributes will generate an *mqtt.Msg for the attributes of an entity, that can be used for updating the entity's attributes.
func (ButtonEntity) MarshalConfig ¶
func (ButtonEntity) MarshalState ¶
MarshalState will generate an *mqtt.Msg for a given entity, that can be used to publish the entity's state to the MQTT bus.
func (ButtonEntity) MarshalSubscription ¶
func (e ButtonEntity) 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.
func (ButtonEntity) WithAttributesCallback ¶
func (e ButtonEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
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 (ButtonEntity) WithAttributesTemplate ¶
func (e ButtonEntity) WithAttributesTemplate(t string) *entity
WithAttributesTemplate configures the passed in template to be used to extract the value of the attributes in Home Assistant.
func (ButtonEntity) WithCommandCallback ¶
WithCommandCallback will add the passed in function as the callback action to be run when a message is received on the command topic of the entity. It doesn't make sense to add this for entities that don't have a command topic, like regular sensors.
func (ButtonEntity) WithDefaultOriginInfo ¶
func (e ButtonEntity) WithDefaultOriginInfo() *entity
WithOriginInfo adds a pre-filled origin that references go-hass-agent to the entity config.
func (ButtonEntity) WithDeviceClass ¶
func (e ButtonEntity) WithDeviceClass(d string) *entity
WithDeviceClass configures the Device Class for the entity.
func (ButtonEntity) WithDeviceInfo ¶
func (e ButtonEntity) WithDeviceInfo(d *Device) *entity
WithDeviceInfo adds the passed in device info to the entity config.
func (ButtonEntity) WithIcon ¶
func (e ButtonEntity) WithIcon(i string) *entity
WithIcon adds an icon to the entity.
func (ButtonEntity) WithNodeID ¶
func (e ButtonEntity) WithNodeID(id string) *entity
WithNodeID adds an additional section to the topics of the entity in MQTT. It can be used to help structure various entities being provided.
func (ButtonEntity) WithOriginInfo ¶
func (e ButtonEntity) WithOriginInfo(o *Origin) *entity
WithOriginInfo adds the passed in origin info to the entity config.
func (ButtonEntity) WithStateCallback ¶
func (e ButtonEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
WithStateCallback will add the passed in function as the callback action to be run whenever the state of the entity is needed. It doesn't make sense to add this for entities that don't report a state, like buttons. 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 (ButtonEntity) WithStateClassMeasurement ¶
func (e ButtonEntity) WithStateClassMeasurement() *entity
WithStateClassMeasurement configures the State Class for the entity to be "measurement".
func (ButtonEntity) WithStateClassTotal ¶
func (e ButtonEntity) WithStateClassTotal() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total".
func (ButtonEntity) WithStateClassTotalIncreasing ¶
func (e ButtonEntity) WithStateClassTotalIncreasing() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total_increasing".
func (ButtonEntity) WithStateExpiry ¶
func (e ButtonEntity) WithStateExpiry(i int) *entity
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".
func (ButtonEntity) WithUnits ¶
func (e ButtonEntity) WithUnits(u string) *entity
WithUnits adds a unit of measurement to the entity.
func (ButtonEntity) WithValueTemplate ¶
func (e ButtonEntity) WithValueTemplate(t string) *entity
WithValueTemplate configures the passed in template to be used to extract the value of the entity in Home Assistant.
type CameraEntity ¶ added in v11.1.0
type CameraEntity struct { Encoding string `json:"encoding,omitempty"` ImageEncoding string `json:"image_encoding,omitempty"` Topic string `json:"topic"` // contains filtered or unexported fields }
CameraEntity represents an entity which sends image files through MQTT. For more details, see https://www.home-assistant.io/integrations/camera.mqtt/
func AsCamera ¶ added in v11.1.0
func AsCamera(entity *entity) *CameraEntity
AsCamera converts the given entity into a CameraEntity. The min, max parameters do not need to be specified (default min: 0, default max: 255).
func (CameraEntity) AsDiagnostic ¶ added in v11.1.0
func (e CameraEntity) AsDiagnostic() *entity
AsDiagnostic will mark this entity as a diagnostic entity in Home Assistant.
func (CameraEntity) GetTopics ¶ added in v11.1.0
func (e CameraEntity) GetTopics() *Topics
GetTopics returns a Topic struct containing the topics configured for this entity. If an entity does not have a particular topic (due to not having some functionality), the topic value will be an empty string.
func (CameraEntity) MarshalAttributes ¶ added in v11.1.0
MarshalAttributes will generate an *mqtt.Msg for the attributes of an entity, that can be used for updating the entity's attributes.
func (*CameraEntity) MarshalConfig ¶ added in v11.1.0
func (entity *CameraEntity) MarshalConfig() (*mqttapi.Msg, error)
func (CameraEntity) MarshalState ¶ added in v11.1.0
MarshalState will generate an *mqtt.Msg for a given entity, that can be used to publish the entity's state to the MQTT bus.
func (CameraEntity) MarshalSubscription ¶ added in v11.1.0
func (e CameraEntity) 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.
func (CameraEntity) WithAttributesCallback ¶ added in v11.1.0
func (e CameraEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
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 (CameraEntity) WithAttributesTemplate ¶ added in v11.1.0
func (e CameraEntity) WithAttributesTemplate(t string) *entity
WithAttributesTemplate configures the passed in template to be used to extract the value of the attributes in Home Assistant.
func (CameraEntity) WithCommandCallback ¶ added in v11.1.0
WithCommandCallback will add the passed in function as the callback action to be run when a message is received on the command topic of the entity. It doesn't make sense to add this for entities that don't have a command topic, like regular sensors.
func (CameraEntity) WithDefaultOriginInfo ¶ added in v11.1.0
func (e CameraEntity) WithDefaultOriginInfo() *entity
WithOriginInfo adds a pre-filled origin that references go-hass-agent to the entity config.
func (CameraEntity) WithDeviceClass ¶ added in v11.1.0
func (e CameraEntity) WithDeviceClass(d string) *entity
WithDeviceClass configures the Device Class for the entity.
func (CameraEntity) WithDeviceInfo ¶ added in v11.1.0
func (e CameraEntity) WithDeviceInfo(d *Device) *entity
WithDeviceInfo adds the passed in device info to the entity config.
func (*CameraEntity) WithEncoding ¶ added in v11.1.0
func (entity *CameraEntity) WithEncoding(encoding string) *CameraEntity
WithEncoding sets the encoding of the payloads. By default, a CameraEntity publishes raw binary data on the topic.
func (CameraEntity) WithIcon ¶ added in v11.1.0
func (e CameraEntity) WithIcon(i string) *entity
WithIcon adds an icon to the entity.
func (*CameraEntity) WithImageEncoding ¶ added in v11.1.0
func (entity *CameraEntity) WithImageEncoding(encoding string) *CameraEntity
WithImageEncoding sets the image encoding of the payloads. By default, a CameraEntity publishes images as raw binary data on the topic. Setting a special value of "b64" is used by Home Assistant to represent base64 encoding of images.
func (CameraEntity) WithNodeID ¶ added in v11.1.0
func (e CameraEntity) WithNodeID(id string) *entity
WithNodeID adds an additional section to the topics of the entity in MQTT. It can be used to help structure various entities being provided.
func (CameraEntity) WithOriginInfo ¶ added in v11.1.0
func (e CameraEntity) WithOriginInfo(o *Origin) *entity
WithOriginInfo adds the passed in origin info to the entity config.
func (CameraEntity) WithStateCallback ¶ added in v11.1.0
func (e CameraEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
WithStateCallback will add the passed in function as the callback action to be run whenever the state of the entity is needed. It doesn't make sense to add this for entities that don't report a state, like buttons. 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 (CameraEntity) WithStateClassMeasurement ¶ added in v11.1.0
func (e CameraEntity) WithStateClassMeasurement() *entity
WithStateClassMeasurement configures the State Class for the entity to be "measurement".
func (CameraEntity) WithStateClassTotal ¶ added in v11.1.0
func (e CameraEntity) WithStateClassTotal() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total".
func (CameraEntity) WithStateClassTotalIncreasing ¶ added in v11.1.0
func (e CameraEntity) WithStateClassTotalIncreasing() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total_increasing".
func (CameraEntity) WithStateExpiry ¶ added in v11.1.0
func (e CameraEntity) WithStateExpiry(i int) *entity
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".
func (CameraEntity) WithUnits ¶ added in v11.1.0
func (e CameraEntity) WithUnits(u string) *entity
WithUnits adds a unit of measurement to the entity.
func (CameraEntity) WithValueTemplate ¶ added in v11.1.0
func (e CameraEntity) WithValueTemplate(t string) *entity
WithValueTemplate configures the passed in template to be used to extract the value of the entity in Home Assistant.
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 EntityConstraint ¶
type EntityConstraint[T constraints.Ordered] interface { ~*SensorEntity | ~*BinarySensorEntity | ~*ButtonEntity | ~*NumberEntity[T] | ~*SwitchEntity }
type EntityType ¶
type EntityType int
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 ¶ added in v11.1.0
type ImageEntity struct { Encoding string `json:"encoding,omitempty"` ImageEncoding string `json:"image_encoding,omitempty"` ImageTopic string `json:"image_topic,omitempty"` ContentType string `json:"content_type,omitempty"` URLTopic string `json:"url_topic,omitempty"` 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 AsImage ¶ added in v11.1.0
func AsImage(entity *entity, mode ImageMode) *ImageEntity
AsImage converts the given entity into a ImageEntity. A mode can be specified that controls how the entity will be handled by Home Assistant. Mode "Image" expects an image file as the contents of the entity's state topic. Mode "URL" expects a URL. The default value of mode is "Image".
func (ImageEntity) AsDiagnostic ¶ added in v11.1.0
func (e ImageEntity) AsDiagnostic() *entity
AsDiagnostic will mark this entity as a diagnostic entity in Home Assistant.
func (*ImageEntity) GetImageTopic ¶ added in v11.1.0
func (entity *ImageEntity) GetImageTopic() string
GetImageTopic returns the topic on which images will appear on MQTT.
func (ImageEntity) GetTopics ¶ added in v11.1.0
func (e ImageEntity) GetTopics() *Topics
GetTopics returns a Topic struct containing the topics configured for this entity. If an entity does not have a particular topic (due to not having some functionality), the topic value will be an empty string.
func (ImageEntity) MarshalAttributes ¶ added in v11.1.0
MarshalAttributes will generate an *mqtt.Msg for the attributes of an entity, that can be used for updating the entity's attributes.
func (*ImageEntity) MarshalConfig ¶ added in v11.1.0
func (entity *ImageEntity) MarshalConfig() (*mqttapi.Msg, error)
func (ImageEntity) MarshalState ¶ added in v11.1.0
MarshalState will generate an *mqtt.Msg for a given entity, that can be used to publish the entity's state to the MQTT bus.
func (ImageEntity) MarshalSubscription ¶ added in v11.1.0
func (e ImageEntity) 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.
func (ImageEntity) WithAttributesCallback ¶ added in v11.1.0
func (e ImageEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
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 (ImageEntity) WithAttributesTemplate ¶ added in v11.1.0
func (e ImageEntity) WithAttributesTemplate(t string) *entity
WithAttributesTemplate configures the passed in template to be used to extract the value of the attributes in Home Assistant.
func (ImageEntity) WithCommandCallback ¶ added in v11.1.0
WithCommandCallback will add the passed in function as the callback action to be run when a message is received on the command topic of the entity. It doesn't make sense to add this for entities that don't have a command topic, like regular sensors.
func (*ImageEntity) WithContentType ¶ added in v11.1.0
func (entity *ImageEntity) WithContentType(ctype string) *ImageEntity
WithContentType defines what kind of image format the message body is using. For example, "image/png" or "image/jpeg".
func (ImageEntity) WithDefaultOriginInfo ¶ added in v11.1.0
func (e ImageEntity) WithDefaultOriginInfo() *entity
WithOriginInfo adds a pre-filled origin that references go-hass-agent to the entity config.
func (ImageEntity) WithDeviceClass ¶ added in v11.1.0
func (e ImageEntity) WithDeviceClass(d string) *entity
WithDeviceClass configures the Device Class for the entity.
func (ImageEntity) WithDeviceInfo ¶ added in v11.1.0
func (e ImageEntity) WithDeviceInfo(d *Device) *entity
WithDeviceInfo adds the passed in device info to the entity config.
func (*ImageEntity) WithEncoding ¶ added in v11.1.0
func (entity *ImageEntity) WithEncoding(encoding string) *ImageEntity
WithEncoding sets the encoding of the payloads. By default, a ImageEntity publishes raw binary data on the topic.
func (ImageEntity) WithIcon ¶ added in v11.1.0
func (e ImageEntity) WithIcon(i string) *entity
WithIcon adds an icon to the entity.
func (*ImageEntity) WithImageEncoding ¶ added in v11.1.0
func (entity *ImageEntity) WithImageEncoding(encoding string) *ImageEntity
WithImageEncoding sets the image encoding of the payloads. By default, a ImageEntity publishes images as raw binary data on the topic. Setting a special value of "b64" is used by Home Assistant to represent base64 encoding of images.
func (ImageEntity) WithNodeID ¶ added in v11.1.0
func (e ImageEntity) WithNodeID(id string) *entity
WithNodeID adds an additional section to the topics of the entity in MQTT. It can be used to help structure various entities being provided.
func (ImageEntity) WithOriginInfo ¶ added in v11.1.0
func (e ImageEntity) WithOriginInfo(o *Origin) *entity
WithOriginInfo adds the passed in origin info to the entity config.
func (ImageEntity) WithStateCallback ¶ added in v11.1.0
func (e ImageEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
WithStateCallback will add the passed in function as the callback action to be run whenever the state of the entity is needed. It doesn't make sense to add this for entities that don't report a state, like buttons. 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 (ImageEntity) WithStateClassMeasurement ¶ added in v11.1.0
func (e ImageEntity) WithStateClassMeasurement() *entity
WithStateClassMeasurement configures the State Class for the entity to be "measurement".
func (ImageEntity) WithStateClassTotal ¶ added in v11.1.0
func (e ImageEntity) WithStateClassTotal() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total".
func (ImageEntity) WithStateClassTotalIncreasing ¶ added in v11.1.0
func (e ImageEntity) WithStateClassTotalIncreasing() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total_increasing".
func (ImageEntity) WithStateExpiry ¶ added in v11.1.0
func (e ImageEntity) WithStateExpiry(i int) *entity
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".
func (*ImageEntity) WithURLTemplate ¶ added in v11.1.0
func (entity *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.
func (ImageEntity) WithUnits ¶ added in v11.1.0
func (e ImageEntity) WithUnits(u string) *entity
WithUnits adds a unit of measurement to the entity.
func (ImageEntity) WithValueTemplate ¶ added in v11.1.0
func (e ImageEntity) WithValueTemplate(t string) *entity
WithValueTemplate configures the passed in template to be used to extract the value of the entity in Home Assistant.
type ImageMode ¶ added in v11.1.0
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"` Mode string `json:"mode,omitempty"` // contains filtered or unexported fields }
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 AsNumber ¶
func AsNumber[T constraints.Ordered](entity *entity, step, min, max T, mode NumberMode) *NumberEntity[T]
AsNumber converts the given entity into a NumberEntity. Additional builders can potentially be applied to customise it further.
func (NumberEntity) AsDiagnostic ¶
func (e NumberEntity) AsDiagnostic() *entity
AsDiagnostic will mark this entity as a diagnostic entity in Home Assistant.
func (NumberEntity) GetTopics ¶
func (e NumberEntity) GetTopics() *Topics
GetTopics returns a Topic struct containing the topics configured for this entity. If an entity does not have a particular topic (due to not having some functionality), the topic value will be an empty string.
func (NumberEntity) MarshalAttributes ¶
MarshalAttributes will generate an *mqtt.Msg for the attributes of an entity, that can be used for updating the entity's attributes.
func (*NumberEntity[T]) MarshalConfig ¶
func (e *NumberEntity[T]) MarshalConfig() (*mqttapi.Msg, error)
func (NumberEntity) MarshalState ¶
MarshalState will generate an *mqtt.Msg for a given entity, that can be used to publish the entity's state to the MQTT bus.
func (NumberEntity) MarshalSubscription ¶
func (e NumberEntity) 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.
func (NumberEntity) WithAttributesCallback ¶
func (e NumberEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
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 (NumberEntity) WithAttributesTemplate ¶
func (e NumberEntity) WithAttributesTemplate(t string) *entity
WithAttributesTemplate configures the passed in template to be used to extract the value of the attributes in Home Assistant.
func (NumberEntity) WithCommandCallback ¶
WithCommandCallback will add the passed in function as the callback action to be run when a message is received on the command topic of the entity. It doesn't make sense to add this for entities that don't have a command topic, like regular sensors.
func (NumberEntity) WithDefaultOriginInfo ¶
func (e NumberEntity) WithDefaultOriginInfo() *entity
WithOriginInfo adds a pre-filled origin that references go-hass-agent to the entity config.
func (NumberEntity) WithDeviceClass ¶
func (e NumberEntity) WithDeviceClass(d string) *entity
WithDeviceClass configures the Device Class for the entity.
func (NumberEntity) WithDeviceInfo ¶
func (e NumberEntity) WithDeviceInfo(d *Device) *entity
WithDeviceInfo adds the passed in device info to the entity config.
func (NumberEntity) WithIcon ¶
func (e NumberEntity) WithIcon(i string) *entity
WithIcon adds an icon to the entity.
func (NumberEntity) WithNodeID ¶
func (e NumberEntity) WithNodeID(id string) *entity
WithNodeID adds an additional section to the topics of the entity in MQTT. It can be used to help structure various entities being provided.
func (NumberEntity) WithOriginInfo ¶
func (e NumberEntity) WithOriginInfo(o *Origin) *entity
WithOriginInfo adds the passed in origin info to the entity config.
func (NumberEntity) WithStateCallback ¶
func (e NumberEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
WithStateCallback will add the passed in function as the callback action to be run whenever the state of the entity is needed. It doesn't make sense to add this for entities that don't report a state, like buttons. 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 (NumberEntity) WithStateClassMeasurement ¶
func (e NumberEntity) WithStateClassMeasurement() *entity
WithStateClassMeasurement configures the State Class for the entity to be "measurement".
func (NumberEntity) WithStateClassTotal ¶
func (e NumberEntity) WithStateClassTotal() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total".
func (NumberEntity) WithStateClassTotalIncreasing ¶
func (e NumberEntity) WithStateClassTotalIncreasing() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total_increasing".
func (NumberEntity) WithStateExpiry ¶
func (e NumberEntity) WithStateExpiry(i int) *entity
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".
func (NumberEntity) WithUnits ¶
func (e NumberEntity) WithUnits(u string) *entity
WithUnits adds a unit of measurement to the entity.
func (NumberEntity) WithValueTemplate ¶
func (e NumberEntity) WithValueTemplate(t string) *entity
WithValueTemplate configures the passed in template to be used to extract the value of the entity in Home Assistant.
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 {
// 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 AsSensor ¶
func AsSensor(entity *entity) *SensorEntity
AsSensor converts the given entity into a SensorEntity. Additional builders can potentially be applied to customise it further.
func (SensorEntity) AsDiagnostic ¶
func (e SensorEntity) AsDiagnostic() *entity
AsDiagnostic will mark this entity as a diagnostic entity in Home Assistant.
func (SensorEntity) GetTopics ¶
func (e SensorEntity) GetTopics() *Topics
GetTopics returns a Topic struct containing the topics configured for this entity. If an entity does not have a particular topic (due to not having some functionality), the topic value will be an empty string.
func (SensorEntity) MarshalAttributes ¶
MarshalAttributes will generate an *mqtt.Msg for the attributes of an entity, that can be used for updating the entity's attributes.
func (SensorEntity) MarshalConfig ¶
func (SensorEntity) MarshalState ¶
MarshalState will generate an *mqtt.Msg for a given entity, that can be used to publish the entity's state to the MQTT bus.
func (SensorEntity) MarshalSubscription ¶
func (e SensorEntity) 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.
func (SensorEntity) WithAttributesCallback ¶
func (e SensorEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
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 (SensorEntity) WithAttributesTemplate ¶
func (e SensorEntity) WithAttributesTemplate(t string) *entity
WithAttributesTemplate configures the passed in template to be used to extract the value of the attributes in Home Assistant.
func (SensorEntity) WithCommandCallback ¶
WithCommandCallback will add the passed in function as the callback action to be run when a message is received on the command topic of the entity. It doesn't make sense to add this for entities that don't have a command topic, like regular sensors.
func (SensorEntity) WithDefaultOriginInfo ¶
func (e SensorEntity) WithDefaultOriginInfo() *entity
WithOriginInfo adds a pre-filled origin that references go-hass-agent to the entity config.
func (SensorEntity) WithDeviceClass ¶
func (e SensorEntity) WithDeviceClass(d string) *entity
WithDeviceClass configures the Device Class for the entity.
func (SensorEntity) WithDeviceInfo ¶
func (e SensorEntity) WithDeviceInfo(d *Device) *entity
WithDeviceInfo adds the passed in device info to the entity config.
func (SensorEntity) WithIcon ¶
func (e SensorEntity) WithIcon(i string) *entity
WithIcon adds an icon to the entity.
func (SensorEntity) WithNodeID ¶
func (e SensorEntity) WithNodeID(id string) *entity
WithNodeID adds an additional section to the topics of the entity in MQTT. It can be used to help structure various entities being provided.
func (SensorEntity) WithOriginInfo ¶
func (e SensorEntity) WithOriginInfo(o *Origin) *entity
WithOriginInfo adds the passed in origin info to the entity config.
func (SensorEntity) WithStateCallback ¶
func (e SensorEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
WithStateCallback will add the passed in function as the callback action to be run whenever the state of the entity is needed. It doesn't make sense to add this for entities that don't report a state, like buttons. 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 (SensorEntity) WithStateClassMeasurement ¶
func (e SensorEntity) WithStateClassMeasurement() *entity
WithStateClassMeasurement configures the State Class for the entity to be "measurement".
func (SensorEntity) WithStateClassTotal ¶
func (e SensorEntity) WithStateClassTotal() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total".
func (SensorEntity) WithStateClassTotalIncreasing ¶
func (e SensorEntity) WithStateClassTotalIncreasing() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total_increasing".
func (SensorEntity) WithStateExpiry ¶
func (e SensorEntity) WithStateExpiry(i int) *entity
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".
func (SensorEntity) WithUnits ¶
func (e SensorEntity) WithUnits(u string) *entity
WithUnits adds a unit of measurement to the entity.
func (SensorEntity) WithValueTemplate ¶
func (e SensorEntity) WithValueTemplate(t string) *entity
WithValueTemplate configures the passed in template to be used to extract the value of the entity in Home Assistant.
type SwitchEntity ¶
type SwitchEntity struct { Optimistic bool `json:"optimistic,omitempty"` // contains filtered or unexported fields }
SwitchEntity represents an entity that can be turned on or off. For more details see https://www.home-assistant.io/integrations/switch.mqtt/
func AsSwitch ¶
func AsSwitch(entity *entity, optimistic bool) *SwitchEntity
AsSwitch converts the given entity into a SwitchEntity. Additional builders can potentially be applied to customise it further.
func (SwitchEntity) AsDiagnostic ¶
func (e SwitchEntity) AsDiagnostic() *entity
AsDiagnostic will mark this entity as a diagnostic entity in Home Assistant.
func (*SwitchEntity) AsTypeOutlet ¶
func (e *SwitchEntity) AsTypeOutlet() *SwitchEntity
AsTypeSwitch sets the SwitchEntity device class as an "outlet". This primarily affects how it will be displayed in Home Assistant.
func (*SwitchEntity) AsTypeSwitch ¶
func (e *SwitchEntity) AsTypeSwitch() *SwitchEntity
AsTypeSwitch sets the SwitchEntity device class as a "switch". This primarily affects how it will be displayed in Home Assistant.
func (SwitchEntity) GetTopics ¶
func (e SwitchEntity) GetTopics() *Topics
GetTopics returns a Topic struct containing the topics configured for this entity. If an entity does not have a particular topic (due to not having some functionality), the topic value will be an empty string.
func (SwitchEntity) MarshalAttributes ¶
MarshalAttributes will generate an *mqtt.Msg for the attributes of an entity, that can be used for updating the entity's attributes.
func (*SwitchEntity) MarshalConfig ¶
func (e *SwitchEntity) MarshalConfig() (*mqttapi.Msg, error)
func (SwitchEntity) MarshalState ¶
MarshalState will generate an *mqtt.Msg for a given entity, that can be used to publish the entity's state to the MQTT bus.
func (SwitchEntity) MarshalSubscription ¶
func (e SwitchEntity) 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.
func (SwitchEntity) WithAttributesCallback ¶
func (e SwitchEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
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 (SwitchEntity) WithAttributesTemplate ¶
func (e SwitchEntity) WithAttributesTemplate(t string) *entity
WithAttributesTemplate configures the passed in template to be used to extract the value of the attributes in Home Assistant.
func (SwitchEntity) WithCommandCallback ¶
WithCommandCallback will add the passed in function as the callback action to be run when a message is received on the command topic of the entity. It doesn't make sense to add this for entities that don't have a command topic, like regular sensors.
func (SwitchEntity) WithDefaultOriginInfo ¶
func (e SwitchEntity) WithDefaultOriginInfo() *entity
WithOriginInfo adds a pre-filled origin that references go-hass-agent to the entity config.
func (SwitchEntity) WithDeviceClass ¶
func (e SwitchEntity) WithDeviceClass(d string) *entity
WithDeviceClass configures the Device Class for the entity.
func (SwitchEntity) WithDeviceInfo ¶
func (e SwitchEntity) WithDeviceInfo(d *Device) *entity
WithDeviceInfo adds the passed in device info to the entity config.
func (SwitchEntity) WithIcon ¶
func (e SwitchEntity) WithIcon(i string) *entity
WithIcon adds an icon to the entity.
func (SwitchEntity) WithNodeID ¶
func (e SwitchEntity) WithNodeID(id string) *entity
WithNodeID adds an additional section to the topics of the entity in MQTT. It can be used to help structure various entities being provided.
func (SwitchEntity) WithOriginInfo ¶
func (e SwitchEntity) WithOriginInfo(o *Origin) *entity
WithOriginInfo adds the passed in origin info to the entity config.
func (SwitchEntity) WithStateCallback ¶
func (e SwitchEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
WithStateCallback will add the passed in function as the callback action to be run whenever the state of the entity is needed. It doesn't make sense to add this for entities that don't report a state, like buttons. 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 (SwitchEntity) WithStateClassMeasurement ¶
func (e SwitchEntity) WithStateClassMeasurement() *entity
WithStateClassMeasurement configures the State Class for the entity to be "measurement".
func (SwitchEntity) WithStateClassTotal ¶
func (e SwitchEntity) WithStateClassTotal() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total".
func (SwitchEntity) WithStateClassTotalIncreasing ¶
func (e SwitchEntity) WithStateClassTotalIncreasing() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total_increasing".
func (SwitchEntity) WithStateExpiry ¶
func (e SwitchEntity) WithStateExpiry(i int) *entity
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".
func (SwitchEntity) WithUnits ¶
func (e SwitchEntity) WithUnits(u string) *entity
WithUnits adds a unit of measurement to the entity.
func (SwitchEntity) WithValueTemplate ¶
func (e SwitchEntity) WithValueTemplate(t string) *entity
WithValueTemplate configures the passed in template to be used to extract the value of the entity in Home Assistant.
type TextEntity ¶
type TextEntity struct { Mode string `json:"mode,omitempty"` Min int `json:"min,omitempty"` Max int `json:"max,omitempty"` // contains filtered or unexported fields }
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 AsText ¶
func AsText(entity *entity, min, max int) *TextEntity
AsText converts the given entity into a TextEntity. The min, max parameters do not need to be specified (default min: 0, default max: 255).
func (TextEntity) AsDiagnostic ¶
func (e TextEntity) AsDiagnostic() *entity
AsDiagnostic will mark this entity as a diagnostic entity in Home Assistant.
func (*TextEntity) AsPassword ¶
func (e *TextEntity) AsPassword() *TextEntity
AsPassword sets the mode for this text entity to a password.
func (*TextEntity) AsPlainText ¶
func (e *TextEntity) AsPlainText() *TextEntity
AsPlainText sets the mode for this text entity to (the default) plain text.
func (TextEntity) GetTopics ¶
func (e TextEntity) GetTopics() *Topics
GetTopics returns a Topic struct containing the topics configured for this entity. If an entity does not have a particular topic (due to not having some functionality), the topic value will be an empty string.
func (TextEntity) MarshalAttributes ¶
MarshalAttributes will generate an *mqtt.Msg for the attributes of an entity, that can be used for updating the entity's attributes.
func (*TextEntity) MarshalConfig ¶
func (e *TextEntity) MarshalConfig() (*mqttapi.Msg, error)
func (TextEntity) MarshalState ¶
MarshalState will generate an *mqtt.Msg for a given entity, that can be used to publish the entity's state to the MQTT bus.
func (TextEntity) MarshalSubscription ¶
func (e TextEntity) 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.
func (TextEntity) WithAttributesCallback ¶
func (e TextEntity) WithAttributesCallback(c func(args ...any) (json.RawMessage, error)) *entity
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 (TextEntity) WithAttributesTemplate ¶
func (e TextEntity) WithAttributesTemplate(t string) *entity
WithAttributesTemplate configures the passed in template to be used to extract the value of the attributes in Home Assistant.
func (TextEntity) WithCommandCallback ¶
WithCommandCallback will add the passed in function as the callback action to be run when a message is received on the command topic of the entity. It doesn't make sense to add this for entities that don't have a command topic, like regular sensors.
func (TextEntity) WithDefaultOriginInfo ¶
func (e TextEntity) WithDefaultOriginInfo() *entity
WithOriginInfo adds a pre-filled origin that references go-hass-agent to the entity config.
func (TextEntity) WithDeviceClass ¶
func (e TextEntity) WithDeviceClass(d string) *entity
WithDeviceClass configures the Device Class for the entity.
func (TextEntity) WithDeviceInfo ¶
func (e TextEntity) WithDeviceInfo(d *Device) *entity
WithDeviceInfo adds the passed in device info to the entity config.
func (TextEntity) WithIcon ¶
func (e TextEntity) WithIcon(i string) *entity
WithIcon adds an icon to the entity.
func (TextEntity) WithNodeID ¶
func (e TextEntity) WithNodeID(id string) *entity
WithNodeID adds an additional section to the topics of the entity in MQTT. It can be used to help structure various entities being provided.
func (TextEntity) WithOriginInfo ¶
func (e TextEntity) WithOriginInfo(o *Origin) *entity
WithOriginInfo adds the passed in origin info to the entity config.
func (TextEntity) WithStateCallback ¶
func (e TextEntity) WithStateCallback(c func(args ...any) (json.RawMessage, error)) *entity
WithStateCallback will add the passed in function as the callback action to be run whenever the state of the entity is needed. It doesn't make sense to add this for entities that don't report a state, like buttons. 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 (TextEntity) WithStateClassMeasurement ¶
func (e TextEntity) WithStateClassMeasurement() *entity
WithStateClassMeasurement configures the State Class for the entity to be "measurement".
func (TextEntity) WithStateClassTotal ¶
func (e TextEntity) WithStateClassTotal() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total".
func (TextEntity) WithStateClassTotalIncreasing ¶
func (e TextEntity) WithStateClassTotalIncreasing() *entity
WithStateClassMeasurement configures the State Class for the entity to be "total_increasing".
func (TextEntity) WithStateExpiry ¶
func (e TextEntity) WithStateExpiry(i int) *entity
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".
func (TextEntity) WithUnits ¶
func (e TextEntity) WithUnits(u string) *entity
WithUnits adds a unit of measurement to the entity.
func (TextEntity) WithValueTemplate ¶
func (e TextEntity) WithValueTemplate(t string) *entity
WithValueTemplate configures the passed in template to be used to extract the value of the entity in Home Assistant.
type TextEntityMode ¶
type TextEntityMode int
const ( PlainText TextEntityMode = iota // text Password // password )
func (TextEntityMode) String ¶
func (i TextEntityMode) String() string