-
-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
Add AfterShip sensor for packages #18034
Conversation
doesnt this sensor already exists |
@vMeph That is a custom card for Lovelace and not a sensor platfrom like this PR. |
ohh ok cool |
yes, I learned after publishing this that https://github.com/custom-components/sensor.aftership exists and I think I'll merge its features. I do though think it would be nice to have a generic all-purpose package tracker (rather than the fairly limited/dedicated ones in there) - hence why suggesting to add it officially. |
one thing i'm wondering - is the best way to expose details about the current incoming packages really to put it as a json dictionary as data on the sensor or would it be better to have these as some kind of temporary tracking entities or similar ? |
fyi - delay in updating the PR is due to that after moving to hassio I'm battling this issue: https://community.home-assistant.io/t/runtimeerror-the-processor-time-used-is-not-available-or-its-value-cannot-be-represented/77659 alternatively I could just use the api directly (as its trivial) and avoid the use of clock() in the aftership sdk - suggestions welcome. |
Could not find a related PR on our documentation repository. Adding |
6afb4e9
to
c2402bf
Compare
b1f742a
to
d4001eb
Compare
Now cleaned this up based on feedback. I also had to move to using pyaftership rather than aftership's own python sdk as the latter fails when running over a day on a hass.io raspberry (some issue using .clock() calls). In addition I added a service to call for adding packages - I wanted to add service description but did not find services.yaml for sensors - is that expected ? should I create a new ? I'll make a corresponding doc tomorrow - time to sleep now ;) |
from homeassistant.util import Throttle | ||
from homeassistant.exceptions import PlatformNotReady | ||
|
||
REQUIREMENTS = ['pyaftership==0.0.5'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like that the latest release is 0.1.1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, new update came out based on this PR - pushed update using latest that is also async.
but just noticed the service is failing for this version so looking into that now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the service code to make the initial PR simpler.
25cb2fb
to
f4c1258
Compare
_LOGGER.error("Unkown errors when querying AfterShip. See logs for details.") | ||
return | ||
elif self.aftership.meta['code'] != 200: | ||
_LOGGER.error("Errors when querying AfterShip. %s", str(self.aftership.meta)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line too long (89 > 79 characters)
async def async_update(self): | ||
"""Get the latest data from the AfterShip API.""" | ||
await self.aftership.get_trackings() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line contains whitespace
|
||
if not aftership.meta or aftership.meta['code'] != 200: | ||
_LOGGER.error("No tracking data found. Check AfterShip API key is correct: %s", aftership.meta) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trailing whitespace
aftership = Tracking(hass.loop, session, apikey) | ||
|
||
await aftership.get_trackings() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line contains whitespace
f4c1258
to
9ce458b
Compare
apparently my githook isn't properly running lint ;/ fix those issues and pushed updated that has async and latest pyaftership usage. |
Just noticed the 17track component which does the sensor per package I wanted to do. I know you prefer small PRS over big ones. Could we commit the current state for this one and then I add the package sensors or you prefer I do it in one go ? Thanks! |
This is almost ready for merge. Please don't extend it more in this PR, unless it would be a breaking change later. |
I'm cool with leave as is if that gets it included; then I can add the actual individual package tracking in additional PR's. |
Why: * I receive a lot of packages from many different shipping companies. * I would like to see in haas how many packages are being delivered. This change addreses the need by: * Adding a sensor for AfterShip (aftership.com) * AfterShip supports ~490 couriers world wide thus should cover almost any sensible tracking. Notes: - For now this sensor assumes you somehow have added trackings to aftership manually. - Future idea is to expose service that allows adding a tracking based on incoming mails. - Other improvments would be to add map markers for package locations. Related: - https://community.home-assistant.io/t/package-tracking/858 - https://community.home-assistant.io/t/aftership-package-tracking/24068 - https://community.home-assistant.io/t/aftership-shipment-tracking-platform/14074 - https://community.home-assistant.io/t/aftership-state-card/57912
9ce458b
to
2b82669
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good!
For the future, please don't squash commits after review has started to make it easier for readers to track changes. We always squash upon merge via github anyway.
Can be merged when build passes.
Thanks @fabaff! |
Why:
This change addreses the need by:
almost any sensible tracking.
Notes:
aftership manually
based on incoming mails.
Related: