lib.hemtjan.st: lib.hemtjan.st/server Index | Files

package server

import "lib.hemtjan.st/server"

Package server lets you interact with existing devices

Index

Package Files

device.go doc.go fake_device.go feature.go manager.go

Constants

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

type Device Uses

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 Uses

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

NewDevice should normally only be called with data from announcements.

type FakeDevice Uses

type FakeDevice struct {
    Err   error
    Topic string
}

func (*FakeDevice) Exists Uses

func (f *FakeDevice) Exists() bool

func (*FakeDevice) Feature Uses

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

func (*FakeDevice) Features Uses

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

func (*FakeDevice) Id Uses

func (f *FakeDevice) Id() string

func (*FakeDevice) Info Uses

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

func (*FakeDevice) IsReachable Uses

func (f *FakeDevice) IsReachable() bool

func (*FakeDevice) Manufacturer Uses

func (f *FakeDevice) Manufacturer() string

func (*FakeDevice) Model Uses

func (f *FakeDevice) Model() string

func (*FakeDevice) Name Uses

func (f *FakeDevice) Name() string

func (*FakeDevice) SerialNumber Uses

func (f *FakeDevice) SerialNumber() string

func (*FakeDevice) Type Uses

func (f *FakeDevice) Type() string

type Feature Uses

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 Uses

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

type Manager Uses

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 Uses

func New(t Transport) *Manager

New creates a new Manager

func (*Manager) Device Uses

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

Device returns a device associated with the topic

func (*Manager) DeviceByType Uses

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

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

func (*Manager) Devices Uses

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

Devices returns all devices known to the manager

func (*Manager) HasDevice Uses

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

HasDevice checks if a device is registered on the topic

func (*Manager) SetHandler Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

type UpdateType Uses

type UpdateType string

Package server imports 7 packages (graph) and is imported by 1 packages. Updated 2019-05-05. Refresh now. Tools for package owners.