mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-09 14:07:24 -06:00
listeners working, sunrise/sunset working with string offset
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user