Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SelectionOptions type and refactor GetThermostat to use them #15

Merged
merged 4 commits into from
Jun 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}