From 87787b5b3c72a0fbcc8c01903c769da696925e76 Mon Sep 17 00:00:00 2001 From: Daniel Gonzalez Date: Mon, 14 Feb 2022 01:01:06 +0100 Subject: [PATCH] feat: Add interface methods to Device and MobileDevice object --- device.go | 12 ++++++++++++ home.go | 1 + mobile_device.go | 13 +++++++++++++ models.go | 1 + 4 files changed, 27 insertions(+) create mode 100644 device.go create mode 100644 mobile_device.go diff --git a/device.go b/device.go new file mode 100644 index 0000000..5252517 --- /dev/null +++ b/device.go @@ -0,0 +1,12 @@ +package gotado + +import "context" + +// GetTemperatureOffset returns the temperature offsets of the device +func (d *Device) GetTemperatureOffset(ctx context.Context) (*TemperatureOffset, error) { + temperatureOffset := &TemperatureOffset{} + if err := d.client.get(ctx, apiURL("devices/%s/temperatureOffset", d.SerialNo), &temperatureOffset); err != nil { + return nil, err + } + return temperatureOffset, nil +} diff --git a/home.go b/home.go index d0b8809..256da25 100644 --- a/home.go +++ b/home.go @@ -77,6 +77,7 @@ func (h *Home) GetMobileDevices(ctx context.Context) ([]*MobileDevice, error) { } for _, mobileDevice := range mobileDevices { mobileDevice.client = h.client + mobileDevice.home = h } return mobileDevices, nil } diff --git a/mobile_device.go b/mobile_device.go new file mode 100644 index 0000000..aff3ee3 --- /dev/null +++ b/mobile_device.go @@ -0,0 +1,13 @@ +package gotado + +import "context" + +// SetMobileDeviceSettings updates the mobile device with the given settings +func (md *MobileDevice) SetSettings(ctx context.Context, settings MobileDeviceSettings) error { + return md.client.put(ctx, apiURL("homes/%d/mobileDevices/%d/settings", md.home.ID, md.ID), settings) +} + +// DeleteMobileDevice deletes the mobile device +func (md *MobileDevice) Delete(ctx context.Context) error { + return md.client.delete(ctx, apiURL("homes/%d/mobileDevices/%d", md.home.ID, md.ID)) +} diff --git a/models.go b/models.go index 3ea7879..14d6eae 100644 --- a/models.go +++ b/models.go @@ -445,6 +445,7 @@ type Installation struct { // MobileDevice represents a mobile device with the tado° app installed type MobileDevice struct { client *client + home *Home Name string `json:"name"` ID int32 `json:"id"` Settings MobileDeviceSettings `json:"settings"`