hubtypes

package
v0.0.0-...-f8c32d9 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttrBool

type AttrBool struct {
	Value      bool      `json:"value"`
	LastReport time.Time `json:"reported"`
}

func (*AttrBool) CopyIfDifferent

func (a *AttrBool) CopyIfDifferent(dest **AttrBool)

func (*AttrBool) LastChange

func (a *AttrBool) LastChange() time.Time

type AttrBuilder

type AttrBuilder struct {
	Reported time.Time
}

func NewAttrBuilder

func NewAttrBuilder(reported time.Time) AttrBuilder

func (AttrBuilder) Bool

func (a AttrBuilder) Bool(value bool) *AttrBool

func (AttrBuilder) Color

func (a AttrBuilder) Color(r, g, b uint8) *AttrColor

func (AttrBuilder) Event

func (a AttrBuilder) Event() *AttrEvent

func (AttrBuilder) Float

func (a AttrBuilder) Float(value float64) *AttrFloat

func (AttrBuilder) Int

func (a AttrBuilder) Int(value int64) *AttrInt

func (AttrBuilder) PlaybackControl

func (a AttrBuilder) PlaybackControl(control PlaybackControl) *AttrPlaybackControl

func (AttrBuilder) PressUp

func (a AttrBuilder) PressUp(key evdevcodes.KeyOrButton) *AttrPress

func (AttrBuilder) String

func (a AttrBuilder) String(value string) *AttrString

type AttrColor

type AttrColor struct {
	Red        uint8     `json:"r"` // [0..255]
	Green      uint8     `json:"g"` // [0..255]
	Blue       uint8     `json:"b"` // [0..255]
	LastReport time.Time `json:"reported"`
}

func (AttrColor) Converter

func (a AttrColor) Converter() colorful.Color

func (*AttrColor) CopyIfDifferent

func (a *AttrColor) CopyIfDifferent(dest **AttrColor)

func (*AttrColor) LastChange

func (a *AttrColor) LastChange() time.Time

type AttrEvent

type AttrEvent struct {
	LastReport time.Time `json:"reported"`
}

event is like bool, but with "always true", i.e. it just happened. there is no "not happened" - or if there is it implicitly at times when even didn't happen.

func (*AttrEvent) LastChange

func (a *AttrEvent) LastChange() time.Time

type AttrFloat

type AttrFloat struct {
	Value      float64   `json:"value"`
	LastReport time.Time `json:"reported"`
}

func (*AttrFloat) CopyIfDifferent

func (a *AttrFloat) CopyIfDifferent(dest **AttrFloat)

func (*AttrFloat) LastChange

func (a *AttrFloat) LastChange() time.Time

type AttrInt

type AttrInt struct {
	Value      int64     `json:"value"`
	LastReport time.Time `json:"reported"`
}

func (*AttrInt) CopyIfDifferent

func (a *AttrInt) CopyIfDifferent(dest **AttrInt)

func (*AttrInt) LastChange

func (a *AttrInt) LastChange() time.Time

type AttrOrientation

type AttrOrientation struct {
	X          int
	Y          int
	Z          int
	LastReport time.Time `json:"reported"`
}

func (*AttrOrientation) LastChange

func (a *AttrOrientation) LastChange() time.Time

type AttrPlaybackControl

type AttrPlaybackControl struct {
	Control    PlaybackControl `json:"control"`
	LastReport time.Time       `json:"reported"`
}

func (*AttrPlaybackControl) LastChange

func (a *AttrPlaybackControl) LastChange() time.Time

type AttrPress

