Documentation ¶
Index ¶
- func DefaultHandler(logger *slog.Logger) mqtt.MessageHandler
- type Client
- type Config
- type MockClient
- func (_m *MockClient) Connect() error
- func (_m *MockClient) Disconnect(_a0 uint)
- func (_m *MockClient) LightTopic(_a0 string) (string, error)
- func (_m *MockClient) Publish(_a0 string, _a1 []byte) error
- func (_m *MockClient) StopAllTopic(_a0 string) (string, error)
- func (_m *MockClient) StopTopic(_a0 string) (string, error)
- func (_m *MockClient) WaterTopic(_a0 string) (string, error)
- type TopicHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultHandler ¶
func DefaultHandler(logger *slog.Logger) mqtt.MessageHandler
Types ¶
type Client ¶
type Client interface { Publish(string, []byte) error WaterTopic(string) (string, error) StopTopic(string) (string, error) StopAllTopic(string) (string, error) LightTopic(string) (string, error) Connect() error Disconnect(uint) }
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"` WaterTopicTemplate string `mapstructure:"water_topic"` StopTopicTemplate string `mapstructure:"stop_topic"` StopAllTopicTemplate string `mapstructure:"stop_all_topic"` LightTopicTemplate string `mapstructure:"light_topic"` }
Config is used to read the necessary configuration values from a YAML file
func (*Config) LightTopic ¶
LightTopic returns the topic string for changing the light state in a Garden
func (*Config) StopAllTopic ¶
StopAllTopic returns the topic string for stopping watering all zones in a garden
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) 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
func (*MockClient) LightTopic ¶
func (_m *MockClient) LightTopic(_a0 string) (string, error)
LightTopic provides a mock function with given fields: _a0
func (*MockClient) Publish ¶
func (_m *MockClient) Publish(_a0 string, _a1 []byte) error
Publish provides a mock function with given fields: _a0, _a1
func (*MockClient) StopAllTopic ¶
func (_m *MockClient) StopAllTopic(_a0 string) (string, error)
StopAllTopic provides a mock function with given fields: _a0
func (*MockClient) StopTopic ¶
func (_m *MockClient) StopTopic(_a0 string) (string, error)
StopTopic provides a mock function with given fields: _a0
func (*MockClient) WaterTopic ¶
func (_m *MockClient) WaterTopic(_a0 string) (string, error)
WaterTopic 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