67 lines
2.4 KiB
Go
67 lines
2.4 KiB
Go
// Package ha produces the Home Assistant MQTT discovery document and maps
|
|
// inbound MQTT command payloads to robot commands.
|
|
package ha
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"git.i3omb.com/gronod/ha-n95-local-control/internal/config"
|
|
)
|
|
|
|
// discoveryDoc is a struct so the compact JSON key order stays fixed.
|
|
type discoveryDoc struct {
|
|
Name string `json:"name"`
|
|
UniqueID string `json:"unique_id"`
|
|
CommandTopic string `json:"command_topic"`
|
|
SetFanSpeedTopic string `json:"set_fan_speed_topic"`
|
|
SendCommandTopic string `json:"send_command_topic"`
|
|
StateTopic string `json:"state_topic"`
|
|
JSONAttributesTopic string `json:"json_attributes_topic"`
|
|
AvailabilityTopic string `json:"availability_topic"`
|
|
PayloadAvailable string `json:"payload_available"`
|
|
PayloadNotAvailable string `json:"payload_not_available"`
|
|
FanSpeedList []string `json:"fan_speed_list"`
|
|
SupportedFeatures []string `json:"supported_features"`
|
|
Device deviceDiscovery `json:"device"`
|
|
}
|
|
|
|
type deviceDiscovery struct {
|
|
Identifiers []string `json:"identifiers"`
|
|
Manufacturer string `json:"manufacturer"`
|
|
Model string `json:"model"`
|
|
SerialNumber string `json:"serial_number"`
|
|
}
|
|
|
|
func DiscoveryTopic(cfg config.Config, serial string) string {
|
|
return cfg.HADiscoveryPrefix + "/vacuum/ecovacs_" + serial + "/config"
|
|
}
|
|
|
|
func Discovery(cfg config.Config, serial string) []byte {
|
|
root := cfg.MQTTBase + "/" + serial
|
|
doc := discoveryDoc{
|
|
Name: "Deebot N95",
|
|
UniqueID: "ecovacs_" + serial,
|
|
CommandTopic: root + "/command",
|
|
SetFanSpeedTopic: root + "/set_fan_speed",
|
|
SendCommandTopic: root + "/send_command",
|
|
StateTopic: root + "/state",
|
|
JSONAttributesTopic: root + "/json_attributes",
|
|
AvailabilityTopic: root + "/availability",
|
|
PayloadAvailable: "online",
|
|
PayloadNotAvailable: "offline",
|
|
FanSpeedList: []string{"standard", "strong"},
|
|
SupportedFeatures: []string{
|
|
"start", "stop", "return_home", "status", "locate",
|
|
"clean_spot", "fan_speed", "send_command",
|
|
},
|
|
Device: deviceDiscovery{
|
|
Identifiers: []string{serial},
|
|
Manufacturer: "Ecovacs",
|
|
Model: "Deebot N95 (wukong/155)",
|
|
SerialNumber: serial,
|
|
},
|
|
}
|
|
b, _ := json.Marshal(doc)
|
|
return b
|
|
}
|