Skip to content

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

@bachya

Description

@bachya

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions