X-Git-Url: https://git.giacomolli.uk/onehouse/blobdiff_plain/9ea825d64a3efaf8679990ea652ffaad0615c24c..b28ae53ae04c41116acb2beae9d5a2128a187c83:/protocol/address.go diff --git a/protocol/address.go b/protocol/address.go index 31d1b45..fbd0d26 100644 --- a/protocol/address.go +++ b/protocol/address.go @@ -11,20 +11,28 @@ const ( // Descriptor identifies retained device metadata. Descriptor Kind = "descriptor" + // Availability identifies retained device reachability. Availability Kind = "availability" + // Reported identifies a retained point value. Reported Kind = "reported" + // Telemetry identifies a non-retained measurement. Telemetry Kind = "telemetry" + // Event identifies a non-retained occurrence. Event Kind = "events" + // Command identifies a non-retained point request. Command Kind = "commands" + // CommandBatch identifies an ordered group of point requests. CommandBatch Kind = "batch" + // Result identifies a command outcome. Result Kind = "results" + // HubStatus identifies retained Zigbee hub diagnostics. HubStatus Kind = "status" ) @@ -91,9 +99,15 @@ func ParseTopic(topic string) (Address, error) { switch { case len(parts) == 6 && parts[2] == "zigbee" && parts[3] == "hubs" && parts[5] == "status": - address = Address{Kind: HubStatus, ID: parts[4]} + address = Address{ + Kind: HubStatus, + ID: parts[4], + } case (len(parts) == 5 || len(parts) == 6) && parts[2] == "devices": - address = Address{Kind: Kind(parts[4]), ID: parts[3]} + address = Address{ + Kind: Kind(parts[4]), + ID: parts[3], + } if len(parts) == 6 { address.Target = parts[5] if address.Kind == Command && address.Target == "$batch" { @@ -127,12 +141,30 @@ type Subscription struct { // house-state input. Telemetry uses QoS 0. Other subscriptions use QoS 1. func CoreSubscriptions() []Subscription { return []Subscription{ - {Filter: Root + "/devices/+/descriptor", QoS: 1}, - {Filter: Root + "/devices/+/availability", QoS: 1}, - {Filter: Root + "/devices/+/reported/+", QoS: 1}, - {Filter: Root + "/devices/+/telemetry/+", QoS: 0}, - {Filter: Root + "/devices/+/events/+", QoS: 1}, - {Filter: Root + "/devices/+/results/+", QoS: 1}, + { + Filter: Root + "/devices/+/descriptor", + QoS: 1, + }, + { + Filter: Root + "/devices/+/availability", + QoS: 1, + }, + { + Filter: Root + "/devices/+/reported/+", + QoS: 1, + }, + { + Filter: Root + "/devices/+/telemetry/+", + QoS: 0, + }, + { + Filter: Root + "/devices/+/events/+", + QoS: 1, + }, + { + Filter: Root + "/devices/+/results/+", + QoS: 1, + }, } } @@ -142,10 +174,16 @@ func CommandSubscription(deviceID string) (Subscription, error) { return Subscription{}, fmt.Errorf("device ID must be a canonical ULID") } - return Subscription{Filter: Root + "/devices/" + deviceID + "/commands/+", QoS: 1}, nil + return Subscription{ + Filter: Root + "/devices/" + deviceID + "/commands/+", + QoS: 1, + }, nil } // HubStatusSubscription returns the filter for all Zigbee hub diagnostics. func HubStatusSubscription() Subscription { - return Subscription{Filter: Root + "/zigbee/hubs/+/status", QoS: 1} + return Subscription{ + Filter: Root + "/zigbee/hubs/+/status", + QoS: 1, + } }