smarthome

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2018 License: MIT Imports: 9 Imported by: 5

README

smarthome

Go package for writing github.com/mqtt-smarthome based services

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultMQTTClientOptions

func DefaultMQTTClientOptions() *mqtt.ClientOptions

Types

type Client

type Client interface {
	// Set publishes a set message with the value
	Set(toplevel, item string, value string) error
	// Get publishes a get request message.
	Get(toplevel, item string) (Value, error)
	// Command publishes a command to the toplevel topic.
	Command(toplevel string, cmd []byte) error

	// Subscribe to receive callbacks whenever a status message is received.
	Subscribe(toplevel, item string) *Subscription

	// Close disconnects the client.
	Close()
}

func NewClient

func NewClient(opts *mqtt.ClientOptions) (Client, error)

type ConnectionState

type ConnectionState int
const (
	Connected ConnectionState = iota
	Disconnected
)

type Device

type Device struct {
	Toplevel string
	Item     string
	Value    Value
}

type DeviceLookup

type DeviceLookup interface {
	Device(toplevel, item string) (Device, bool)
	Find(toplevel string, itemMatch *regexp.Regexp) []Device
	Close()
}

func NewDeviceLookup

func NewDeviceLookup(c Client) DeviceLookup

type Handler

type Handler interface {
	// Set handles a set request.
	Set(toplevel, item string, value interface{})
	// Get handles a get request.
	Get(toplevel, item string) (Value, bool)
	// Command handles a command request.
	Command(toplevel string, cmd []byte)
}

type Server

type Server interface {
	// Connect to the MQTT broker.
	Connect() error
	// Disconnect from the MQTT broker.
	Disconnect()

	// Publish the state of the hardware connection.
	PublishHWStatus(ConnectionState) error

	// Publish a status message.
	PublishStatus(item string, value Value) error
	// Publish a one-shot message.
	PublishOneShotStatus(item string, value Value) error

	// Client returns a client that shares the underlying MQTT connection.
	// The server must be connected before calling.
	// Closing the client is required but will not disconnect the underlying MQTT connection.
	Client() (Client, error)
}

func NewServer

func NewServer(toplevel string, h Handler, opts *mqtt.ClientOptions) Server

type StatusMessage

type StatusMessage struct {
	Toplevel string
	Item     string
	Value    Value
}

type Subscription

type Subscription struct {
	C <-chan StatusMessage
	// contains filtered or unexported fields
}

func (*Subscription) Unsubscribe

func (s *Subscription) Unsubscribe()

type Value

type Value struct {
	Value       interface{}
	Time        time.Time
	LastChanged time.Time
}

func PayloadToValue

func PayloadToValue(data []byte) Value

func (Value) MarshalJSON

func (v Value) MarshalJSON() ([]byte, error)

func (*Value) UnmarshalJSON

func (v *Value) UnmarshalJSON(text []byte) error

Jump to

Keyboard shortcuts

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