Skip to content
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

Weather Platform - IPMA #14716

Merged
merged 14 commits into from
Jun 3, 2018
Merged

Conversation

dgomes
Copy link
Contributor

@dgomes dgomes commented May 31, 2018

Description:

This new platform provides weather information made publicly available by the Portuguese Weather service (Instituto Português do Mar e Atmosfera - IPMA)

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

Example entry for configuration.yaml (if applicable):

weather:
  - platform: ipma

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

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

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

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

Copy link
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. Didn't look at the tests yet. Some comments below.

"""
import logging
from datetime import timedelta
import async_timeout
Copy link
Member

Choose a reason for hiding this comment

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

Group 3rd party imports and have a blank line between the three groups standard library, 3rd party and homeassistant imports.


def __init__(self, station, config):
"""Initialise the platform with a data instance and station name."""
self._stationname = config.get(CONF_NAME, station.local)
Copy link
Member

Choose a reason for hiding this comment

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

self._station_name = ...

@property
def condition(self):
"""Return the current condition."""
return [k for k, v in CONDITION_CLASSES.items()
Copy link
Member

Choose a reason for hiding this comment

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

return next((
    k for k, v in CONDITION_CLASSES.items()
    if self._forecast[0].idWeatherType in v), None)

@property
def visibility(self):
"""Return the current visibility."""
return None
Copy link
Member

Choose a reason for hiding this comment

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

Don't overwrite if not used.

data_out = {}
data_out[ATTR_FORECAST_TIME] = data_in.forecastDate
data_out[ATTR_FORECAST_CONDITION] =\
[k for k, v in CONDITION_CLASSES.items()
Copy link
Member

Choose a reason for hiding this comment

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

Use next and generator expression.

return fcdata_out

@property
def state_attributes(self):
Copy link
Member

Choose a reason for hiding this comment

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

Don't overwrite state_attributes. Use device_state_attributes. It will be merged with state_attributes during a state update.

@dgomes
Copy link
Contributor Author

dgomes commented Jun 2, 2018

Thanks for the review! 👍

Copy link
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 like it should be possible to mock the dependency and then we wouldn't need to add it to test requirements.

There's a helper MockDependency to mock a dependency in tests/common.py.

Copy link
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.

Great!

Copy link
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.

Missed this one. Can be merged after that.


if None in (latitude, longitude):
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
return False
Copy link
Member

Choose a reason for hiding this comment

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

Just return here.

@MartinHjelmare
Copy link
Member

Coveralls been acting up lately. Merging since we've got 97% coverage in this module.

@MartinHjelmare MartinHjelmare merged commit aec425d into home-assistant:dev Jun 3, 2018
@balloob balloob mentioned this pull request Jun 22, 2018
girlpunk pushed a commit to girlpunk/home-assistant that referenced this pull request Sep 4, 2018
* initial commit

* lint

* update with pyipma

* Added test

* Added test

* lint

* missing dep

* address comments

* lint

* make sure list is iterable

* don't bother with list

* mock dependency

* no need to add test requirements

* last correction
@home-assistant home-assistant locked and limited conversation to collaborators Sep 5, 2018
@dgomes dgomes deleted the weather_ipma branch April 7, 2022 18:10
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.

3 participants