type AttrPress struct {
	// key press, identified by Linux evdev code. examples (below Key{VOLUMEUP} means evdevcodes.KeyVOLUMEUP):
	// - Key{BRIGHTNESSUP, BRIGHTNESSDOWN} if key is for ± brightness
	// - Key{VOLUMEUP, VOLUMEDOWN} if key is for ± volume
	// - Key{OK, SELECT, CANCEL, BACK} for generic selections and navigation
	// - Key{POWER} if key is for power (toggling) generic devices (not just lights)
	// - Key{OPEN, CLOSE} if key is for power opening or closing something (curtains, shades, door etc.)
	// - Key{LIGHTS_TOGGLE} if key can be used only for toggling lights (like if the key has a light symbol instead of a power symbol)
	// - Btn{0,...,9} for generic buttons or un-numbered buttons whose press isn't intended to produce their number: "button 1", "button 2", ... or "leftmost button", "the second button", "third button" etc.
	// - Key{NUMERIC_0,...NUMERIC_9,NUMERIC_STAR,NUMERIC_POUND} for keypads, remote controls **where the buttons have number labels**
	// - Key{NEXT, PREVIOUS} if key is for selecting a list item, be it playlist, scene list or similar
	// - Key{NEXTSONG, PREVIOUSSONG} if key is for controlling audio. prefer {NEXT,PREVIOUS} if playlist can contain video or other non-audio items.
	// - Key{PLAYPAUSE, PLAY, STOP, MUTE, etc.} if key is for media control
	// - Key{LEFT, RIGHT} if key has horizontal directionality and no distinct evdev property to control (volume, brightness)
	// - Key{UP, DOWN} if key has vertical directionality and no distinct evdev property to control (volume, brightness)
	// - Most suitable evdev code if above instructions don't cover your use case
	Key            evdevcodes.KeyOrButton   `json:"key"`                       // primary (or first) key. for convenience because usually we get only single-key presses
	KeysAdditional []evdevcodes.KeyOrButton `json:"keys_additional,omitempty"` // in rare occasion there are multiple keys pressed at once. additional keys to primary are here. see AllKeys()
	Kind           PressKind                `json:"kind,omitempty"`            // usually PressKindUp, but can be down/hold if we have hold detection or get separate keyup, keydown events
	CountRaw       *int                     `json:"count,omitempty"`           // double, triple etc. clicks. only specify if >= 2. see Count()

	LastReport time.Time `json:"reported"`
}

Models a key/button press. Supports key combinations and double/triple/etc. clicks. Examples:

{Key: KeyPOWER} for a power toggle {Key: Btn0, KeysAdditional=[Btn1], Kind=Hold} for two buttons held in a switch that has two buttons {Key: Btn0, Times=2} for a double click in a single-button switch

func (*AttrPress) AllKeys

func (a *AttrPress) AllKeys() []evdevcodes.KeyOrButton

it is recommended to use this to know all keys which were pressed instead of accessing Key/KeysAdditional directly!

func (*AttrPress) Count

func (a *AttrPress) Count() int

returns how many times they key was pressed

func (*AttrPress) HasKey

func (a *AttrPress) HasKey(key evdevcodes.KeyOrButton) bool

func (*AttrPress) LastChange

func (a *AttrPress) LastChange() time.Time

type AttrString

type AttrString struct {
	Value      string    `json:"value"`
	LastReport time.Time `json:"reported"`
}

func (*AttrString) CopyIfDifferent

func (a *AttrString) CopyIfDifferent(dest **AttrString)

func (*AttrString) LastChange

func (a *AttrString) LastChange() time.Time

type Attribute

type Attribute interface {
	LastChange() time.Time
}

things each attribute is expected to implement

type Attributes

