Documentation
¶
Index ¶
- Constants
- func DefaultHandler(logger *slog.Logger) mqtt.MessageHandler
- func LightTopic(topicPrefix string) (string, error)
- func StopAllTopic(topicPrefix string) (string, error)
- func StopTopic(topicPrefix string) (string, error)
- func UpdateTopic(topicPrefix string) (string, error)
- func WaterTopic(topicPrefix string) (string, error)
- type Client
- type Config
- type MockClient
- type TopicHandler
Constants ¶
const QOS = byte(1)
Variables ¶
This section is empty.
Functions ¶
func DefaultHandler ¶
func DefaultHandler(logger *slog.Logger) mqtt.MessageHandler
func LightTopic ¶
LightTopic returns the topic string for changing the light state in a Garden
func StopAllTopic ¶
StopAllTopic returns the topic string for stopping watering all zones in a garden
func UpdateTopic ¶
UpdateTopic returns the topic string for updating a controller
func WaterTopic ¶
WaterTopic returns the topic string for watering a zone
Types ¶
type Client ¶
type Client interface { Publish(string, []byte) error Connect() error Disconnect(uint) AddHandler(TopicHandler) }
Client is an interface that allows access to MQTT functionality within the garden-app
func NewClient ¶
func NewClient(config Config, defaultHandler mqtt.MessageHandler, handlers ...TopicHandler) (Client, error)
NewClient is used to create and return a MQTTClient. The handlers argument enables the subscriber using the supplied functions to handle incoming messages. It really should be used with only one function, but I wanted to make it an optional argument, which required using the variadic function argument
type Config ¶
type Config struct { ClientID string `mapstructure:"client_id"` Broker string `mapstructure:"broker"` Port int `mapstructure:"port"` }
Config is used to read the necessary configuration values from a YAML file
type MockClient ¶
MockClient is an autogenerated mock type for the Client type
func NewMockClient ¶
func NewMockClient(t interface { mock.TestingT Cleanup(func()) }) *MockClient
NewMockClient creates a new instance of MockClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*MockClient) AddHandler ¶
func (_m *MockClient) AddHandler(_a0 TopicHandler)
AddHandler provides a mock function with given fields: _a0
func (*MockClient) Connect ¶
func (_m *MockClient) Connect() error
Connect provides a mock function with given fields:
func (*MockClient) Disconnect ¶
func (_m *MockClient) Disconnect(_a0 uint)
Disconnect provides a mock function with given fields: _a0
type TopicHandler ¶
type TopicHandler struct { Topic string Handler mqtt.MessageHandler }
TopicHandler is a struct that contains a topic string and MessageHandler for instructing the client how to handle topics