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

Merged
merged 2 commits into from Dec 27, 2018

Conversation

@maxandersen
Copy link
Contributor

maxandersen commented Oct 30, 2018

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:

Show resolved Hide resolved homeassistant/components/sensor/aftership.py
Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
@vMeph

This comment has been minimized.

Copy link

vMeph commented Nov 2, 2018

doesnt this sensor already exists
https://github.com/custom-cards/aftership-card

@ludeeus

This comment has been minimized.

Copy link
Member

ludeeus commented Nov 2, 2018

@vMeph That is a custom card for Lovelace and not a sensor platfrom like this PR.
That card uses another custom_component to fetch the data since (currently) there is no dedicated sensor in Home Assistant for this.

@vMeph

This comment has been minimized.

Copy link

vMeph commented Nov 2, 2018

ohh ok cool
ty for explanation

@maxandersen

This comment has been minimized.

Copy link
Contributor

maxandersen commented Nov 5, 2018

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.

@maxandersen

This comment has been minimized.

Copy link
Contributor

maxandersen commented Nov 5, 2018

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 ?

@ludeeus ludeeus referenced this pull request Nov 5, 2018

Closed

🔥 Deprecation warning. #4

@maxandersen

This comment has been minimized.

Copy link
Contributor

maxandersen commented Nov 14, 2018

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.

@frenck

This comment has been minimized.

Copy link
Member

frenck commented Nov 19, 2018

Could not find a related PR on our documentation repository. Adding docs-missing label.

@frenck frenck added the docs-missing label Nov 19, 2018

@maxandersen maxandersen force-pushed the maxandersen:aftership branch from 6afb4e9 to c2402bf Nov 21, 2018

Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated

@maxandersen maxandersen force-pushed the maxandersen:aftership branch 2 times, most recently from b1f742a to d4001eb Nov 21, 2018

@maxandersen

This comment has been minimized.

Copy link
Contributor

maxandersen commented Nov 21, 2018

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 ;)

Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
from homeassistant.util import Throttle
from homeassistant.exceptions import PlatformNotReady

REQUIREMENTS = ['pyaftership==0.0.5']

This comment has been minimized.

@fabaff

fabaff Nov 25, 2018

Member

It looks like that the latest release is 0.1.1.

This comment has been minimized.

@maxandersen

maxandersen Nov 27, 2018

Contributor

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.

This comment has been minimized.

@maxandersen

maxandersen Nov 27, 2018

Contributor

removed the service code to make the initial PR simpler.

@maxandersen maxandersen force-pushed the maxandersen:aftership branch 3 times, most recently from 25cb2fb to f4c1258 Nov 27, 2018

Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
_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))

This comment has been minimized.

@houndci-bot

houndci-bot Nov 27, 2018

line too long (89 > 79 characters)

Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
async def async_update(self):
"""Get the latest data from the AfterShip API."""
await self.aftership.get_trackings()

This comment has been minimized.

@houndci-bot

houndci-bot Nov 27, 2018

blank line contains whitespace

Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated

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

This comment has been minimized.

@houndci-bot

houndci-bot Nov 27, 2018

trailing whitespace

Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
aftership = Tracking(hass.loop, session, apikey)

await aftership.get_trackings()

This comment has been minimized.

@houndci-bot

houndci-bot Nov 27, 2018

blank line contains whitespace

Show resolved Hide resolved homeassistant/components/sensor/aftership.py Outdated
Show resolved Hide resolved homeassistant/components/sensor/aftership.py

@maxandersen maxandersen force-pushed the maxandersen:aftership branch from f4c1258 to 9ce458b Nov 27, 2018

@maxandersen

This comment has been minimized.

Copy link
Contributor

maxandersen commented Nov 27, 2018

apparently my githook isn't properly running lint ;/ fix those issues and pushed updated that has async and latest pyaftership usage.

@maxandersen

This comment has been minimized.

Copy link
Contributor

maxandersen commented Nov 30, 2018

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!

@MartinHjelmare

This comment has been minimized.

Copy link
Member

MartinHjelmare commented Dec 9, 2018

This is almost ready for merge. Please don't extend it more in this PR, unless it would be a breaking change later.

@maxandersen

This comment has been minimized.

Copy link
Contributor

maxandersen commented Dec 10, 2018

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.

Add AfterShip sensor for packages
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

@maxandersen maxandersen force-pushed the maxandersen:aftership branch from 9ce458b to 2b82669 Dec 19, 2018

@MartinHjelmare
Copy link
Member

MartinHjelmare left a comment

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.

@fabaff

fabaff approved these changes Dec 27, 2018

@MartinHjelmare

This comment has been minimized.

Copy link
Member

MartinHjelmare commented Dec 27, 2018

Thanks @fabaff!

@MartinHjelmare MartinHjelmare merged commit b32e6fe into home-assistant:dev Dec 27, 2018

5 checks passed

Hound No violations found. Woof!
WIP ready for review
Details
cla-bot Everyone involved has signed the CLA
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls First build on aftership at 93.048%
Details

@wafflebot wafflebot bot removed the in progress label Dec 27, 2018

@balloob balloob referenced this pull request Jan 10, 2019

Merged

0.85.0 #19897

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment