Skip to content

Commit 9e00fe2

Browse files
schmittxawarecan
authored andcommitted
Allow ability to cancel ETA (#157)
* Allow ability to cancel ETA * Clean up format
1 parent 6b49b7f commit 9e00fe2

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

nest/nest.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,28 +1526,39 @@ def eta_begin(self):
15261526
if 'eta_begin' in self._structure:
15271527
return parse_time(self._structure['eta_begin'])
15281528

1529+
def _set_eta(self, trip_id, eta_begin, eta_end):
1530+
if self.num_thermostats == 0:
1531+
raise ValueError("ETA can only be set or cancelled when a"
1532+
" thermostat is in the structure.")
1533+
if trip_id is None:
1534+
raise ValueError("trip_id must be not None")
1535+
1536+
data = {'trip_id': trip_id,
1537+
'estimated_arrival_window_begin': eta_begin,
1538+
'estimated_arrival_window_end': eta_end}
1539+
1540+
self._set('structures', {'eta': data})
1541+
15291542
def set_eta(self, trip_id, eta_begin, eta_end=None):
15301543
"""
15311544
Set estimated arrival winow, use same trip_id to update estimation.
1532-
Nest may choose ignore inaccurate estimation.
1545+
Nest may choose to ignore inaccurate estimation.
15331546
See: https://developers.nest.com/documentation/cloud/away-guide
15341547
#make_an_eta_write_call
15351548
"""
1536-
if self.num_thermostats == 0:
1537-
raise ValueError("ETA can only be set when Thermostat is in the"
1538-
" structure.")
1539-
if trip_id is None:
1540-
raise ValueError("trip_id must be not None")
15411549
if eta_begin is None:
15421550
raise ValueError("eta_begin must be not None")
15431551
if eta_end is None:
1544-
# set default eta window to 1 minute
1545-
eta_end = eta_begin + datetime.timedelta(0, 60)
1552+
eta_end = eta_begin + datetime.timedelta(minutes=1)
15461553

1547-
data = {'trip_id': trip_id,
1548-
'estimated_arrival_window_begin': eta_begin.isoformat(),
1549-
'estimated_arrival_window_end': eta_end.isoformat()}
1550-
self._set('structures', {'eta': data})
1554+
self._set_eta(trip_id, eta_begin.isoformat(), eta_end.isoformat())
1555+
1556+
def cancel_eta(self, trip_id):
1557+
"""
1558+
Cancel estimated arrival winow.
1559+
"""
1560+
eta_end = datetime.datetime.utcnow()
1561+
self._set_eta(trip_id, int(0), eta_end.isoformat())
15511562

15521563
@property
15531564
def wheres(self):

0 commit comments

Comments
 (0)