mqtt

package
v0.0.0-...-c731d2b Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

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

func (c *Config) LightTopic(topicPrefix string) (string, error)

LightTopic returns the topic string for changing the light state in a Garden

func (*Config) StopAllTopic

func (c *Config) StopAllTopic(topicPrefix string) (string, error)

StopAllTopic returns the topic string for stopping watering all zones in a garden

func (*Config) StopTopic

func (c *Config) StopTopic(topicPrefix string) (string, error)

StopTopic returns the topic string for stopping watering a single zone

func (*Config) WaterTopic

func (c *Config) WaterTopic(topicPrefix string) (string, error)

WaterTopic returns the topic string for watering a zone

type MockClient

type MockClient struct {
	mock.Mock
}

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

Jump to

Keyboard shortcuts

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