devices

package
v2.1.5 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrWrongIDFormat = fmt.Errorf("wrong ID format. Expected nodeuuid.deviceid")

ErrWrongIDFormat is returned if the new ID is not in the correct format.

Functions

This section is empty.

Types

type Device

type Device struct {
	Type   string   `json:"type"`
	ID     ID       `json:"id"`
	Name   string   `json:"name,omitempty"`
	Alias  string   `json:"alias,omitempty"`
	Online bool     `json:"online"`
	State  State    `json:"state"`
	Traits []string `json:"traits"`
	sync.RWMutex
}

func NewDevice

func NewDevice() *Device

NewDevice initializes a new device with needed maps.

func (*Device) Copy

func (d *Device) Copy() *Device

Copy copies a device.

func (*Device) Equal

func (d *Device) Equal(dev *Device) bool

Equal checks if 2 devices are equal.

func (*Device) MarshalJSON

func (d *Device) MarshalJSON() ([]byte, error)

func (*Device) SetOnline

func (d *Device) SetOnline(v bool)

SetOnline set online state.

type DeviceMap

type DeviceMap map[ID]*Device

type ID

type ID struct {
	Node string
	ID   string
}

func NewIDFromString

func NewIDFromString(id string) (ID, error)

func (ID) Bytes

func (id ID) Bytes() []byte

func (ID) IsZero

func (id ID) IsZero() bool

func (ID) MarshalText

func (id ID) MarshalText() (text []byte, err error)

func (ID) String

func (id ID) String() string

func (*ID) UnmarshalText

func (id *ID) UnmarshalText(text []byte) error

type List

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

func NewList

func NewList() *List

func (*List) Add

func (d *List) Add(dev *Device)

Add adds a device to the list.

func (*List) All

func (d *List) All() DeviceMap

All get all devices.

func (*List) Copy

func (d *List) Copy() *List

Copy copies a list of devices.

func (*List) Flatten

func (d *List) Flatten() map[string]interface{}

Flatten can be used for metrics export and logic rules.

func (*List) Get

func (d *List) Get(id ID) *Device

Get returns a device.

func (*List) Len

func (d *List) Len() int

Len return how many devices there are in the list.

func (*List) MarshalJSON

func (d *List) MarshalJSON() ([]byte, error)

func (*List) Remove

func (d *List) Remove(id ID)

func (*List) SetState

func (d *List) SetState(id ID, state State) error

Update the state of a device.

func (*List) StateGroupedByNode

func (d *List) StateGroupedByNode() map[string]map[ID]State

StateGroupedByNode get state from all devices grouped by node uuid.

func (*List) UnmarshalJSON

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

type State

type State map[string]interface{}

func (State) Bool

func (ds State) Bool(key string, fn func(bool))

Bool runs fn only if key is found in map and it is of type bool.

func (State) Clone

func (ds State) Clone() State

func (State) Diff

func (ds State) Diff(right State) State

Diff calculates the diff between 2 states. If key is missing in right but exists in left it will not be a diff.

func (State) Equal

func (ds State) Equal(right State) bool

func (State) Float

func (ds State) Float(key string, fn func(float64))

Float runs fn only if key is found in map and it is of type int.

func (State) Int

func (ds State) Int(key string, fn func(int64))

Int runs fn only if key is found in map and it is of type int.

func (State) Merge

func (ds State) Merge(right State) State

Merge two states.

func (State) MergeWith

func (ds State) MergeWith(right State)

func (State) String

func (ds State) String(key string, fn func(string))

String runs fn only if key is found in map and it is of type int.

Jump to

Keyboard shortcuts

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