Fixes UPS MyChoice exception (#9587)
* Fixes UPS MyChoice exception * Added unit of measurement * Collaborator-requested changespull/9581/merge
parent
312de6b3a3
commit
d499c18e63
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue