mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 01:15:10 -06:00
28 lines
625 B
Go
28 lines
625 B
Go
package services
|
|
|
|
import (
|
|
ws "github.com/Xevion/go-ha/internal/websocket"
|
|
"github.com/Xevion/go-ha/types"
|
|
)
|
|
|
|
type Notify struct {
|
|
conn *ws.WebsocketWriter
|
|
}
|
|
|
|
// Notify sends a notification. Takes a types.NotifyRequest.
|
|
func (ha *Notify) Notify(reqData types.NotifyRequest) error {
|
|
req := NewBaseServiceRequest("")
|
|
req.Domain = "notify"
|
|
req.Service = reqData.ServiceName
|
|
|
|
serviceData := map[string]any{}
|
|
serviceData["message"] = reqData.Message
|
|
serviceData["title"] = reqData.Title
|
|
if reqData.Data != nil {
|
|
serviceData["data"] = reqData.Data
|
|
}
|
|
|
|
req.ServiceData = serviceData
|
|
return ha.conn.WriteMessage(req)
|
|
}
|