Documentation ¶
Index ¶
- func FormatID(s string) string
- func FormatName(s string) string
- func MarshalConfig(e *EntityConfig) (*mqtt.Msg, error)
- func MarshalState(e *EntityConfig) (*mqtt.Msg, error)
- func MarshalSubscription(e *EntityConfig) (*mqtt.Subscription, error)
- func PublishConfigs(device MQTTDevice, client MQTTClient) error
- func PublishState(device MQTTDevice, client MQTTClient) error
- func Register(device MQTTDevice, client MQTTClient) error
- func Subscribe(device MQTTDevice, client MQTTClient) error
- func UnRegister(device MQTTDevice, client MQTTClient) error
- func Unpublish(device MQTTDevice, client MQTTClient) error
- type Device
- type Entity
- type EntityConfig
- func (e *EntityConfig) AsBinarySensor() *EntityConfig
- func (e *EntityConfig) AsButton() *EntityConfig
- func (e *EntityConfig) AsSensor() *EntityConfig
- func (e *EntityConfig) WithAttributesCallback(c func() (json.RawMessage, error)) *EntityConfig
- func (e *EntityConfig) WithAttributesTemplate(t string) *EntityConfig
- func (e *EntityConfig) WithAttributesTopic() *EntityConfig
- func (e *EntityConfig) WithCommandCallback(c func(MQTT.Client, MQTT.Message)) *EntityConfig
- func (e *EntityConfig) WithDefaultOriginInfo() *EntityConfig
- func (e *EntityConfig) WithDeviceClass(d string) *EntityConfig
- func (e *EntityConfig) WithDeviceInfo(d *Device) *EntityConfig
- func (e *EntityConfig) WithIcon(i string) *EntityConfig
- func (e *EntityConfig) WithOriginInfo(o *Origin) *EntityConfig
- func (e *EntityConfig) WithStateCallback(c func() (json.RawMessage, error)) *EntityConfig
- func (e *EntityConfig) WithStateClassMeasurement() *EntityConfig
- func (e *EntityConfig) WithStateClassTotal() *EntityConfig
- func (e *EntityConfig) WithStateClassTotalIncreasing() *EntityConfig
- func (e *EntityConfig) WithUnits(u string) *EntityConfig
- func (e *EntityConfig) WithValueTemplate(t string) *EntityConfig
- type MQTTClient
- type MQTTDevice
- type Origin
Constants ¶
This section is empty.
Variables ¶
This section is empty.
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.
func MarshalConfig ¶
func MarshalConfig(e *EntityConfig) (*mqtt.Msg, error)
MarshalConfig will marshal a config message and payload from the given EntityConfig.
func MarshalState ¶
func MarshalState(e *EntityConfig) (*mqtt.Msg, error)
MarshalState will marshal a state message and payload from the given EntityConfig and state value. Where an entity state is combined with other entities, it might be better to manually create a state message.
func MarshalSubscription ¶
func MarshalSubscription(e *EntityConfig) (*mqtt.Subscription, error)
MarshalState will marshal a subscription from the given EntityConfig.
func PublishConfigs ¶
func PublishConfigs(device MQTTDevice, client MQTTClient) error
func PublishState ¶
func PublishState(device MQTTDevice, client MQTTClient) error
func Register ¶
func Register(device MQTTDevice, client MQTTClient) error
Register will check if the app has been registered and if not, publish the app configs to MQTT, which will in turn register the app with Home Assistant. If successfully registered, it will also record this status in the app configuration. If any of these actions are unsuccessful, it will return an error with more details. Otherwise it returns nil.
func Subscribe ¶
func Subscribe(device MQTTDevice, client MQTTClient) error
func UnRegister ¶
func UnRegister(device MQTTDevice, client MQTTClient) error
UnRegister performs two actions. First, it removes the app config topics from MQTT, effectively removing the app from Home Assistant. Second, it updates the app config to indicate it is unregistered. It will return an error if either action fails, otherwise it will return nil.
func Unpublish ¶
func Unpublish(device MQTTDevice, client MQTTClient) error
Types ¶
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"` }
type Entity ¶
type Entity struct { Origin *Origin `json:"origin,omitempty"` Device *Device `json:"device,omitempty"` DeviceClass string `json:"device_class,omitempty"` StateTopic string `json:"state_topic"` StateClass string `json:"state_class,omitempty"` CommandTopic string `json:"command_topic,omitempty"` UnitOfMeasurement string `json:"unit_of_measurement,omitempty"` ValueTemplate string `json:"value_template"` UniqueID string `json:"unique_id"` Name string `json:"name"` EntityCategory string `json:"entity_category,omitempty"` Icon string `json:"icon,omitempty"` AttributesTopic string `json:"json_attributes_topic,omitempty"` AttributesTemplate string `json:"json_attributes_template,omitempty"` }
type EntityConfig ¶
type EntityConfig struct { Entity *Entity App string CommandCallback func(MQTT.Client, MQTT.Message) StateCallback func() (json.RawMessage, error) AttributesCallback func() (json.RawMessage, error) ConfigTopic string // contains filtered or unexported fields }
func NewEntityByID ¶
func NewEntityByID(id, app string) *EntityConfig
NewEntityByID will create a new entity and config based off the given id and app. Use this when you want to ensure the exact format of the id for the underlying sensor in Home Assistant. The name will be derived from the id.
func NewEntityByName ¶
func NewEntityByName(name, app string) *EntityConfig
NewEntityByName will create a new entity and config based off the given name and app. Use this function where you don't care about the id of the underlying sensor in Home Assistant. The id will be derived from the name by converting it to snake_case.
func (*EntityConfig) AsBinarySensor ¶
func (e *EntityConfig) AsBinarySensor() *EntityConfig
AsBinarySensor will configure appropriate MQTT topics to represent a Home Assistant binary_sensor.
func (*EntityConfig) AsButton ¶
func (e *EntityConfig) AsButton() *EntityConfig
AsButton will configure appropriate MQTT topics to represent a Home Assistant button.
func (*EntityConfig) AsSensor ¶
func (e *EntityConfig) AsSensor() *EntityConfig
AsSensor will configure appropriate MQTT topics to represent a Home Assistant sensor.
func (*EntityConfig) WithAttributesCallback ¶
func (e *EntityConfig) WithAttributesCallback(c func() (json.RawMessage, error)) *EntityConfig
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 (*EntityConfig) WithAttributesTemplate ¶
func (e *EntityConfig) WithAttributesTemplate(t string) *EntityConfig
WithAttributesTemplate configures the passed in template to be used to extract the value of the attributes in Home Assistant.
func (*EntityConfig) WithAttributesTopic ¶
func (e *EntityConfig) WithAttributesTopic() *EntityConfig
WithAttributes ensures that the entity has a topic that can be used to publish its attributes.
func (*EntityConfig) WithCommandCallback ¶
func (e *EntityConfig) WithCommandCallback(c func(MQTT.Client, MQTT.Message)) *EntityConfig
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 (*EntityConfig) WithDefaultOriginInfo ¶
func (e *EntityConfig) WithDefaultOriginInfo() *EntityConfig
WithOriginInfo adds a pre-filled origin that references go-hass-agent to the entity config.
func (*EntityConfig) WithDeviceClass ¶
func (e *EntityConfig) WithDeviceClass(d string) *EntityConfig
WithDeviceClass configures the Device Class for the entity.
func (*EntityConfig) WithDeviceInfo ¶
func (e *EntityConfig) WithDeviceInfo(d *Device) *EntityConfig
WithDeviceInfo adds the passed in device info to the entity config.
func (*EntityConfig) WithIcon ¶
func (e *EntityConfig) WithIcon(i string) *EntityConfig
WithIcon adds an icon to the entity
func (*EntityConfig) WithOriginInfo ¶
func (e *EntityConfig) WithOriginInfo(o *Origin) *EntityConfig
WithOriginInfo adds the passed in origin info to the entity config.
func (*EntityConfig) WithStateCallback ¶
func (e *EntityConfig) WithStateCallback(c func() (json.RawMessage, error)) *EntityConfig
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 (*EntityConfig) WithStateClassMeasurement ¶
func (e *EntityConfig) WithStateClassMeasurement() *EntityConfig
WithStateClassMeasurement configures the State Class for the entity to be "measurement".
func (*EntityConfig) WithStateClassTotal ¶
func (e *EntityConfig) WithStateClassTotal() *EntityConfig
WithStateClassMeasurement configures the State Class for the entity to be "total".
func (*EntityConfig) WithStateClassTotalIncreasing ¶
func (e *EntityConfig) WithStateClassTotalIncreasing() *EntityConfig
WithStateClassMeasurement configures the State Class for the entity to be "total_increasing".
func (*EntityConfig) WithUnits ¶
func (e *EntityConfig) WithUnits(u string) *EntityConfig
WithUnits adds a unit of measurement to the entity.
func (*EntityConfig) WithValueTemplate ¶
func (e *EntityConfig) WithValueTemplate(t string) *EntityConfig
WithValueTemplate configures the passed in template to be used to extract the value of the entity in Home Assistant.