Documentation ¶
Index ¶
- type AttrBool
- type AttrBuilder
- func (a AttrBuilder) Bool(value bool) *AttrBool
- func (a AttrBuilder) Color(r, g, b uint8) *AttrColor
- func (a AttrBuilder) Event() *AttrEvent
- func (a AttrBuilder) Float(value float64) *AttrFloat
- func (a AttrBuilder) Int(value int64) *AttrInt
- func (a AttrBuilder) PlaybackControl(control PlaybackControl) *AttrPlaybackControl
- func (a AttrBuilder) PressUp(key evdevcodes.KeyOrButton) *AttrPress
- func (a AttrBuilder) String(value string) *AttrString
- type AttrColor
- type AttrEvent
- type AttrFloat
- type AttrInt
- type AttrOrientation
- type AttrPlaybackControl
- type AttrPress
- type AttrString
- type Attribute
- type Attributes
- type AttrsCtx
- type BatteryType
- type Device
- type DeviceState
- type PlaybackControl
- type PressKind
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AttrBuilder ¶
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) CopyIfDifferent ¶
func (*AttrColor) LastChange ¶
type AttrEvent ¶
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 ¶
type AttrOrientation ¶
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) HasKey ¶
func (a *AttrPress) HasKey(key evdevcodes.KeyOrButton) bool
func (*AttrPress) LastChange ¶
type AttrString ¶
func (*AttrString) CopyIfDifferent ¶
func (a *AttrString) CopyIfDifferent(dest **AttrString)
func (*AttrString) LastChange ¶
func (a *AttrString) LastChange() time.Time
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
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" )