Files
ha-n95-local-control/internal/ha/command.go
T

38 lines
888 B
Go

package ha
import (
"git.i3omb.com/gronod/ha-n95-local-control/internal/robot"
)
// Command maps one MQTT message on a per-robot command topic to a
// robot.Command. Payloads are used verbatim — no trimming.
func Command(suffix string, payload []byte) robot.Command {
s := string(payload)
switch suffix {
case "command":
switch s {
case "start", "stop", "return_to_base", "clean_spot", "locate":
return robot.Command{Name: s}
default:
return robot.Command{Reject: s}
}
case "set_fan_speed":
switch s {
case "standard", "strong":
return robot.Command{
Name: "set_fan_speed",
Args: map[string]string{"speed": s},
}
default:
return robot.Command{Reject: s}
}
case "send_command":
return robot.Command{
Name: "send_command",
Payload: append([]byte(nil), payload...),
}
default:
return robot.Command{Reject: "unsupported"}
}
}