hass

package
v9.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func FormatID(s string) string

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

func FormatName(s string) string

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.

func NewEntity

func NewEntity(app, name, id string) *entity

NewEntity creates a minimal entity based on the given name and id and associates it with the given app. Additional builder functions should be chained to fill out functionality that the entity will provide.

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(e *entity) *BinarySensorEntity

AsBinarySensor converts the given entity into a BinarySensorEntity. Additional builders can potentially be applied to customise it further.

func (BinarySensorEntity) AsDiagnostic added in v9.2.0

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

func (e BinarySensorEntity) 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.

func (*BinarySensorEntity) MarshalConfig

func (e *BinarySensorEntity) MarshalConfig() (*mqttapi.Msg, error)

func (BinarySensorEntity) MarshalState

func (e BinarySensorEntity) 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.

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

func (e BinarySensorEntity) WithCommandCallback(c func(p *paho.Publish)) *entity

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(e *entity) *ButtonEntity

AsButton converts the given entity into a ButtonEntity. Additional builders can potentially be applied to customise it further.

func (ButtonEntity) AsDiagnostic added in v9.2.0

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

func (e ButtonEntity) 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.

func (*ButtonEntity) MarshalConfig

func (e *ButtonEntity) MarshalConfig() (*mqttapi.Msg, error)

func (ButtonEntity) MarshalState

func (e ButtonEntity) 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.

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

func (e ButtonEntity) WithCommandCallback(c func(p *paho.Publish)) *entity

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 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
)

func (EntityType) String

func (i EntityType) String() string

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](e *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 added in v9.2.0

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

func (e NumberEntity) 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.

func (*NumberEntity[T]) MarshalConfig

func (e *NumberEntity[T]) MarshalConfig() (*mqttapi.Msg, error)

func (NumberEntity) MarshalState

func (e NumberEntity) 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.

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

func (e NumberEntity) WithCommandCallback(c func(p *paho.Publish)) *entity

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(e *entity) *SensorEntity

AsSensor converts the given entity into a SensorEntity. Additional builders can potentially be applied to customise it further.

func (SensorEntity) AsDiagnostic added in v9.2.0

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

func (e SensorEntity) 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.

func (*SensorEntity) MarshalConfig

func (e *SensorEntity) MarshalConfig() (*mqttapi.Msg, error)

func (SensorEntity) MarshalState

func (e SensorEntity) 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.

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

func (e SensorEntity) WithCommandCallback(c func(p *paho.Publish)) *entity

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(e *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 added in v9.2.0

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

func (e SwitchEntity) 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.

func (*SwitchEntity) MarshalConfig

func (e *SwitchEntity) MarshalConfig() (*mqttapi.Msg, error)

func (SwitchEntity) MarshalState

func (e SwitchEntity) 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.

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

func (e SwitchEntity) WithCommandCallback(c func(p *paho.Publish)) *entity

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 Topics

type Topics struct {
	Config     string
	Command    string
	State      string
	Attributes string
}

Topics contains the names of important topics on the MQTT bus related to the entity. Apps can store these topics for later retrieval and usage (for example, to update state topics or listen to command topics).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL