Documentation
¶
Overview ¶
Package zigbee speaks Zigbee2MQTT's MQTT API: its topics, device names, availability, bridge messages and the device list with each device's features ("exposes"). The Zigbee nodes and the discovery service build on it (docs/design/zigbee.md).
Index ¶
- Constants
- func AvailabilityTopic(base, device string) string
- func BridgeTopic(base, sub string) string
- func DeviceTopic(base, device string) string
- func GetTopic(base, device string) string
- func ParseAvailability(payload []byte) (online, ok bool)
- func SetTopic(base, device string) string
- func ValidDeviceName(name string) error
- type BridgeInfo
- type BridgeStatus
- type Device
- type DeviceStatus
- type Feature
- type Manager
- type Network
Constants ¶
const ( AccessPublished = 1 AccessSet = 2 AccessGet = 4 )
Access bits of a feature.
const MaxDeviceNameLength = 256
MaxDeviceNameLength bounds a device's friendly name.
const (
// MaxPermitJoinSeconds is Zigbee2MQTT's longest permit-join window.
MaxPermitJoinSeconds = 254
)
Bounds of what a watcher keeps.
Variables ¶
This section is empty.
Functions ¶
func AvailabilityTopic ¶
AvailabilityTopic is where Zigbee2MQTT publishes whether a device is online.
func BridgeTopic ¶
BridgeTopic is a topic under the bridge (state, info, devices, request/…).
func DeviceTopic ¶
DeviceTopic is where Zigbee2MQTT publishes a device's state.
func ParseAvailability ¶
ParseAvailability reads an availability payload: {"state":"online"} or, in Zigbee2MQTT's legacy format, the plain word.
func ValidDeviceName ¶
ValidDeviceName checks a device (or group) friendly name as a topic part: not empty, no wildcards, no empty level, not the bridge and not ending in a command suffix (set, get, availability).
Types ¶
type BridgeInfo ¶
type BridgeInfo struct {
Version string `json:"version"`
PermitJoin bool `json:"permitJoin"`
// PermitJoinEnd is when joining closes, in Unix milliseconds
// (Zigbee2MQTT 2.x), if it says.
PermitJoinEnd *int64 `json:"permitJoinEnd,omitempty"`
Coordinator string `json:"coordinator,omitempty"`
}
BridgeInfo is what bridge/info says that the editor shows.
func ParseBridgeInfo ¶
func ParseBridgeInfo(payload []byte) (BridgeInfo, error)
ParseBridgeInfo reads bridge/info.
type BridgeStatus ¶
type BridgeStatus struct {
Online bool `json:"online"`
Info BridgeInfo `json:"info"`
}
BridgeStatus is the bridge as the editor shows it.
type Device ¶
type Device struct {
FriendlyName string `json:"friendlyName"`
IEEE string `json:"ieee"`
Type string `json:"type"` // Router or EndDevice
PowerSource string `json:"powerSource,omitempty"`
Model string `json:"model,omitempty"`
Vendor string `json:"vendor,omitempty"`
Description string `json:"description,omitempty"`
Supported bool `json:"supported"`
Disabled bool `json:"disabled,omitempty"`
Features []Feature `json:"features"`
}
Device is a device of the network (the coordinator left out).
func ParseDevices ¶
ParseDevices reads bridge/devices: every device but the coordinator, its features flattened (a light's or switch's features are listed as its own; composite features keep their property, without sub-features).
func (Device) Properties ¶
Properties are the properties the device publishes, in its order.
func (Device) SettableProperties ¶
SettableProperties are the properties the device can be set, in its order.
type DeviceStatus ¶
type DeviceStatus struct {
Device
State map[string]any `json:"state,omitempty"`
Online *bool `json:"online,omitempty"`
LastSeen *time.Time `json:"lastSeen,omitempty"`
}
DeviceStatus is a device with what it last reported.
type Feature ¶
type Feature struct {
Property string `json:"property"`
Name string `json:"name"`
Type string `json:"type"` // binary, numeric, enum, text, …
Access int `json:"access"`
Unit string `json:"unit,omitempty"`
Min *float64 `json:"min,omitempty"`
Max *float64 `json:"max,omitempty"`
Values []string `json:"values,omitempty"`
ValueOn any `json:"valueOn,omitempty"`
ValueOff any `json:"valueOff,omitempty"`
ValueToggle any `json:"valueToggle,omitempty"`
Description string `json:"description,omitempty"`
}
Feature is one property of a device: what it publishes and, per its access bits, whether it can be set or read on request.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager watches each broker connection's Zigbee2MQTT network (<base>/#, on its own pooled connection, ADR-0025): the bridge's state and info, the device list, and each device's last state and availability. It serves device discovery in the editor and the state the expressions read.
var Default *Manager
Default is the process-wide manager (main starts it); expressions read device states from it. Nil when not started.
func NewManager ¶
NewManager creates a manager for the connections of store.
func (*Manager) Connections ¶
Connections returns the names of the watched connections.
func (*Manager) DeviceState ¶
DeviceState returns the last state device reported on the connection name (a copy).
func (*Manager) PermitJoin ¶
PermitJoin opens (seconds > 0) or closes (0) the network to new devices for up to MaxPermitJoinSeconds. It is the administrator's: no node or agent tool calls it.
type Network ¶
type Network struct {
Connection string `json:"connection"`
BaseTopic string `json:"baseTopic"`
Connected bool `json:"connected"` // to the broker
Bridge BridgeStatus `json:"bridge"`
Devices []DeviceStatus `json:"devices"`
}
Network is a connection's Zigbee network.