device

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2023 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Overview

Package device defines the basic requirements of a device

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(d *Device) error

Types

type Action

type Action string
const (
	DeleteAction Action = "delete"
	UpdateAction Action = "update"
	LeaveAction  Action = "leave"
)

type Common

type Common interface {
	// Id will return the unique id of the device.
	// This is currently always the same as the topic name.
	Id() string

	// Name returns the name of the device
	Name() string

	// Manufacturer returns the manufacturer
	Manufacturer() string

	// Model returns the model name/number
	Model() string

	// SerialNumber returns the serial number
	SerialNumber() string

	// Type returns the type of the device (lightbulb, outlet, etc)
	Type() string
}

Device contains the common functions for Client and Server

type Device

type Device struct {
	Info      *Info
	Features  map[string]feature.Feature
	Transport Transport
}

func (*Device) Exists

func (d *Device) Exists() bool

func (*Device) Feature

func (d *Device) Feature(name string) feature.Feature

func (*Device) Id

func (d *Device) Id() string

func (*Device) Manufacturer

func (d *Device) Manufacturer() string

func (*Device) Model

func (d *Device) Model() string

func (*Device) Name

func (d *Device) Name() string

func (*Device) SerialNumber

func (d *Device) SerialNumber() string

func (*Device) SetFeature

func (d *Device) SetFeature(f *feature.Info, b []byte)

func (*Device) SubscribeFeature

func (d *Device) SubscribeFeature(topic string) chan []byte

func (*Device) Type

func (d *Device) Type() string

func (*Device) UpdateFeature

func (d *Device) UpdateFeature(f *feature.Info, b []byte)

func (*Device) UpdateInfo

func (d *Device) UpdateInfo(info *Info) (updates []*InfoUpdate, err error)

type Info

type Info 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.Info `json:"feature"`
	Reachable    bool                     `json:"-"`
}

type InfoUpdate

type InfoUpdate struct {
	Field       string
	Old         string
	New         string
	FeatureInfo []*feature.InfoUpdate
}

type State

type State struct {
	Device *Info
	Action Action
	Topic  string
}

type Transport

type Transport interface {
	Publish(topic string, payload []byte, retain bool)
	Subscribe(topic string) chan []byte
	Unsubscribe(topic string) bool
	Resubscribe(oldTopic, newTopic string) bool
	Discover() chan struct{}
	PublishMeta(topic string, payload []byte)
	LastWillID() string
}

type Type

type Type string

Type is the type of device

const (
	AccessoryInformation         Type = "accessoryInformation"
	AirPurifier                  Type = "airPurifier"
	AirQualitySensor             Type = "airQualitySensor"
	BatteryService               Type = "batteryService"
	BridgeConfiguration          Type = "bridgeConfiguration"
	BridgingState                Type = "bridgingState"
	CameraControl                Type = "cameraControl"
	CameraRTPStreamManagement    Type = "cameraRTPStreamManagement"
	CarbonDioxideSensor          Type = "carbonDioxideSensor"
	CarbonMonoxideSensor         Type = "carbonMonoxideSensor"
	ContactSensor                Type = "contactSensor"
	Door                         Type = "door"
	Doorbell                     Type = "doorbell"
	Fan                          Type = "fan"
	FanV2                        Type = "fanV2"
	Faucet                       Type = "faucet"
	FilterMaintenance            Type = "filterMaintenance"
	GarageDoorOpener             Type = "garageDoorOpener"
	HeaterCooler                 Type = "heaterCooler"
	HumidifierDehumidifier       Type = "humidifierDehumidifier"
	HumiditySensor               Type = "humiditySensor"
	IrrigationSystem             Type = "irrigationSystem"
	LeakSensor                   Type = "leakSensor"
	LightSensor                  Type = "lightSensor"
	Lightbulb                    Type = "lightbulb"
	LockManagement               Type = "lockManagement"
	LockMechanism                Type = "lockMechanism"
	Microphone                   Type = "microphone"
	MotionSensor                 Type = "motionSensor"
	OccupancySensor              Type = "occupancySensor"
	Outlet                       Type = "outlet"
	SecuritySystem               Type = "securitySystem"
	ServiceLabel                 Type = "serviceLabel"
	Slat                         Type = "slat"
	SmokeSensor                  Type = "smokeSensor"
	Speaker                      Type = "speaker"
	StatefulProgrammableSwitch   Type = "statefulProgrammableSwitch"
	StatelessProgrammableSwitch  Type = "statelessProgrammableSwitch"
	Switch                       Type = "switch"
	TemperatureSensor            Type = "temperatureSensor"
	Thermostat                   Type = "thermostat"
	TimeInformation              Type = "timeInformation"
	TunneledBTLEAccessoryService Type = "tunneledBTLEAccessoryService"
	Valve                        Type = "valve"
	Window                       Type = "window"
	WindowCovering               Type = "windowCovering"
)

All supported device types

func (Type) Equal

func (t Type) Equal(y Type) bool

Equal checks if two devices are the same

func (Type) String

func (t Type) String() string

String returns the string representation of the device type

Jump to

Keyboard shortcuts

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