@@ -191,7 +191,7 @@ def updateAllDetails(self, session: requests.Session):
191191 try :
192192 self .updateBehaviorStats (session )
193193 except Exception as e :
194- LOGGER .debug (f"Could not update behavior stats for Pet { self .name } . This may be an older collar model .\n { e } " )
194+ LOGGER .warning (f"Could not update behavior stats for Pet { self .name } .\n { e } " )
195195 # Behavior stats may not be available for older collars
196196 pass
197197
@@ -200,8 +200,20 @@ def updateBehaviorStats(self, sessionId: requests.Session):
200200 """Update behavior statistics for Series 3+ collars."""
201201 healthTrendsJSON = query .getPetHealthTrends (sessionId , self .petId , 'DAY' )
202202 behavior_trends = healthTrendsJSON .get ('behaviorTrends' , [])
203+
203204 self .setBehaviorStatsFromTrends (behavior_trends )
204205
206+ def _parseBehaviorDuration (self , input : str ) -> int :
207+ # examples: '46min'
208+ if input .startswith ('<' ):
209+ return 0
210+ elif input .endswith ('min' ):
211+ return int (input .replace ('min' , '' ), 10 )
212+ elif input .endswith ('hr' ):
213+ return int (input .replace ('hr' , '' ), 10 ) * 60
214+ else :
215+ return int (input )
216+
205217 def setBehaviorStatsFromTrends (self , behaviorTrends ):
206218 """Parse behavior data from health trends API."""
207219 # Reset all metrics
@@ -238,16 +250,7 @@ def setBehaviorStatsFromTrends(self, behaviorTrends):
238250 duration_summary = summary .get ('durationSummary' )
239251 duration_seconds = 0
240252 if duration_summary :
241- if duration_summary .startswith ('<' ):
242- duration_seconds = 30
243- else :
244- parts = duration_summary .replace ('h' , '' ).replace ('m' , '' ).split ()
245- if len (parts ) == 2 :
246- duration_seconds = int (parts [0 ]) * 3600 + int (parts [1 ]) * 60
247- elif 'h' in duration_summary :
248- duration_seconds = int (parts [0 ]) * 3600
249- else :
250- duration_seconds = int (parts [0 ]) * 60
253+ duration_seconds = self ._parseBehaviorDuration (duration_summary )
251254
252255 # Map to our attributes
253256 if trend_id == 'barking:DAY' :
0 commit comments