server

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2022 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Overview

Package server lets you interact with existing devices

Index

Constants

View Source
const (
	AddedDevice   = "added"
	UpdatedDevice = "updated"
	RemovedDevice = "removed"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device interface {
	// Common contains the common methods for client and server
	device.Common

	// Feature returns the feature with server functions (Set(), OnUpdate()) available.
	// Fetching a feature that doesn't exist will _NOT_ return nil, but instead create
	// a *feature.Fake. To check if feature actually exists; call Feature("name").Exists()
	Feature(name string) Feature

	// Exists returns true if the device exists
	Exists() bool

	// Features returns a slice of available features
	Features() []Feature

	// IsReachable returns true if device is online
	IsReachable() bool

	// Info returns the original device info
	Info() *device.Info
	// contains filtered or unexported methods
}

Device is used by applications that monitor or send commands to the different client devices. For examples an application that integrates with a personal assistant

func NewDevice

func NewDevice(info *device.Info, transport device.Transport) (Device, error)

NewDevice should normally only be called with data from announcements.

type FakeDevice

type FakeDevice struct {
	Err   error
	Topic string
}

func (*FakeDevice) Exists

func (f *FakeDevice) Exists() bool

func (*FakeDevice) Feature

func (f *FakeDevice) Feature(name string) Feature

func (*FakeDevice) Features

func (f *FakeDevice) Features() []Feature

func (*FakeDevice) Id

func (f *FakeDevice) Id() string

func (*FakeDevice) Info

func (f *FakeDevice) Info() *device.Info

func (*FakeDevice) IsReachable

func (f *FakeDevice) IsReachable() bool

func (*FakeDevice) Manufacturer

func (f *FakeDevice) Manufacturer() string

func (*FakeDevice) Model

func (f *FakeDevice) Model() string

func (*FakeDevice) Name

func (f *FakeDevice) Name() string

func (*FakeDevice) SerialNumber

func (f *FakeDevice) SerialNumber() string

func (*FakeDevice) Type

func (f *FakeDevice) Type() string

type Feature

type Feature interface {
	Name() string
	Min() int
	Max() int
	Step() int
	Exists() bool
	Set(string) error
	OnUpdate() (chan string, error)
	OnUpdateFunc(func(string)) error
	Value() string
}

type Handler

type Handler interface {
	AddedDevice(Device)
	UpdatedDevice(Device, []*device.InfoUpdate)
	RemovedDevice(Device)
}

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager holds all the devices and deals with updating device state as it receives it from the transport

func New

func New(t Transport) *Manager

New creates a new Manager

func (*Manager) Device

func (m *Manager) Device(topic string) Device

Device returns a device associated with the topic

func (*Manager) DeviceByType

func (m *Manager) DeviceByType(t string) []Device

DeviceByType returns all devices known to the manager of type t.

func (*Manager) Devices

func (m *Manager) Devices() []Device

Devices returns all devices known to the manager

func (*Manager) HasDevice

func (m *Manager) HasDevice(topic string) bool

HasDevice checks if a device is registered on the topic

func (*Manager) SetHandler

func (m *Manager) SetHandler(handler Handler)

SetHandler is a wrapper around SetUpdateChannel for use with callbacks instead of channels, the handler is called synchronously

func (*Manager) SetUpdateChannel

func (m *Manager) SetUpdateChannel(ch chan<- Update)

SetUpdateChannel registers a channel that will receive Update when a device is added, removed or changed.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context) error

Start starts the Manager's main loop, conusming messages and reacting to changes in the system.Start

func (*Manager) WaitForDevice

func (m *Manager) WaitForDevice(ctx context.Context, topic string) Device

WaitForDevice waits for a device on the specified topic to appear This blocks until either the device shows up, or the context is cancelled

type Transport

type Transport interface {
	// DeviceState receives a device.Info on announce, leave or update
	DeviceState() chan *device.State
	device.Transport
}

Transport is the server's transport

type Update

type Update struct {
	Type    UpdateType
	Device  Device
	Changes []*device.InfoUpdate
}

type UpdateType

type UpdateType string

Jump to

Keyboard shortcuts

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