mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Fixes UPS MyChoice exception (#9587)
* Fixes UPS MyChoice exception * Added unit of measurement * Collaborator-requested changes
This commit is contained in:
parent
312de6b3a3
commit
d499c18e63
@ -76,17 +76,26 @@ class UPSSensor(Entity):
|
|||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def unit_of_measurement(self):
|
||||||
|
"""Return the unit of measurement of this entity, if any."""
|
||||||
|
return 'packages'
|
||||||
|
|
||||||
def _update(self):
|
def _update(self):
|
||||||
"""Update device state."""
|
"""Update device state."""
|
||||||
import upsmychoice
|
import upsmychoice
|
||||||
status_counts = defaultdict(int)
|
status_counts = defaultdict(int)
|
||||||
for package in upsmychoice.get_packages(self._session):
|
try:
|
||||||
status = slugify(package['status'])
|
for package in upsmychoice.get_packages(self._session):
|
||||||
skip = status == STATUS_DELIVERED and \
|
status = slugify(package['status'])
|
||||||
parse_date(package['delivery_date']) < now().date()
|
skip = status == STATUS_DELIVERED and \
|
||||||
if skip:
|
parse_date(package['delivery_date']) < now().date()
|
||||||
continue
|
if skip:
|
||||||
status_counts[status] += 1
|
continue
|
||||||
|
status_counts[status] += 1
|
||||||
|
except upsmychoice.UPSError:
|
||||||
|
_LOGGER.error('Could not connect to UPS My Choice account')
|
||||||
|
|
||||||
self._attributes = {
|
self._attributes = {
|
||||||
ATTR_ATTRIBUTION: upsmychoice.ATTRIBUTION
|
ATTR_ATTRIBUTION: upsmychoice.ATTRIBUTION
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user