listeners working, sunrise/sunset working with string offset

This commit is contained in:
Sam Lewis
2022-10-16 22:23:46 -04:00
parent 8b888a2d89
commit 6ca78e88dd
10 changed files with 317 additions and 140 deletions

View File

@@ -1,8 +1,23 @@
package internal
import (
"log"
"time"
"github.com/golang-module/carbon"
)
var id int64 = 0
func GetId() int64 {
id += 1
return id
}
func ParseTime[T ~string](s T) carbon.Carbon {
t, err := time.Parse("15:04", string(s))
if err != nil {
log.Fatalf("Failed to parse time string \"%s\"; format must be HH:MM.", s)
}
return carbon.Now().StartOfDay().SetHour(t.Hour()).SetMinute(t.Minute())
}

View File

@@ -3,7 +3,6 @@ package services
import (
"context"
"fmt"
"log"
"github.com/gorilla/websocket"
"github.com/saml-dev/gome-assistant/internal"
@@ -36,7 +35,6 @@ type BaseServiceRequest struct {
func NewBaseServiceRequest(entityId string) BaseServiceRequest {
id := internal.GetId()
log.Default().Println("service id", id)
bsr := BaseServiceRequest{
Id: fmt.Sprint(id),
RequestType: "call_service",

View File

@@ -20,7 +20,6 @@ type ChanMsg struct {
func ListenWebsocket(conn *websocket.Conn, ctx context.Context, c chan ChanMsg) {
for {
// log.Default().Println("reading message")
bytes, _ := ReadMessage(conn, ctx)
base := BaseMessage{}
json.Unmarshal(bytes, &base)