mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-06 01:15:10 -06:00
fix bug with newer HA versions by sending int id instead of string add warning to logs when receiving unsuccessful websocket response
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
package services
|
|
|
|
import (
|
|
"context"
|
|
|
|
"saml.dev/gome-assistant/internal"
|
|
ws "saml.dev/gome-assistant/internal/websocket"
|
|
)
|
|
|
|
func BuildService[
|
|
T AlarmControlPanel |
|
|
Climate |
|
|
Cover |
|
|
Light |
|
|
HomeAssistant |
|
|
Lock |
|
|
MediaPlayer |
|
|
Switch |
|
|
InputBoolean |
|
|
InputButton |
|
|
InputDatetime |
|
|
InputText |
|
|
InputNumber |
|
|
Notify |
|
|
Number |
|
|
Scene |
|
|
TTS |
|
|
Vacuum,
|
|
](conn *ws.WebsocketWriter, ctx context.Context) *T {
|
|
return &T{conn: conn, ctx: ctx}
|
|
}
|
|
|
|
type BaseServiceRequest struct {
|
|
Id int64 `json:"id"`
|
|
RequestType string `json:"type"` // hardcoded "call_service"
|
|
Domain string `json:"domain"`
|
|
Service string `json:"service"`
|
|
ServiceData map[string]any `json:"service_data,omitempty"`
|
|
Target struct {
|
|
EntityId string `json:"entity_id,omitempty"`
|
|
} `json:"target,omitempty"`
|
|
}
|
|
|
|
func NewBaseServiceRequest(entityId string) BaseServiceRequest {
|
|
id := internal.GetId()
|
|
bsr := BaseServiceRequest{
|
|
Id: id,
|
|
RequestType: "call_service",
|
|
}
|
|
if entityId != "" {
|
|
bsr.Target.EntityId = entityId
|
|
}
|
|
return bsr
|
|
}
|