Skip to content

Commit

Permalink
feat: Allow controling mobile device settings
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzolino committed Jul 14, 2021
1 parent 20fe381 commit 7336d47
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tado.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,29 @@ func DeleteMobileDevice(client *Client, userHome *UserHome, mobileDevice *Mobile
return nil
}

// SetMobileDeviceSettings updates the given mobile device with the given settings
func SetMobileDeviceSettings(client *Client, userHome *UserHome, mobileDevice *MobileDevice, settings MobileDeviceSettings) error {
data, err := json.Marshal(settings)
if err != nil {
return fmt.Errorf("unable to marshal mobile device settings: %w", err)
}
req, err := http.NewRequest(http.MethodPut, apiURL("homes/%d/mobileDevices/%d/settings", userHome.ID, mobileDevice.ID), bytes.NewReader(data))
if err != nil {
return fmt.Errorf("unable to create http request: %w", err)
}
req.Header.Set("Content-Type", "application/json;charset=utf-8")
resp, err := client.Do(req)
if err != nil {
return err
}

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

return nil
}

// GetUsers lists all users and their mobile devices linked to the given home
func GetUsers(client *Client, userHome *UserHome) ([]*User, error) {
resp, err := client.Request(http.MethodGet, apiURL("homes/%d/users", userHome.ID), nil)
Expand Down

0 comments on commit 7336d47

Please sign in to comment.