From d499c18e6330b824768adc17114f1b0643aea717 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Wed, 27 Sep 2017 11:44:32 -0600 Subject: [PATCH] Fixes UPS MyChoice exception (#9587) * Fixes UPS MyChoice exception * Added unit of measurement * Collaborator-requested changes --- homeassistant/components/sensor/ups.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/sensor/ups.py b/homeassistant/components/sensor/ups.py index 40d84fe2618..c51ae67475f 100644 --- a/homeassistant/components/sensor/ups.py +++ b/homeassistant/components/sensor/ups.py @@ -76,17 +76,26 @@ class UPSSensor(Entity): """Return the state of the sensor.""" return self._state + @property + def unit_of_measurement(self): + """Return the unit of measurement of this entity, if any.""" + return 'packages' + def _update(self): """Update device state.""" import upsmychoice status_counts = defaultdict(int) - for package in upsmychoice.get_packages(self._session): - status = slugify(package['status']) - skip = status == STATUS_DELIVERED and \ - parse_date(package['delivery_date']) < now().date() - if skip: - continue - status_counts[status] += 1 + try: + for package in upsmychoice.get_packages(self._session): + status = slugify(package['status']) + skip = status == STATUS_DELIVERED and \ + parse_date(package['delivery_date']) < now().date() + if skip: + continue + status_counts[status] += 1 + except upsmychoice.UPSError: + _LOGGER.error('Could not connect to UPS My Choice account') + self._attributes = { ATTR_ATTRIBUTION: upsmychoice.ATTRIBUTION }