@@ -146,7 +146,7 @@ def _dump_activities(self, msg):
146
146
)
147
147
148
148
# Media library has updated, reload today's events.
149
- def _update_media (self ):
149
+ def _update_from_media_library (self ):
150
150
self .debug ("reloading cache for " + self ._name )
151
151
count , videos = self ._arlo .ml .videos_for (self )
152
152
if videos :
@@ -163,7 +163,7 @@ def _update_media(self):
163
163
self ._cache_count = count
164
164
self ._cached_videos = videos
165
165
166
- # update latest video details
166
+ # Update latest video details.
167
167
if videos :
168
168
if videos [0 ].created_at != self ._load (LAST_VIDEO_CREATED_KEY ):
169
169
self ._save_and_do_callbacks (LAST_VIDEO_CREATED_KEY , videos [0 ].created_at )
@@ -172,7 +172,7 @@ def _update_media(self):
172
172
self ._save_and_do_callbacks (LAST_VIDEO_OBJECT_TYPE , videos [0 ].object_type )
173
173
self ._save_and_do_callbacks (LAST_VIDEO_OBJECT_REGION , videos [0 ].object_region )
174
174
175
- # signal video up!
175
+ # Tell anyone listening about the new capture and how it affects things.
176
176
self ._save_and_do_callbacks (CAPTURED_TODAY_KEY , captured_today )
177
177
if last_captured is not None :
178
178
self ._save_and_do_callbacks (LAST_CAPTURE_KEY , last_captured )
@@ -181,18 +181,24 @@ def _update_media(self):
181
181
# new snapshot?
182
182
snapshot = self ._arlo .ml .snapshot_for (self )
183
183
if snapshot is not None :
184
- self .debug ("snapshot updated for media " + self .name )
185
- self ._save (SNAPSHOT_KEY , snapshot .image_url )
186
- self ._arlo .bg .run_low (self ._update_snapshot )
184
+ if self ._load (SNAPSHOT_KEY , None ) != snapshot .image_url :
185
+ self .debug ("snapshot updated for media " + self .name )
186
+ self ._save (SNAPSHOT_KEY , snapshot .image_url )
187
+ self ._arlo .bg .run_low (self ._update_image_from_snapshot )
188
+ else :
189
+ self .debug ("snapshot already done for " + self .name )
187
190
188
- # new image?
191
+ # New image? Then fetch it an update image details.
189
192
if last_image is not None :
190
- self .debug ("image updated for media " + self .name )
191
- self ._save (LAST_IMAGE_KEY , last_image )
192
- self ._arlo .bg .run_low (self ._update_image )
193
+ if self ._load (LAST_IMAGE_KEY , None ) != last_image :
194
+ self .debug ("image updated for media " + self .name )
195
+ self ._save (LAST_IMAGE_KEY , last_image )
196
+ self ._arlo .bg .run_low (self ._update_image_from_capture )
197
+ else :
198
+ self .debug ("image already done for " + self .name )
193
199
194
200
# Update last captured image.
195
- def _update_image (self ):
201
+ def _update_image_from_capture (self ):
196
202
# Get image and date, if fails ignore
197
203
img , date = http_get_img (self ._load (LAST_IMAGE_KEY , None ))
198
204
if img is None :
@@ -205,14 +211,13 @@ def _update_image(self):
205
211
date = date .strftime (self ._arlo .cfg .last_format )
206
212
self .debug (f"updating image for { self .name } ({ date } )" )
207
213
self ._save_and_do_callbacks (LAST_IMAGE_SRC_KEY , "capture/" + date )
208
- self ._save_and_do_callbacks (LAST_CAPTURE_KEY , date )
209
214
self ._save_and_do_callbacks (LAST_IMAGE_DATA_KEY , img )
210
215
else :
211
216
date = date .strftime (self ._arlo .cfg .last_format )
212
217
self .vdebug (f"ignoring image for { self .name } ({ date } )" )
213
218
214
219
# Update the last snapshot
215
- def _update_snapshot (self , ignore_date = False ):
220
+ def _update_image_from_snapshot (self , ignore_date = False ):
216
221
# Get image and date, if fails ignore.
217
222
img , date = http_get_img (self ._load (SNAPSHOT_KEY , None ), ignore_date )
218
223
if img is None :
@@ -270,7 +275,7 @@ def _queue_media_updates(self):
270
275
for retry in self ._arlo .cfg .media_retry :
271
276
self .debug ("queueing update in {}" .format (retry ))
272
277
self ._arlo .bg .run_in (
273
- self ._arlo .ml .queue_update , retry , cb = self ._update_media
278
+ self ._arlo .ml .queue_update , retry , cb = self ._update_from_media_library
274
279
)
275
280
276
281
def _mark_as_idle (self ):
@@ -371,20 +376,20 @@ def _event_handler(self, resource, event):
371
376
if LAST_IMAGE_KEY in event :
372
377
if not self .is_taking_snapshot :
373
378
self .debug ("{} -> thumbnail changed" .format (self .name ))
374
- self ._arlo .bg .run_low (self ._update_image )
379
+ self ._arlo .bg .run_low (self ._update_image_from_capture )
375
380
else :
376
381
self .debug (
377
382
"{} -> snapshot(thumbnail) ready" .format (self .name )
378
383
)
379
384
self ._save (SNAPSHOT_KEY , event .get (LAST_IMAGE_KEY , "" ))
380
- self ._arlo .bg .run_low (self ._update_snapshot , ignore_date = True )
385
+ self ._arlo .bg .run_low (self ._update_image_from_snapshot , ignore_date = True )
381
386
382
387
# Recording has stopped so a new video is available. Queue an
383
388
# media update, this could later trigger a snapshot or image
384
389
# update.
385
390
if event .get (RECORDING_STOPPED_KEY , False ):
386
391
self .debug ("{} -> recording stopped" .format (self .name ))
387
- self ._arlo .ml .queue_update (self ._update_media )
392
+ self ._arlo .ml .queue_update (self ._update_from_media_library )
388
393
389
394
# Examine the URL passed; snapshots contain `/snapshots/` and
390
395
# recordings contain `recordings`. For snapshot, save URL and queue
@@ -394,7 +399,7 @@ def _event_handler(self, resource, event):
394
399
if "/snapshots/" in value :
395
400
self .debug ("{} -> snapshot1 ready" .format (self .name ))
396
401
self ._save (SNAPSHOT_KEY , value )
397
- self ._arlo .bg .run_low (self ._update_snapshot )
402
+ self ._arlo .bg .run_low (self ._update_image_from_snapshot )
398
403
if "/recordings/" in value :
399
404
self .debug ("{} -> new recording ready" .format (self .name ))
400
405
@@ -443,15 +448,15 @@ def _event_handler(self, resource, event):
443
448
if value is not None :
444
449
self .debug ("{} -> snapshot2 ready" .format (self .name ))
445
450
self ._save (SNAPSHOT_KEY , value )
446
- self ._arlo .bg .run_low (self ._update_snapshot )
451
+ self ._arlo .bg .run_low (self ._update_image_from_snapshot )
447
452
448
453
# Non subscription...
449
454
if event .get ("action" , "" ) == "lastImageSnapshotAvailable" :
450
455
value = event .get ("properties" , {}).get ("presignedLastImageUrl" , None )
451
456
if value is not None :
452
457
self .debug ("{} -> snapshot3 ready" .format (self .name ))
453
458
self ._save (SNAPSHOT_KEY , value )
454
- self ._arlo .bg .run_low (self ._update_snapshot )
459
+ self ._arlo .bg .run_low (self ._update_image_from_snapshot )
455
460
456
461
# Ambient sensors update, decode and push changes.
457
462
if resource .endswith ("/ambientSensors/history" ):
@@ -704,10 +709,10 @@ def update_media(self, wait=None):
704
709
wait = self ._arlo .cfg .synchronous_mode
705
710
if wait :
706
711
self .debug ("doing media update" )
707
- self ._update_media ()
712
+ self ._update_from_media_library ()
708
713
else :
709
714
self .debug ("queueing media update" )
710
- self ._arlo .bg .run_low (self ._update_media )
715
+ self ._arlo .bg .run_low (self ._update_from_media_library )
711
716
712
717
def update_last_image (self , wait = None ):
713
718
"""Requests last thumbnail from the backend server.
@@ -721,10 +726,10 @@ def update_last_image(self, wait=None):
721
726
wait = self ._arlo .cfg .synchronous_mode
722
727
if wait :
723
728
self .debug ("doing image update" )
724
- self ._update_image ()
729
+ self ._update_image_from_capture ()
725
730
else :
726
731
self .debug ("queueing image update" )
727
- self ._arlo .bg .run_low (self ._update_image )
732
+ self ._arlo .bg .run_low (self ._update_image_from_capture )
728
733
729
734
def update_ambient_sensors (self ):
730
735
"""Requests the latest temperature, humidity and air quality settings.
@@ -812,7 +817,7 @@ def request_snapshot(self):
812
817
for check in self ._arlo .cfg .snapshot_checks :
813
818
self .debug ("queueing snapshot check in {}" .format (check ))
814
819
self ._arlo .bg .run_in (
815
- self ._arlo .ml .queue_update , check , cb = self ._update_media
820
+ self ._arlo .ml .queue_update , check , cb = self ._update_from_media_library
816
821
)
817
822
818
823
self .vdebug ("handle dodgy cameras" )
0 commit comments