Fixes UPS MyChoice exception (#9587)

* Fixes UPS MyChoice exception

* Added unit of measurement

* Collaborator-requested changes
pull/9581/merge
Aaron Bach 2017-09-27 11:44:32 -06:00 committed by Paulus Schoutsen
parent 312de6b3a3
commit d499c18e63
1 changed files with 16 additions and 7 deletions

View File

@ -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
}