Documentation
¶
Index ¶
- func MQTTDiscoveryOverride(field reflect.StructField) (string, bool)
- func MQTTOverride(field reflect.StructField) (string, bool)
- func SimpleKVMapParser(kvSep string, itemSep string) func(v string) (interface{}, error)
- type Command
- type CommandObserver
- type CommandPublisher
- type Event
- type GeneralConfig
- type MQTTDiscovery
- type MQTTProxy
- func (c *MQTTProxy) AvailabilityTopic() string
- func (c *MQTTProxy) CommandTopic(name string, sensor string) string
- func (c *MQTTProxy) Initialize(onConn mqtt.OnConnectHandler, onLost mqtt.ConnectionLostHandler)
- func (c *MQTTProxy) LastPublishedOnTopic(topic string) string
- func (c *MQTTProxy) LogSettings()
- func (c *MQTTProxy) NewMQTTDiscovery(name string, sensor string, sensorType string) *MQTTDiscovery
- func (c *MQTTProxy) Publish(topic string, payload string)
- func (c *MQTTProxy) PublishDiscovery(mqd *MQTTDiscovery)
- func (c *MQTTProxy) PublishWithOpts(topic string, payload string, opts MQTTProxyPublishOptions)
- func (c *MQTTProxy) Run()
- func (c *MQTTProxy) StateTopic(name string, sensor string) string
- func (c *MQTTProxy) Subscribe(topic string, qos byte, callback mqtt.MessageHandler) mqtt.Token
- type MQTTProxyConfig
- type MQTTProxyPublishOptions
- type MoqMessage
- type StateObserver
- type StatePublisher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MQTTDiscoveryOverride ¶
func MQTTDiscoveryOverride(field reflect.StructField) (string, bool)
MQTTDiscoveryOverride -
Types ¶
type Command ¶
type Command = int64
Command - A type used to communicate commands between publisher and observer
type CommandObserver ¶ added in v0.2.0
CommandObserver - Observe commands and take action
type CommandPublisher ¶ added in v0.2.0
type CommandPublisher struct {
// contains filtered or unexported fields
}
CommandPublisher - Determine commands and inform observers
func (*CommandPublisher) Register ¶ added in v0.2.0
func (c *CommandPublisher) Register(l CommandObserver)
Register - Register an observer
func (*CommandPublisher) SendCommand ¶ added in v0.2.0
func (c *CommandPublisher) SendCommand(cmd Command, e Event)
SendCommand - Send commands to observers
type GeneralConfig ¶
type GeneralConfig struct {
DebugLogLevel bool `env:"DEBUG" envDefault:"false"`
}
GeneralConfig - Configuration applicable to the genereal application
type MQTTDiscovery ¶
type MQTTDiscovery struct {
// Used for topic generation; never output in discovery JSON
DiscoveryName string `json:"-"`
DiscoveryPrefix string `json:"-"`
Component string `json:"-"`
NodeID string `json:"-"`
ObjectID string `json:"-"`
// Used in discovery JSON
AuxCommandTopic string `json:"aux_command_topic,omitempty"`
AuxStateTemplate string `json:"aux_state_template,omitempty"`
AuxStateTopic string `json:"aux_state_topic,omitempty"`
AvailabilityTopic string `json:"availability_topic,omitempty"`
AwayModeCommandTopic string `json:"away_mode_command_topic,omitempty"`
AwayModeStateTemplate string `json:"away_mode_state_template,omitempty"`
AwayModeStateTopic string `json:"away_mode_state_topic,omitempty"`
BrightnessCommandTopic string `json:"brightness_command_topic,omitempty"`
BrightnessScale string `json:"brightness_scale,omitempty"`
BrightnessStateTopic string `json:"brightness_state_topic,omitempty"`
BrightnessValueTemplate string `json:"brightness_value_template,omitempty"`
ColorTempCommandTopic string `json:"color_temp_command_topic,omitempty"`
ColorTempStateTopic string `json:"color_temp_state_topic,omitempty"`
ColorTempValueTemplate string `json:"color_temp_value_template,omitempty"`
CommandTopic string `json:"command_topic,omitempty"`
CurrentTemperatureTopic string `json:"current_temperature_topic,omitempty"`
DeviceClass string `json:"device_class,omitempty"`
EffectCommandTopic string `json:"effect_command_topic,omitempty"`
EffectList string `json:"effect_list,omitempty"`
EffectStateTopic string `json:"effect_state_topic,omitempty"`
EffectValueTemplate string `json:"effect_value_template,omitempty"`
ExpireAfter string `json:"expire_after,omitempty"`
FanModeCommandTopic string `json:"fan_mode_command_topic,omitempty"`
FanModeStateTemplate string `json:"fan_mode_state_template,omitempty"`
FanModeStateTopic string `json:"fan_mode_state_topic,omitempty"`
ForceUpdate string `json:"force_update,omitempty"`
HoldCommandTopic string `json:"hold_command_topic,omitempty"`
HoldStateTemplate string `json:"hold_state_template,omitempty"`
HoldStateTopic string `json:"hold_state_topic,omitempty"`
Icon string `json:"icon,omitempty"`
Initial string `json:"initial,omitempty"`
JSONAttributesTopic string `json:"json_attributes_topic,omitempty"`
JSONAttributes string `json:"json_attributes,omitempty"`
MaxTemp string `json:"max_temp,omitempty"`
MinTemp string `json:"min_temp,omitempty"`
ModeCommandTopic string `json:"mode_command_topic,omitempty"`
ModeStateTemplate string `json:"mode_state_template,omitempty"`
ModeStateTopic string `json:"mode_state_topic,omitempty"`
Name string `json:"name,omitempty"`
OnCommandType string `json:"on_command_type,omitempty"`
Optimistic string `json:"optimistic,omitempty"`
OscillationCommandTopic string `json:"oscillation_command_topic,omitempty"`
OscillationStateTopic string `json:"oscillation_state_topic,omitempty"`
OscillationValueTemplate string `json:"oscillation_value_template,omitempty"`
PayloadArmAway string `json:"payload_arm_away,omitempty"`
PayloadArmHome string `json:"payload_arm_home,omitempty"`
PayloadAvailable string `json:"payload_available,omitempty"`
PayloadClose string `json:"payload_close,omitempty"`
PayloadDisarm string `json:"payload_disarm,omitempty"`
PayloadHighSpeed string `json:"payload_high_speed,omitempty"`
PayloadLock string `json:"payload_lock,omitempty"`
PayloadLowSpeed string `json:"payload_low_speed,omitempty"`
PayloadMediumSpeed string `json:"payload_medium_speed,omitempty"`
PayloadNotAvailable string `json:"payload_not_available,omitempty"`
PayloadOff string `json:"payload_off,omitempty"`
PayloadOn string `json:"payload_on,omitempty"`
PayloadOpen string `json:"payload_open,omitempty"`
PayloadOscillationOff string `json:"payload_oscillation_off,omitempty"`
PayloadOscillationOn string `json:"payload_oscillation_on,omitempty"`
PayloadStop string `json:"payload_stop,omitempty"`
PayloadUnlock string `json:"payload_unlock,omitempty"`
PowerCommandTopic string `json:"power_command_topic,omitempty"`
Retain string `json:"retain,omitempty"`
RgbCommandTemplate string `json:"rgb_command_template,omitempty"`
RgbCommandTopic string `json:"rgb_command_topic,omitempty"`
RgbStateTopic string `json:"rgb_state_topic,omitempty"`
RgbValueTemplate string `json:"rgb_value_template,omitempty"`
SendIfOff string `json:"send_if_off,omitempty"`
SetPositionTemplate string `json:"set_position_template,omitempty"`
SetPositionTopic string `json:"set_position_topic,omitempty"`
SpeedCommandTopic string `json:"speed_command_topic,omitempty"`
SpeedStateTopic string `json:"speed_state_topic,omitempty"`
SpeedValueTemplate string `json:"speed_value_template,omitempty"`
Speeds string `json:"speeds,omitempty"`
StateClosed string `json:"state_closed,omitempty"`
StateOff string `json:"state_off,omitempty"`
StateOn string `json:"state_on,omitempty"`
StateOpen string `json:"state_open,omitempty"`
StateTopic string `json:"state_topic,omitempty"`
StateValueTemplate string `json:"state_value_template,omitempty"`
SwingModeCommandTopic string `json:"swing_mode_command_topic,omitempty"`
SwingModeStateTemplate string `json:"swing_mode_state_template,omitempty"`
SwingModeStateTopic string `json:"swing_mode_state_topic,omitempty"`
TemperatureCommandTopic string `json:"temperature_command_topic,omitempty"`
TemperatureStateTemplate string `json:"temperature_state_template,omitempty"`
TemperatureStateTopic string `json:"temperature_state_topic,omitempty"`
TiltClosedValue string `json:"tilt_closed_value,omitempty"`
TiltCommandTopic string `json:"tilt_command_topic,omitempty"`
TiltInvertState string `json:"tilt_invert_state,omitempty"`
TiltMax string `json:"tilt_max,omitempty"`
TiltMin string `json:"tilt_min,omitempty"`
TiltOpenedValue string `json:"tilt_opened_value,omitempty"`
TiltStatusOptimistic string `json:"tilt_status_optimistic,omitempty"`
TiltStatusTopic string `json:"tilt_status_topic,omitempty"`
Topic string `json:"topic,omitempty"`
UniqueID string `json:"unique_id,omitempty"`
UnitOfMeasurement string `json:"unit_of_measurement,omitempty"`
ValueTemplate string `json:"value_template,omitempty"`
WhiteValueCommandTopic string `json:"white_value_command_topic,omitempty"`
WhiteValueStateTopic string `json:"white_value_state_topic,omitempty"`
WhiteValueTemplate string `json:"white_value_template,omitempty"`
XyCommandTopic string `json:"xy_command_topic,omitempty"`
XyStateTopic string `json:"xy_state_topic,omitempty"`
XyValueTemplate string `json:"xy_value_template,omitempty"`
}
MQTTDiscovery - Aid creating/publishing Home-Assistant MQTT Discovery.
type MQTTProxy ¶
type MQTTProxy struct {
MQTTProxyConfig
Client mqtt.Client
// contains filtered or unexported fields
}
MQTTProxy - A wrapper for the Paho MQTT
func NewMQTTProxy ¶
func NewMQTTProxy(mqttCfg MQTTProxyConfig) *MQTTProxy
NewMQTTProxy - Create a proxy for an MQTT Client
func (*MQTTProxy) AvailabilityTopic ¶
AvailabilityTopic - Generate the availability topic
func (*MQTTProxy) CommandTopic ¶
CommandTopic - Generate the command topic for a named sensor
func (*MQTTProxy) Initialize ¶
func (c *MQTTProxy) Initialize(onConn mqtt.OnConnectHandler, onLost mqtt.ConnectionLostHandler)
Initialize - Initialize the MQTT Client with all the appropriate settings
func (*MQTTProxy) LastPublishedOnTopic ¶
LastPublishedOnTopic - Determine what was last published on a topic
func (*MQTTProxy) LogSettings ¶
func (c *MQTTProxy) LogSettings()
LogSettings - Logs the current settings
func (*MQTTProxy) NewMQTTDiscovery ¶
func (c *MQTTProxy) NewMQTTDiscovery(name string, sensor string, sensorType string) *MQTTDiscovery
NewMQTTDiscovery - Proxy a new MQTTDiscovery object
func (*MQTTProxy) PublishDiscovery ¶
func (c *MQTTProxy) PublishDiscovery(mqd *MQTTDiscovery)
PublishDiscovery - Publish a MQTTDiscovery
func (*MQTTProxy) PublishWithOpts ¶ added in v0.1.1
func (c *MQTTProxy) PublishWithOpts(topic string, payload string, opts MQTTProxyPublishOptions)
PublishWithOpts - Publish a topic and payload with specific options
func (*MQTTProxy) StateTopic ¶
StateTopic - Generate the state topic for a named sensor
type MQTTProxyConfig ¶
type MQTTProxyConfig struct {
ClientID string `env:"MQTT_CLIENTID"`
Broker string `env:"MQTT_BROKER" envDefault:"tcp://test.mosquitto.org:1883"`
Username string `env:"MQTT_USERNAME"`
Password string `env:"MQTT_PASSWORD"`
TopicPrefix string `env:"MQTT_TOPICPREFIX"`
Discovery bool `env:"MQTT_DISCOVERY" envDefault:"false"`
DiscoveryPrefix string `env:"MQTT_DISCOVERYPREFIX" envDefault:"homeassistant"`
DiscoveryName string `env:"MQTT_DISCOVERYNAME"`
}
MQTTProxyConfig - Configuration applicable to the MQTTProxy
type MQTTProxyPublishOptions ¶ added in v0.1.1
MQTTProxyPublishOptions - MQTTProxy Publish Options
type MoqMessage ¶
MoqMessage - Aid testing MQTT callbacks
func (*MoqMessage) Duplicate ¶
func (m *MoqMessage) Duplicate() bool
Duplicate - I'm just here so I don't get fined
func (*MoqMessage) MessageID ¶
func (m *MoqMessage) MessageID() uint16
MessageID - I'm just here so I don't get fined
func (*MoqMessage) Payload ¶
func (m *MoqMessage) Payload() []byte
Payload - I'm just here so I don't get fined
func (*MoqMessage) Retained ¶
func (m *MoqMessage) Retained() bool
Retained - I'm just here so I don't get fined
func (*MoqMessage) Topic ¶
func (m *MoqMessage) Topic() string
Topic - I'm just here so I don't get fined
type StateObserver ¶ added in v0.2.0
type StateObserver interface {
ReceiveState(Event)
}
StateObserver - Observe state changes and do something with them (e.g. publish over MQTT)
type StatePublisher ¶ added in v0.2.0
type StatePublisher struct {
// contains filtered or unexported fields
}
StatePublisher - Determine states and inform observers
func (*StatePublisher) Register ¶ added in v0.2.0
func (c *StatePublisher) Register(l StateObserver)
Register - Register an observer
func (*StatePublisher) SendState ¶ added in v0.2.0
func (c *StatePublisher) SendState(e Event)
SendState - Send states to observers