Skip to content
Merged
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
35 changes: 23 additions & 12 deletions nest/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,28 +1526,39 @@ def eta_begin(self):
if 'eta_begin' in self._structure:
return parse_time(self._structure['eta_begin'])

def _set_eta(self, trip_id, eta_begin, eta_end):
if self.num_thermostats == 0:
raise ValueError("ETA can only be set or cancelled when a"
" thermostat is in the structure.")
if trip_id is None:
raise ValueError("trip_id must be not None")

data = {'trip_id': trip_id,
'estimated_arrival_window_begin': eta_begin,
'estimated_arrival_window_end': eta_end}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data = {'trip_id': trip_id,
            'estimated_arrival_window_begin': eta_begin}
if eta_end is not None:
    data[estimated_arrival_window_end] = eta_end

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that estimated_arrival_window_end must be included even if estimated_arrival_window_begin is set to int(0)


self._set('structures', {'eta': data})

def set_eta(self, trip_id, eta_begin, eta_end=None):
"""
Set estimated arrival winow, use same trip_id to update estimation.
Nest may choose ignore inaccurate estimation.
Nest may choose to ignore inaccurate estimation.
See: https://developers.nest.com/documentation/cloud/away-guide
#make_an_eta_write_call
"""
if self.num_thermostats == 0:
raise ValueError("ETA can only be set when Thermostat is in the"
" structure.")
if trip_id is None:
raise ValueError("trip_id must be not None")
if eta_begin is None:
raise ValueError("eta_begin must be not None")
if eta_end is None:
# set default eta window to 1 minute
eta_end = eta_begin + datetime.timedelta(0, 60)
eta_end = eta_begin + datetime.timedelta(minutes=1)

data = {'trip_id': trip_id,
'estimated_arrival_window_begin': eta_begin.isoformat(),
'estimated_arrival_window_end': eta_end.isoformat()}
self._set('structures', {'eta': data})
self._set_eta(trip_id, eta_begin.isoformat(), eta_end.isoformat())

def cancel_eta(self, trip_id):
"""
Cancel estimated arrival winow.
"""
eta_end = datetime.datetime.utcnow()
self._set_eta(trip_id, int(0), eta_end.isoformat())

@property
def wheres(self):
Expand Down