device

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2021 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	Topic        string              `json:"topic"`
	Name         string              `json:"name"`
	Manufacturer string              `json:"manufacturer"`
	Model        string              `json:"model"`
	SerialNumber string              `json:"serialNumber"`
	Type         string              `json:"type"`
	LastWillID   string              `json:"lastWillID,omitempty"`
	Features     map[string]*Feature `json:"feature"`
	Reachable    bool                `json:"-"`

	sync.RWMutex
	// contains filtered or unexported fields
}

func NewDevice

func NewDevice(topic string, client messaging.PublishSubscriber) *Device

func (*Device) AddFeature

func (d *Device) AddFeature(name string, ft *Feature)

AddFeature adds a feature to the device. It ensures the devRef, GetTopic and SetTopic are correctly populated

func (*Device) GetFeature

func (d *Device) GetFeature(feature string) (*Feature, error)

GetFeature returns a *Feature if a feature by that name is found on the device.

func (*Device) HasFeature

func (d *Device) HasFeature(feature string) bool

func (*Device) PublishMeta

func (d *Device) PublishMeta() error

func (*Device) RemoveFeature

func (d *Device) RemoveFeature(name string) error

RemoveFeature removes a feature by that name from the device. It returns an error if you try to remove a feature that does not exist.

func (*Device) UnmarshalJSON

func (d *Device) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals the JSON representation of a device. This is a custom implementation so that we can correctly call .AddFeature() for every feature. This guarantees that the devRef is properly set and that the GetTopic and SetTopic are always set.

type Feature

type Feature struct {
	Min      int    `json:"min,omitempty"`
	Max      int    `json:"max,omitempty"`
	Step     int    `json:"step,omitempty"`
	GetTopic string `json:"getTopic,omitempty"`
	SetTopic string `json:"setTopic,omitempty"`
	// contains filtered or unexported fields
}

func (*Feature) OnSet

func (f *Feature) OnSet(callback func(msg messaging.Message)) error

func (*Feature) OnUpdate

func (f *Feature) OnUpdate(callback func(msg messaging.Message)) error

func (*Feature) Set

func (f *Feature) Set(value string) error

func (*Feature) Update

func (f *Feature) Update(value string) error

type Handler

type Handler interface {
	Updated(*Device)
	Removed(*Device)
}

type Manager

type Manager struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewManager

func NewManager(c messaging.PublishSubscriber, initChan chan bool) *Manager

func (*Manager) Add

func (m *Manager) Add(topic string, meta []byte)

func (*Manager) AddHandler

func (m *Manager) AddHandler(handler Handler)

func (*Manager) Get

func (m *Manager) Get(id string) (*Device, error)

func (*Manager) GetAll

func (m *Manager) GetAll() map[string]*Device

func (*Manager) Leave

func (m *Manager) Leave(msg string)

func (*Manager) Remove

func (m *Manager) Remove(msg string)

type TestingDeviceHandler

type TestingDeviceHandler struct{}

TestingDeviceHandler is a noop device handler. It is meant to be used in tests.

func (*TestingDeviceHandler) Removed

func (t *TestingDeviceHandler) Removed(*Device)

func (*TestingDeviceHandler) Updated

func (t *TestingDeviceHandler) Updated(*Device)

Jump to

Keyboard shortcuts

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