Skip to content

Commit

Permalink
feat: Add support to enable/disable open window detection
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzolino committed Apr 29, 2023
1 parent d0df97d commit f3d4598
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
7 changes: 7 additions & 0 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,13 @@ type EarlyStart struct {
Enabled bool `json:"enabled"`
}

// OpenWindowDetection controls whether open window detection is enabled or not,
// and how long to shut off the heating after a window has been opened.
type OpenWindowDetection struct {
Enabled bool `json:"enabled"`
TimeoutInSeconds int32 `json:"timeoutInSeconds,omitempty"`
}

// Weather holds weather information from the home's location
type Weather struct {
SolarIntensity *PercentageMeasurement `json:"solarIntensity"`
Expand Down
25 changes: 25 additions & 0 deletions zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,31 @@ func (z *Zone) CloseWindow(ctx context.Context) error {
return z.client.delete(ctx, apiURL("homes/%d/zones/%d/state/openWindow", z.home.ID, z.ID))
}

// EnableOpenWindowDetection enable open window detection with the given heating timeout
// duration in seconds after an open window has been detected.
func (z *Zone) EnableOpenWindowDetection(ctx context.Context, timeout int32) error {
return z.client.put(ctx, apiURL("homes/%d/zones/%d/openWindowDetection", z.home.ID, z.ID), OpenWindowDetection{Enabled: true, TimeoutInSeconds: timeout})
}

// DisableOpenWindowDetection disable open window detection.
func (z *Zone) DisableOpenWindowDetection(ctx context.Context) error {
return z.client.put(ctx, apiURL("homes/%d/zones/%d/openWindowDetection", z.home.ID, z.ID), OpenWindowDetection{Enabled: false})
}

// GetOpenWindowDetection returns the current open window detection settings.
func (z *Zone) GetOpenWindowDetection(ctx context.Context) (*OpenWindowDetection, error) {
// Get fresh zone object to ensure that the returned settings are up to date.
zone, err := z.home.GetZone(ctx, z.Name)
if err != nil {
return nil, err
}

return &OpenWindowDetection{
Enabled: zone.OpenWindowDetection.Enabled,
TimeoutInSeconds: zone.OpenWindowDetection.TimeoutInSeconds,
}, nil
}

// GetEarlyStart checks if early start is enabled in the zone.
func (z *Zone) GetEarlyStart(ctx context.Context) (bool, error) {
earlyStart := &EarlyStart{}
Expand Down

0 comments on commit f3d4598

Please sign in to comment.