8000 RFC: can't use ZIP codes with leading zeroes · Issue #12787 · home-assistant/core · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

RFC: can't use ZIP codes with leading zeroes #12787

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

Closed
bachya opened this issue Feb 28, 2018 · 2 comments · Fixed by #12790
Closed

RFC: can't use ZIP codes with leading zeroes #12787

bachya opened this issue Feb 28, 2018 · 2 comments · Fixed by #12790

Comments

@bachya
Copy link
Contributor
bachya commented Feb 28, 2018

Make sure you are running the latest version of Home Assistant before reporting an issue.

You should only file an issue if you found a bug. Feature and enhancement requests should go in the Feature Requests section of our community forum:

Home Assistant release (hass --version):
0.64.1

Python release (python3 --version):
3.6.1

Component/platform:
sensor/pollen

Description of problem:
ZIP codes with leading zeros (e.g., 00544, which is Holtsville, New York) are not parsed properly from configuration.yaml. Although this issue was discovered via the Pollen.com sensor, it is not an issue unique to that sensor; the solution lies somewhere deeper.

If a bare, unquoted ZIP is provided:

sensor:
- platform: pollen
  zip_code: 00544
  monitored_conditions:
    - allergy_average_forecasted

...the following error shows in the logs (asterisks around the crucial part):

2018-02-28 12:19:13 ERROR (SyncWorker_2) [homeassistant.components.sensor.pollen] An error occurred while retrieving data
2018-02-28 12:19:13 DEBUG (SyncWorker_2) [homeassistant.components.sensor.pollen] 404 Client Error: Not Found for url: https://www.pollen.com/api/forecast/extended/pollen/**356**

Notice the 356 at the tail end of the URL – it appears that PyYAML is interpreting that int as an octal number (00544 in decimal = 356 in octal).

If a quoted version of the ZIP code is used:

sensor:
- platform: pollen
  zip_code: "00544"
  monitored_conditions:
    - allergy_average_forecasted

...the error changes (again, asterisks around the crucial part):

2018-02-28 12:19:13 ERROR (SyncWorker_2) [homeassistant.components.sensor.pollen] An error occurred while retrieving data
2018-02-28 12:19:13 DEBUG (SyncWorker_2) [homeassistant.components.sensor.pollen] 404 Client Error: Not Found for url: https://www.pollen.com/api/forecast/extended/pollen/**544**

Although no octal conversion is occurring, the leading zeroes are still being stripped off.

Expected:
The quoted version of the int should be cast as a string. Open to other alternatives, as well.

Problem-relevant configuration.yaml entries and steps to reproduce:
See above for an example that reveals the issue.

Traceback (if applicable):
N/A

@happyleavesaoc
Copy link
Contributor
  1. The octal thing is part of the yaml spec, no way around that.

  2. You're quoting the zip, but the pollen sensor has a validator that casts it as a positive int, and that's how it's passed into the Client constructor. I think just changing that to cv.string should work ...

@bachya
Copy link
Contributor Author
bachya commented Feb 28, 2018

Great call, @happyleavesaoc. I'll modify the schema and docs. Thanks for your help!

@bachya bachya closed this as completed Feb 28, 2018
balloob pushed a commit to home-assistant/home-assistant.io that referenced this issue Feb 28, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Jul 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants
0