homie

package module
v0.0.0-...-ba1d20a Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2019 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Homie

Homie is a Go implementation of the Homie IoT specification. Homie implements the specification's device tree structure and provides adapters for writing to and reading from MQTT.

Introduction

The Homie device tree consists of Devices, Nodes and Properties. Each are described by additional attributes.

Documentation

Index

Constants

View Source
const DefaultRootTopic = "homie"

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback func(topic string, retained bool, message string)

type DataType

type DataType string
const (
	DataTypeString  DataType = "string"
	DataTypeInteger DataType = "integer"
	DataTypeFloat   DataType = "float"
	DataTypeBoolean DataType = "boolean"
	DataTypeEnum    DataType = "enum"
	DataTypeColor   DataType = "color"
)

type Device

type Device struct {
	Name           string           `mapstructure:"$name"`
	State          State            `mapstructure:"$state"`
	Version        string           `mapstructure:"$homie"`
	Implementation string           `mapstructure:"$implementation"`
	Extensions     []string         `mapstructure:"_extensions"`
	Nodes          map[string]*Node `mapstructure:"_nodes"`
}

Device represents a device in terms of the spec

func NewDevice

func NewDevice() *Device

NewDevice creates a new device

func (*Device) Add

func (d *Device) Add(id string, n *Node) error

Add attaches a node to the node. An error is raised on duplicate node id.

func (*Device) NewNode

func (d *Device) NewNode(id string) (*Node, error)

NewNode is a conveniece method for creating a new node and attaching it to the device

func (*Device) Publish

func (d *Device) Publish(pub Publisher, topic string)

Publish publishes the device including nodes/properties to MQTT at the given topic. It's the callers responsibility to ensure correct topic.

func (*Device) Unmarshal

func (d *Device) Unmarshal(subscribe Subscriber, topic string)

type Homie

type Homie struct {
	RootTopic string             `mapstructure:"_roottopic"`
	Devices   map[string]*Device `mapstructure:"_devices"`
}

func NewHomie

func NewHomie() *Homie

func (*Homie) Add

func (h *Homie) Add(id string, d *Device) error

func (*Homie) NewDevice

func (h *Homie) NewDevice(id string) (*Device, error)

func (*Homie) Unmarshal

func (h *Homie) Unmarshal(subscribe Subscriber)

type Node

type Node struct {
	Name       string               `mapstructure:"$name"`
	Type       string               `mapstructure:"$type"`
	Properties map[string]*Property `mapstructure:"_properties"`
}

Node represents a device's node in terms of the spec

func NewNode

func NewNode() *Node

NewNode creates a new node

func (*Node) Add

func (n *Node) Add(id string, p *Property) error

Add attaches a property to the node. An error is raised on duplicate property id.

func (*Node) NewProperty

func (n *Node) NewProperty(id string) (*Property, error)

NewProperty is a conveniece method for creating a new property and attaching it to the nodes

func (*Node) Publish

func (n *Node) Publish(pub Publisher, topic string)

Publish publishes the node including properties to MQTT at the given topic. It's the callers responsibility to ensure correct topic and include node in the parent devices $nodes attribute.

func (*Node) Unmarshal

func (n *Node) Unmarshal(subscribe Subscriber, topic string)

type Property

type Property struct {
	Name     string   `mapstructure:"$name"`
	DataType DataType `mapstructure:"$datatype"`
	Value    string   `mapstructure:"_value"`
	Format   string   `mapstructure:"$format"`
	Unit     string   `mapstructure:"$unit"`
	Retained bool     `mapstructure:"$retained"`
	Settable bool     `mapstructure:"$settable"`
}

Property represents a node's property according to the spec

func NewProperty

func NewProperty() *Property

NewProperty creates a new property

func (*Property) Publish

func (p *Property) Publish(pub Publisher, topic string)

Publish publishes the property to MQTT at the given topic. It's the callers responsibility to ensure correct topic and include the property in the parent nodes $properties attribute.

func (*Property) Unmarshal

func (p *Property) Unmarshal(subscribe Subscriber, topic string)

type Publisher

type Publisher func(topic string, retained bool, message string)

type State

type State string

State is the Device state

const (
	// Version is the spec version
	Version = "4.0.0"

	StateInit         State = "init"
	StateReady        State = "ready"
	StateDisconnected State = "disconnected"
	StateSleeping     State = "sleeping"
	StateLost         State = "lost"
	StateAlert        State = "alert"
)

type Subscriber

type Subscriber func(topic string, callback Callback)

Directories

Path Synopsis
examples
publish command
subscribe command

Jump to

Keyboard shortcuts

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