Skip to content

Commit

Permalink
Add SelectionOptions type and refactor GetThermostat to use them (#15)
Browse files Browse the repository at this point in the history
Allows granularly controlling the contents of the [Selection](https://www.shared.ecobee.com/home/developer/api/documentation/v1/objects/Selection.shtml) parameter to GetThermostats.
  • Loading branch information
cvvs authored Jun 29, 2024
1 parent b622870 commit 212aacd
Show file tree
Hide file tree
Showing 2 changed files with 141 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ecobee/functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ func (c *Client) UpdateThermostat(utr UpdateThermostatRequest) error {
return fmt.Errorf("API error: %s", s.Status.Message)
}

func (c *Client) GetThermostat(thermostatID string) (*Thermostat, error) {
// TODO: Consider factoring the generation of Selection out into
// something else to make it more convenient to toggle the IncludeX
// flags?
func (c *Client) GetThermostat(thermostatID string, opts ...SelectionOption) (*Thermostat, error) {
s := Selection{
SelectionType: "thermostats",
SelectionMatch: thermostatID,
Expand All @@ -82,6 +79,11 @@ func (c *Client) GetThermostat(thermostatID string) (*Thermostat, error) {
IncludeSensors: true,
IncludeWeather: false,
}

for _, o := range opts {
o(s)
}

thermostats, err := c.GetThermostats(s)
if err != nil {
return nil, err
Expand Down
135 changes: 135 additions & 0 deletions ecobee/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
package ecobee

type SelectionOption func(s Selection)

func WithIncludeAlerts(value bool) SelectionOption {
return func(s Selection) {
s.IncludeAlerts = value
}
}

func WithIncludeAudio(value bool) SelectionOption {
return func(s Selection) {
s.IncludeAudio = value
}
}

func WithIncludeDevice(value bool) SelectionOption {
return func(s Selection) {
s.IncludeDevice = value
}
}

func WithIncludeElectricity(value bool) SelectionOption {
return func(s Selection) {
s.IncludeElectricity = value
}
}

func WithIncludeEquipmentStatus(value bool) SelectionOption {
return func(s Selection) {
s.IncludeElectricity = value
}
}

func WithIncludeEvents(value bool) SelectionOption {
return func(s Selection) {
s.IncludeEvents = value
}
}

func WithIncludeExtendedRuntime(value bool) SelectionOption {
return func(s Selection) {
s.IncludeExtendedRuntime = value
}
}

func WithIncludeHouseDetails(value bool) SelectionOption {
return func(s Selection) {
s.IncludeHouseDetails = value
}
}

func WithIncludeLocation(value bool) SelectionOption {
return func(s Selection) {
s.IncludeLocation = value
}
}

func WithIncludeManagement(value bool) SelectionOption {
return func(s Selection) {
s.IncludeManagement = value
}
}

func WithIncludeNotificationSettings(value bool) SelectionOption {
return func(s Selection) {
s.IncludeManagement = value
}
}

func WithIncludeOemCfg(value bool) SelectionOption {
return func(s Selection) {
s.IncludeOemCfg = value
}
}

func WithIncludePrivacy(value bool) SelectionOption {
return func(s Selection) {
s.IncludePrivacy = value
}
}

func WithIncludeProgram(value bool) SelectionOption {
return func(s Selection) {
s.IncludeProgram = value
}
}

func WithIncludeRuntime(value bool) SelectionOption {
return func(s Selection) {
s.IncludeRuntime = value
}
}

func WithIncludeSecuritySettings(value bool) SelectionOption {
return func(s Selection) {
s.IncludeSecuritySettings = value
}
}

func WithIncludeSensors(value bool) SelectionOption {
return func(s Selection) {
s.IncludeSensors = value
}
}

func WithIncludeSettings(value bool) SelectionOption {
return func(s Selection) {
s.IncludeSettings = value
}
}

func WithIncludeTechnician(value bool) SelectionOption {
return func(s Selection) {
s.IncludeSettings = value
}
}

func WithIncludeUtility(value bool) SelectionOption {
return func(s Selection) {
s.IncludeUtility = value
}
}

func WithIncludeVersion(value bool) SelectionOption {
return func(s Selection) {
s.IncludeVersion = value
}
}

func WithIncludeWeather(value bool) SelectionOption {
return func(s Selection) {
s.IncludeWeather = value
}
}

0 comments on commit 212aacd

Please sign in to comment.