feat(agent): SendDisplayState im MQTT-Publisher + Interface

This commit is contained in:
Jesko Anschütz 2026-03-26 23:07:31 +01:00
parent 4ef16048ad
commit bcc50635e5
2 changed files with 21 additions and 0 deletions

View file

@ -91,6 +91,7 @@ type statusSender interface {
type mqttSender interface { type mqttSender interface {
SendHeartbeat(status, connectivity string, ts time.Time) error SendHeartbeat(status, connectivity string, ts time.Time) error
SendDisplayState(screenSlug, state string) error
Close() Close()
} }

View file

@ -78,6 +78,26 @@ func (p *Publisher) SendHeartbeat(status, connectivity string, ts time.Time) err
return token.Error() return token.Error()
} }
// SendDisplayState publiziert den aktuellen Display-Zustand auf dem display-state-Topic.
// QoS 0, nicht retained — Informationszweck/Monitoring.
func (p *Publisher) SendDisplayState(screenSlug, state string) error {
type dsPayload struct {
DisplayState string `json:"display_state"`
Timestamp string `json:"ts"`
}
data, err := json.Marshal(dsPayload{
DisplayState: state,
Timestamp: time.Now().UTC().Format(time.RFC3339),
})
if err != nil {
return err
}
topic := "signage/screen/" + screenSlug + "/display-state"
token := p.client.Publish(topic, 0, false, data)
token.WaitTimeout(3 * time.Second)
return token.Error()
}
// Close disconnects from the broker gracefully. // Close disconnects from the broker gracefully.
func (p *Publisher) Close() { func (p *Publisher) Close() {
p.client.Disconnect(250) p.client.Disconnect(250)