58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
|
package tiko
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"encoding/json"
|
||
|
"net/http"
|
||
|
)
|
||
|
|
||
|
type Property struct {
|
||
|
ID int64 `json:"id"`
|
||
|
Mode struct {
|
||
|
Boost bool `json:"boost"`
|
||
|
Frost bool `json:"frost"`
|
||
|
Absence bool `json:"absence"`
|
||
|
DisableHeating bool `json:"disableHeating"`
|
||
|
} `json:"mode"`
|
||
|
TypeName string `json:"__typename"`
|
||
|
Rooms []Room
|
||
|
}
|
||
|
|
||
|
type PropertyResp struct {
|
||
|
Property Property `json:"property"`
|
||
|
}
|
||
|
|
||
|
func (c *Client) GetProperty(propertyID int64) (*Property, error) {
|
||
|
if err := c.Init(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
// Créer les données de la requête
|
||
|
requestData := map[string]interface{}{
|
||
|
"operationName": "GET_PROPERTY_OVERVIEW_DECENTRALISED",
|
||
|
"variables": map[string]int64{
|
||
|
"id": propertyID,
|
||
|
},
|
||
|
"query": "query GET_PROPERTY_OVERVIEW_DECENTRALISED($id: Int!, $excludeRooms: [Int]) { property(id: $id) { id mode rooms(excludeRooms: $excludeRooms) { id name type color heaters currentTemperatureDegrees targetTemperatureDegrees humidity sensors mode { boost absence frost disableHeating __typename } status { disconnected heaterDisconnected heatingOperating sensorBatteryLow sensorDisconnected temporaryAdjustment heatersRegulated heaterCalibrationState __typename } __typename } __typename } }",
|
||
|
}
|
||
|
|
||
|
// Convertir les données en JSON
|
||
|
requestDataJSON, err := json.Marshal(requestData)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
// Créer la requête HTTP
|
||
|
req, err := http.NewRequest(http.MethodPost, graphqlAPIURL, bytes.NewBuffer(requestDataJSON))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
resp, err := Do[ApiResp[PropertyResp]](c, req)
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return &resp.Data.Property, nil
|
||
|
}
|