@@ -1526,28 +1526,39 @@ def eta_begin(self):
1526
1526
if 'eta_begin' in self ._structure :
1527
1527
return parse_time (self ._structure ['eta_begin' ])
1528
1528
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
+
1529
1542
def set_eta (self , trip_id , eta_begin , eta_end = None ):
1530
1543
"""
1531
1544
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.
1533
1546
See: https://developers.nest.com/documentation/cloud/away-guide
1534
1547
#make_an_eta_write_call
1535
1548
"""
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" )
1541
1549
if eta_begin is None :
1542
1550
raise ValueError ("eta_begin must be not None" )
1543
1551
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 )
1546
1553
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 ())
1551
1562
1552
1563
@property
1553
1564
def wheres (self ):
0 commit comments