From 3979eb59f4fc827495bcc28c6a73b0481f3bad39 Mon Sep 17 00:00:00 2001 From: mjj4791 Date: Sun, 27 Aug 2017 23:28:40 +0200 Subject: [PATCH 1/2] Prevent iCloud exceptions in logfile With this change ValueError exceptions in the logfile caused by this component will disappear. These errors are caused by the iCloud API returning an HTTP 450 error and the external lib throwing a ValueError because of it. A PR has been raised against the external library, but that fix did not yet make it into a new version of the library. This will catch the exception in the mean time.... https://github.com/picklepete/pyicloud/pull/138 --- homeassistant/components/device_tracker/icloud.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/device_tracker/icloud.py b/homeassistant/components/device_tracker/icloud.py index f20dad1fceb2f..513a9afb30f7e 100644 --- a/homeassistant/components/device_tracker/icloud.py +++ b/homeassistant/components/device_tracker/icloud.py @@ -307,12 +307,15 @@ def keep_alive(self, now): self.api.authenticate() currentminutes = dt_util.now().hour * 60 + dt_util.now().minute - for devicename in self.devices: - interval = self._intervals.get(devicename, 1) - if ((currentminutes % interval == 0) or - (interval > 10 and - currentminutes % interval in [2, 4])): - self.update_device(devicename) + try: + for devicename in self.devices: + interval = self._intervals.get(devicename, 1) + if ((currentminutes % interval == 0) or + (interval > 10 and + currentminutes % interval in [2, 4])): + self.update_device(devicename) + except ValueError: + _LOGGER.debug('iCloud API returned an error.') def determine_interval(self, devicename, latitude, longitude, battery): """Calculate new interval.""" From 1aee9309a5a6ccc734e2a9a0f4c1048932f3cb7b Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Mon, 28 Aug 2017 11:30:21 +0200 Subject: [PATCH 2/2] Align log messages --- homeassistant/components/device_tracker/icloud.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/device_tracker/icloud.py b/homeassistant/components/device_tracker/icloud.py index 513a9afb30f7e..e670287dd879d 100644 --- a/homeassistant/components/device_tracker/icloud.py +++ b/homeassistant/components/device_tracker/icloud.py @@ -315,7 +315,7 @@ def keep_alive(self, now): currentminutes % interval in [2, 4])): self.update_device(devicename) except ValueError: - _LOGGER.debug('iCloud API returned an error.') + _LOGGER.debug("iCloud API returned an error") def determine_interval(self, devicename, latitude, longitude, battery): """Calculate new interval.""" @@ -400,7 +400,7 @@ def update_device(self, devicename): self.see(**kwargs) self.seen_devices[devicename] = True except PyiCloudNoDevicesException: - _LOGGER.error('No iCloud Devices found!') + _LOGGER.error("No iCloud Devices found") def lost_iphone(self, devicename): """Call the lost iPhone function if the device is found."""