mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-05 23:15:07 -06:00
60 lines
1.1 KiB
Go
60 lines
1.1 KiB
Go
package services
|
|
|
|
import (
|
|
"github.com/Xevion/go-ha/internal"
|
|
"github.com/Xevion/go-ha/internal/connect"
|
|
)
|
|
|
|
func BuildService[
|
|
T AdaptiveLighting |
|
|
AlarmControlPanel |
|
|
Climate |
|
|
Cover |
|
|
Light |
|
|
HomeAssistant |
|
|
Lock |
|
|
MediaPlayer |
|
|
Switch |
|
|
InputBoolean |
|
|
InputButton |
|
|
InputDatetime |
|
|
InputText |
|
|
InputNumber |
|
|
Event |
|
|
Notify |
|
|
Number |
|
|
Scene |
|
|
Script |
|
|
TTS |
|
|
Timer |
|
|
Vacuum |
|
|
ZWaveJS,
|
|
](conn *connect.HAConnection) *T {
|
|
return &T{conn: conn}
|
|
}
|
|
|
|
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.NextId()
|
|
request := BaseServiceRequest{
|
|
Id: id,
|
|
RequestType: "call_service",
|
|
}
|
|
|
|
if entityId != "" {
|
|
request.Target.EntityId = entityId
|
|
}
|
|
|
|
return request
|
|
}
|