type Attributes struct {
	Presence         *AttrBool  `json:"presence,omitempty"`   // user is present in a room
	Brightness       *AttrInt   `json:"brightness,omitempty"` // 0-255
	Color            *AttrColor `json:"color,omitempty"`      // color in (R,G,B)
	ColorTemperature *AttrInt   `json:"color_temp,omitempty"` // mireds
	On               *AttrBool  `json:"on,omitempty"`         // on/off state
	Press            *AttrPress `json:"press,omitempty"`      // generalized version of push
	Contact          *AttrBool  `json:"contact,omitempty"`    // true=> door/window closed
	WaterDetected    *AttrBool  `json:"water_detected,omitempty"`
	Vibration        *AttrEvent `json:"vibration,omitempty"`
	Tilt             *AttrEvent `json:"tilt,omitempty"`
	AlertSelect      *AttrEvent `json:"alert_select,omitempty"` // light blinks
	Drop             *AttrEvent `json:"drop,omitempty"`
	BatteryVoltage   *AttrFloat `json:"battery_voltage,omitempty"` // [V]
	// BatteryLevel   *AttrFloat       `json:"battery_level,omitempty"` // [0-100 %]. only set if reported by device. calculated % levels to Home Assistant are usually calculated on-the-fly
	Temperature      *AttrFloat       `json:"temperature,omitempty"`  // [°C]
	HumidityRelative *AttrFloat       `json:"humidity_rel,omitempty"` // [0-100 %]
	Pressure         *AttrFloat       `json:"pressure,omitempty"`     // [hPa]
	Illuminance      *AttrFloat       `json:"illuminance,omitempty"`  // lux?
	Orientation      *AttrOrientation `json:"orientation,omitempty"`
	ShadePosition    *AttrInt         `json:"shade_position,omitempty"` // 0-100. 100 % = covers whole window, i.e. closed
	ShadeStop        *AttrEvent       `json:"shade_stop,omitempty"`

	PlaybackControl *AttrPlaybackControl `json:"playback_control,omitempty"`

	CustomFloat  map[string]*AttrFloat  `json:"custom_float,omitempty"`
	CustomString map[string]*AttrString `json:"custom_string,omitempty"`
}

encapsulates device endpoint's (a device can have many) attribute values like sensor values (temperature, humidity etc.) TODO: rename to endpointattributes?

func NewAttributes

func NewAttributes() *Attributes

func (*Attributes) CopyDifferentAttrsTo

func (a *Attributes) CopyDifferentAttrsTo(dest *Attributes)

type AttrsCtx

type AttrsCtx struct {
	AttrBuilder
	Attrs    *Attributes
	Endpoint zigbee.EndpointId
}

builder helper for wrapping attributes with shared timestamp

type BatteryType

type BatteryType struct {
	// it'd be nice if we could just define simple linear (empty, full) voltage ranges,
	// but in reality it's a curve and thus different battery types need functions map points on curve
	// to the percentage of energy left. example curve for CR2032:
	// https://components101.com/asset/sites/default/files/inline-images/CR2032-Discharge-Time.png
	ToVoltage func(voltage float64) float64
}

func (BatteryType) VoltageToPercentage

func (b BatteryType) VoltageToPercentage(voltage float64) float64

returns clamped range [0.0, 1.0]

type Device

type Device struct {
	FriendlyName string          `json:"friendly_name"`
	Area         string          `json:"area"`          // added to Home Assistant only if this is set
	ZigbeeDevice *ezstack.Device `json:"zigbee_device"` // zigbee-level details
	State        *DeviceState    `json:"state"`
}

unique id is ZigbeeDevice.IEEEAddress

func (*Device) DefaultEndpoint

func (d *Device) DefaultEndpoint() *Attributes

you can use this if device doesn't implement multiple endpoints

func (*Device) ImplementsCluster

func (d *Device) ImplementsCluster(cluster cluster.ClusterId) bool

type DeviceState

type DeviceState struct {
	LinkQuality   *AttrInt                          `json:"link_quality,omitempty"` // signal quality, "LQI" 0-255
	EndpointAttrs map[zigbee.EndpointId]*Attributes `json:"attrs"`                  // endpoint-specific attrs
}

func (*DeviceState) LastHeard

func (d *DeviceState) LastHeard() time.Time

used to also compare which new attributes we received compared to last state we knew

type PlaybackControl

type PlaybackControl string
const (
	PlaybackControlPlay        PlaybackControl = "Play"
	PlaybackControlPause       PlaybackControl = "Pause"
	PlaybackControlStop        PlaybackControl = "Stop"
	PlaybackControlStartOver   PlaybackControl = "StartOver"
	PlaybackControlPrevious    PlaybackControl = "Previous"
	PlaybackControlNext        PlaybackControl = "Next"
	PlaybackControlRewind      PlaybackControl = "Rewind"
	PlaybackControlFastForward PlaybackControl = "FastForward"
)

type PressKind

type PressKind uint8
const (
	PressKindUp   PressKind = 0 // untraditionally keyup first so we can "omitempty" the zero value
	PressKindDown PressKind = 1
	PressKindHold PressKind = 2
)

Jump to

Keyboard shortcuts

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