feat(mqtt): SendDisplayCommand mit retained QoS 1

This commit is contained in:
Jesko Anschütz 2026-03-26 23:05:20 +01:00
parent c359757e31
commit 0d51d951a2

View file

@ -95,6 +95,22 @@ func (n *Notifier) RequestScreenshot(screenSlug string) {
token.WaitTimeout(3 * time.Second)
}
// SendDisplayCommand publiziert einen Display-Befehl (display_on/display_off)
// auf das Command-Topic des Screens. Retained + QoS 1, damit der Agent den
// letzten Sollzustand auch nach einem Reconnect erhält.
func (n *Notifier) SendDisplayCommand(screenSlug, action string) error {
if n.client == nil {
return nil
}
topic := fmt.Sprintf("signage/screen/%s/command", screenSlug)
payload := []byte(fmt.Sprintf(`{"action":%q}`, action))
token := n.client.Publish(topic, 1, true, payload)
if !token.WaitTimeout(5 * time.Second) {
return fmt.Errorf("mqtt publish display command: timeout")
}
return token.Error()
}
func (n *Notifier) publish(screenSlug string) {
topic := Topic(screenSlug)
payload := []byte(fmt.Sprintf(`{"ts":%d}`, time.Now().UnixMilli()))