Added lots of services and fixed bug with ID for websocket calls

This commit is contained in:
Sam Lewis
2022-10-13 02:17:36 -04:00
parent 7f9e346d34
commit b99c1e5925
13 changed files with 379 additions and 59 deletions

View File

@@ -0,0 +1,38 @@
package services
import (
"context"
"fmt"
"time"
ws "github.com/saml-dev/gome-assistant/internal/websocket"
"nhooyr.io/websocket"
)
/* Structs */
type InputDatetime struct {
conn *websocket.Conn
ctx context.Context
}
/* Public API */
func (ib InputDatetime) Set(entityId string, value time.Time) {
req := NewBaseServiceRequest(entityId)
req.Domain = "input_datetime"
req.Service = "set_datetime"
req.ServiceData = map[string]any{
"timestamp": fmt.Sprint(value.Unix()),
}
fmt.Println(req)
ws.WriteMessage(req, ib.conn, ib.ctx) // TODO: this ain't working for some reason
}
func (ib InputDatetime) Reload() {
req := NewBaseServiceRequest("")
req.Domain = "input_datetime"
req.Service = "reload"
ws.WriteMessage(req, ib.conn, ib.ctx)
}