deconz

package
v0.0.0-...-0d36228 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	Config config.APIConfig
	// contains filtered or unexported fields
}

API represents the deCONZ REST API

func (*API) Sensors

func (a *API) Sensors() (*sensor.Sensors, error)

Sensors returns a map of sensors as received from the deCONZ /sensors endpoint The map key is the sensor id.

type CachingSensorProvider

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

CachingSensorProvider is a sensor.Provider that retrieves sensor info from the dCONZ REST API and caches results It is the default sensor.Provider

func NewCachingSensorProvider

func NewCachingSensorProvider(api API, updateInterval time.Duration) (*CachingSensorProvider, error)

NewCachingSensorProvider returns a CachingSensorProvider The CachingSensorProvider is a singleton.

func (*CachingSensorProvider) Sensor

func (c *CachingSensorProvider) Sensor(i int) (*sensor.Sensor, error)

Sensor returns a sensor for a sensor id

func (*CachingSensorProvider) Sensors

func (c *CachingSensorProvider) Sensors() (*sensor.Sensors, error)

Sensors returns all sensors in the cache

type Event

type Event interface {
	EventName() string
	Resource() string
	ResourceID() int
	State() interface{}
}

Event is a common interface for different types of websocket events

func DecodeEvent

func DecodeEvent(sp sensor.Provider, b []byte) (Event, error)

DecodeEvent parses events from bytes

type EventError

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

EventError represents an error during the retrieval or decoding of events It wraps another error Users can specify if the error is recoverable

func NewEventError

func NewEventError(err error, recoverable bool) EventError

NewEventError creates a new EventError that wraps another error

func (EventError) Recoverable

func (e EventError) Recoverable() bool

Recoverable returns true if the error is not critical and execution should go on

type SensorEvent

type SensorEvent struct {
	*sensor.Sensor
	Event
}

SensorEvent is an Event triggered by a Sensor

func (*SensorEvent) Timeseries

func (s *SensorEvent) Timeseries() (map[string]string, map[string]interface{}, error)

Timeseries returns tags and fields for use in InfluxDB

type Timeserieser

type Timeserieser interface {
	Timeseries() (map[string]string, map[string]interface{}, error)
}

Timeserieser returns time series data

type WebsocketEventReader

type WebsocketEventReader struct {
	WebsocketAddr  string
	SensorProvider sensor.Provider
	// contains filtered or unexported fields
}

WebsocketEventReader uses an EventReader (for example WsReader) to provide a channel of SensorEvent The WebsocketEventReader handles connection losses and reconnection attempts of the underlying EventReader

func NewWebsocketEventReader

func NewWebsocketEventReader(api API, si sensor.Provider) (*WebsocketEventReader, error)

NewWebsocketEventReader creates a new WebsocketEventReader that continuously reads events from the deCONZ websocket It uses the API to discover the websocket address The structure of the JSON messages from the websocket depend on the resource/sensor type. Thus, the WsReader requires a sensor.Provider to properly unmarshal those messages.

func (*WebsocketEventReader) Shutdown

func (r *WebsocketEventReader) Shutdown(ctx ctx.Context)

Shutdown closes the reader, closing the connection to deCONZ The method blocks until all background tasks are terminated or the given Context is aborted

func (*WebsocketEventReader) Start

func (r *WebsocketEventReader) Start(ctx ctx.Context) (<-chan *SensorEvent, error)

Start starts a go routine that reads events from the associated EventReader It returns the channel to retrieve events from

type WsEvent

type WsEvent struct {
	// type should always be 'event'
	Type string `json:"t"`

	Event        string `json:"e"`
	ResourceName string `json:"r"`
	ID           int    `json:"id,string"`

	// TODO intermediate type
	// only for e = 'changed'
	RawState json.RawMessage `json:"state"`

	// only for e = 'changed'
	StateDef interface{}
}

WsEvent is a message received over the deCONZ websocket We are only interested in e = 'change' events of resource type r = 'sensor'. Thus we don't implement all fields. See https://dresden-elektronik.github.io/deconz-rest-doc/endpoints/websocket/#message-fields

func (WsEvent) EventName

func (e WsEvent) EventName() string

EventName return the name of an event, e.g. "change"

func (WsEvent) Resource

func (e WsEvent) Resource() string

Resource returns the resource type affected by the event, e.g. "sensor"

func (WsEvent) ResourceID

func (e WsEvent) ResourceID() int

ResourceID returns the unique id of the resource which was affected by the event

func (WsEvent) State

func (e WsEvent) State() interface{}

State returns the current state of the resource

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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