Skip to content

Commit

Permalink
feat: add function to get zone capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzolino committed Jul 4, 2021
1 parent 5f249fa commit e5f6900
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tado.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,28 @@ type ZoneOpenWindowDetection struct {
TimeoutInSeconds int32 `json:"timeoutInSeconds"`
}

// ZoneCapabilitiesstores the capabilities of a zone, such as the supported
// min/max temperatures
type ZoneCapabilities struct {
Type string `json:"type"`
CanSetTemperature *bool `json:"canSetTemperature,omitempty"`
Temperatures *ZoneCapabilitiesTemperatures `json:"temperatures,omitempty"`
}

// ZoneCapabilitiesTemperatures holds the temperature related capabilities of a zone
type ZoneCapabilitiesTemperatures struct {
Celsius *ZoneCapabilitiesTemperatureValues `json:"celsius,omitempty"`
Fahrenheit *ZoneCapabilitiesTemperatureValues `json:"fahrenheit,omitempty"`
}

// ZoneCapabilitiesTemperatureValues holds the numeric values of temperature
// related capabilities of a zone
type ZoneCapabilitiesTemperatureValues struct {
Min int32 `json:"min"`
Max int32 `json:"max"`
Step float32 `json:"step"`
}

// ZoneState represents the state of a tado° zone
type ZoneState struct {
TadoMode string `json:"tadoMode"`
Expand Down Expand Up @@ -386,6 +408,26 @@ func GetZoneState(client *Client, userHome *UserHome, zone *Zone) (*ZoneState, e
return zoneState, nil
}

// GetZoneCapabilities returns the capabilities of the given zone
func GetZoneCapabilities(client *Client, userHome *UserHome, zone *Zone) (*ZoneCapabilities, error) {
resp, err := client.Request(http.MethodGet, apiURL("homes/%d/zones/%d/capabilities", userHome.ID, zone.ID), nil)
if err != nil {
return nil, err
}
defer resp.Body.Close()

if err := isError(resp); err != nil {
return nil, fmt.Errorf("tado° API error: %w", err)
}

zoneCapabilities := &ZoneCapabilities{}
if err := json.NewDecoder(resp.Body).Decode(&zoneCapabilities); err != nil {
return nil, fmt.Errorf("unable to decode tado° API response: %w", err)
}

return zoneCapabilities, nil
}

// setZoneOverlay sets a zone overlay setting
func setZoneOverlay(client *Client, userHome *UserHome, zone *Zone, overlay ZoneOverlay) (*ZoneOverlay, error) {
data, err := json.Marshal(overlay)
Expand Down

0 comments on commit e5f6900

Please sign in to comment.