github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/aagent/watchers/homekitwatcher/state_notification.go (about) 1 // Copyright (c) 2020-2021, R.I. Pienaar and the Choria Project contributors 2 // 3 // SPDX-License-Identifier: Apache-2.0 4 5 package homekitwatcher 6 7 import ( 8 "encoding/json" 9 "fmt" 10 11 cloudevents "github.com/cloudevents/sdk-go/v2" 12 13 "github.com/choria-io/go-choria/aagent/watchers/event" 14 ) 15 16 // StateNotification describes the current state of the watcher 17 // described by io.choria.machine.watcher.homekit.v1.state 18 type StateNotification struct { 19 event.Event 20 21 Path string `json:"path"` 22 PreviousOutcome string `json:"previous_outcome"` 23 } 24 25 // JSON creates a JSON representation of the notification 26 func (s *StateNotification) JSON() ([]byte, error) { 27 return json.Marshal(s.CloudEvent()) 28 } 29 30 // CloudEvent creates a CloudEvent from the state notification 31 func (s *StateNotification) CloudEvent() cloudevents.Event { 32 return s.Event.CloudEvent(s) 33 } 34 35 // String is a string representation of the notification suitable for printing 36 func (s *StateNotification) String() string { 37 return fmt.Sprintf("%s %s#%s previous: %s", s.Identity, s.Machine, s.Name, s.PreviousOutcome) 38 }