8000 Fixes UPS MyChoice exception by bachya · Pull Request #9587 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixes UPS MyChoice exception #9587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions homeassistant/components/sensor/ups.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,26 @@ def state(self):
"""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
}
Expand Down
0