mqtt

package
v1.0.1-0...-55ed96b Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultScheme = "ssl"
	DefaultHost   = "127.0.0.1"
	DefaultPort   = 8883
)

Variables

View Source
var DefaultConfig = Config{
	Scheme: DefaultScheme,
	Host:   DefaultHost,
	Port:   DefaultPort,
}

Functions

func BrokerURI

func BrokerURI(config Config) string

func RandomString

func RandomString(n int) string

func StateTopic

func StateTopic(device ha.Device, suffix string) string

func UniqueId

func UniqueId(device ha.Device, suffix string) string

Types

type Config

type Config struct {
	Scheme   string `mapstructure:"scheme"`
	Host     string `mapstructure:"host"`
	Port     int    `mapstructure:"port"`
	Username string `mapstructure:"username"`
	Password string `mapstructure:"password"`
}

type MQTT

type MQTT struct {
	Client PubSub
}

func NewMQTT

func NewMQTT(ctx context.Context, config Config) (*MQTT, error)

func (*MQTT) ListVehicles

func (m *MQTT) ListVehicles(ctx context.Context, tmCfg tm.Config) (map[string]ha.Device, error)

func (*MQTT) Publish

func (m *MQTT) Publish(ctx context.Context, discoveryPrefix string, v ...interface{}) error

func (*MQTT) PublishDiscovery

func (m *MQTT) PublishDiscovery(ctx context.Context, id string, device ha.Device, haCfg ha.Config,
	unitsCfg units.Config) error

func (*MQTT) Subscribe

func (m *MQTT) Subscribe(ctx context.Context, topic string) (<-chan paho.Message, error)

func (*MQTT) Unsubscribe

func (m *MQTT) Unsubscribe(ctx context.Context, topic string) error

type PubSub

type PubSub interface {
	Publish(topic string, qos byte, retained bool, payload interface{}) paho.Token
	Subscribe(topic string, qos byte, callback paho.MessageHandler) paho.Token
	Unsubscribe(topics ...string) paho.Token
}

Jump to

Keyboard shortcuts

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