Skip to content

Added city/state/country options and fixed several bugs#9436

Merged
MartinHjelmare merged 3 commits into
home-assistant:devfrom
bachya:airvisual_updates
Sep 16, 2017
Merged

Added city/state/country options and fixed several bugs#9436
MartinHjelmare merged 3 commits into
home-assistant:devfrom
bachya:airvisual_updates

Conversation

@bachya
Copy link
Copy Markdown
Contributor

@bachya bachya commented Sep 15, 2017

Description:

  • Adds ability to specify a city/state/country to get information for that particular location
  • Adds a unit to Air Quality Index sensors (to get a nice graph)
  • Fixes an unhandled exception that would occur when retrieving bad/nonexistent API results

Related issue (if applicable): N/A

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#3370

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: airvisual
    api_key: qePWFp2pHoP37txTx
    monitored_conditions:
      - us
      - cn
    city: sao-paulo
    state: sao-paulo
    country: brazil

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. One name change required and one suggestion for simplification.

ATTR_COUNTRY = 'country'
ATTR_POLLUTANT_SYMBOL = 'pollutant_symbol'
ATTR_POLLUTANT_UNIT = 'pollutant_unit'
ATTR_STATE = 'region'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename the constant to eg ATTR_REGION.

_LOGGER('Unable to retrieve data from the API')
_LOGGER.error("There is likely no data on this location")
_LOGGER.debug(exc_info)
self.pollution_info = None
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could do self.pollution_info = {} so you don't have to do all the checks above.

def unit_of_measurement(self):
"""Return the unit the value is expressed in."""
return ''
return 'unit' if self.state == '1' else 'units'
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed this one first pass. I don't think it's wise to change the unit for the same entity. That will mess with 3rd party recorders and be very unpredictable for the users. Just decide on either of these.

@bachya
Copy link
Copy Markdown
Contributor Author

bachya commented Sep 16, 2017

@MartinHjelmare: Made all of your requested changes. Even going with your original unit suggestion. Thanks!

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@MartinHjelmare MartinHjelmare merged commit f3fc571 into home-assistant:dev Sep 16, 2017
@bachya bachya deleted the airvisual_updates branch September 17, 2017 23:06
@balloob balloob mentioned this pull request Sep 22, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Mar 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants