mirror of
https://github.com/Xevion/go-ha.git
synced 2025-12-07 18:07:09 -06:00
add climate service
This commit is contained in:
35
internal/services/climate.go
Normal file
35
internal/services/climate.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
ws "saml.dev/gome-assistant/internal/websocket"
|
||||
"saml.dev/gome-assistant/types"
|
||||
)
|
||||
|
||||
/* Structs */
|
||||
|
||||
type Climate struct {
|
||||
conn *ws.WebsocketWriter
|
||||
ctx context.Context
|
||||
}
|
||||
|
||||
/* Public API */
|
||||
|
||||
func (c Climate) SetFanMode(entityId string, fanMode string) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "climate"
|
||||
req.Service = "set_fan_mode"
|
||||
req.ServiceData = map[string]any{"fan_mode": fanMode}
|
||||
|
||||
c.conn.WriteMessage(req, c.ctx)
|
||||
}
|
||||
|
||||
func (c Climate) SetTemperature(entityId string, serviceData types.SetTemperatureRequest) {
|
||||
req := NewBaseServiceRequest(entityId)
|
||||
req.Domain = "climate"
|
||||
req.Service = "set_temperature"
|
||||
req.ServiceData = serviceData.ToJSON()
|
||||
|
||||
c.conn.WriteMessage(req, c.ctx)
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
func BuildService[
|
||||
T AlarmControlPanel |
|
||||
Climate |
|
||||
Cover |
|
||||
Light |
|
||||
HomeAssistant |
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
type Service struct {
|
||||
AlarmControlPanel *services.AlarmControlPanel
|
||||
Climate *services.Climate
|
||||
Cover *services.Cover
|
||||
HomeAssistant *services.HomeAssistant
|
||||
Light *services.Light
|
||||
@@ -31,6 +32,7 @@ type Service struct {
|
||||
func newService(conn *ws.WebsocketWriter, ctx context.Context, httpClient *http.HttpClient) *Service {
|
||||
return &Service{
|
||||
AlarmControlPanel: services.BuildService[services.AlarmControlPanel](conn, ctx),
|
||||
Climate: services.BuildService[services.Climate](conn, ctx),
|
||||
Cover: services.BuildService[services.Cover](conn, ctx),
|
||||
Light: services.BuildService[services.Light](conn, ctx),
|
||||
HomeAssistant: services.BuildService[services.HomeAssistant](conn, ctx),
|
||||
|
||||
@@ -7,3 +7,27 @@ type NotifyRequest struct {
|
||||
Title string
|
||||
Data map[string]any
|
||||
}
|
||||
|
||||
type SetTemperatureRequest struct {
|
||||
Temperature float32
|
||||
TargetTempHigh float32
|
||||
TargetTempLow float32
|
||||
HvacMode string
|
||||
}
|
||||
|
||||
func (r *SetTemperatureRequest) ToJSON() map[string]any {
|
||||
m := map[string]any{}
|
||||
if r.Temperature != 0 {
|
||||
m["temperature"] = r.Temperature
|
||||
}
|
||||
if r.TargetTempHigh != 0 {
|
||||
m["target_temp_high"] = r.TargetTempHigh
|
||||
}
|
||||
if r.TargetTempLow != 0 {
|
||||
m["target_temp_low"] = r.TargetTempLow
|
||||
}
|
||||
if r.HvacMode != "" {
|
||||
m["hvac_mode"] = r.HvacMode
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user