mqtt

package
v0.0.0-...-7e516ea Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const QOS = byte(1)

Variables

This section is empty.

Functions

func DefaultHandler

func DefaultHandler(logger *slog.Logger) mqtt.MessageHandler

func LightTopic

func LightTopic(topicPrefix string) (string, error)

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

func StopAllTopic

func StopAllTopic(topicPrefix string) (string, error)

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

func StopTopic

func StopTopic(topicPrefix string) (string, error)

StopTopic returns the topic string for stopping watering a single zone

func UpdateTopic

func UpdateTopic(topicPrefix string) (string, error)

UpdateTopic returns the topic string for updating a controller

func WaterTopic

func WaterTopic(topicPrefix string) (string, error)

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

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) 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

func (*MockClient) Publish

func (_m *MockClient) Publish(_a0 string, _a1 []byte) error

Publish provides a mock function with given fields: _a0, _a1

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