Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Added daily and hourly modes to Openweathermap #14875

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

Merged
merged 5 commits into from
Jun 10, 2018
Merged

Added daily and hourly modes to Openweathermap #14875

merged 5 commits into from
Jun 10, 2018

Conversation

Yevgenium
Copy link
Contributor

@Yevgenium Yevgenium commented Jun 8, 2018

Description:

Added daily and hourly modes, wind speed and bearing to forecast

Pull request in home-assistant.github.io with documentation: home-assistant/home-assistant.io#5510

Example entry for configuration.yaml (if applicable):

weather:
  - platform: openweathermap
    api_key: YOUR_API_KEY
    mode: daily

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 or updated 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.

Added wind speed and bearing to forecast
@homeassistant
Copy link
Contributor

Hi @sgttrs,

It seems you haven't yet signed a CLA. Please do so here.

Once you do that we will be able to review and accept this pull request.

Thanks!

if self._mode == 'daily':
fcd = self.owm.daily_forecast_at_coords(self.latitude, self.longitude, 15)
else:
fcd = self.owm.three_hours_forecast_at_coords(self.latitude, self.longitude)

Choose a reason for hiding this comment

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

line too long (92 > 79 characters)

fcd = self.owm.three_hours_forecast_at_coords(
self.latitude, self.longitude)
if self._mode == 'daily':
fcd = self.owm.daily_forecast_at_coords(self.latitude, self.longitude, 15)

Choose a reason for hiding this comment

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

line too long (90 > 79 characters)

ATTR_FORECAST_PRECIPITATION: entry.get_rain().get('3h'),
ATTR_FORECAST_CONDITION:
[k for k, v in CONDITION_CLASSES.items()
if entry.get_weather_code() in v][0]

Choose a reason for hiding this comment

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

continuation line over-indented for visual indent

else:
data.append({
ATTR_FORECAST_TIME: entry.get_reference_time('unix') * 1000,
ATTR_FORECAST_TEMP: round(entry.get_temperature('celsius').get('temp')),

Choose a reason for hiding this comment

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

line too long (92 > 79 characters)

})
else:
data.append({
ATTR_FORECAST_TIME: entry.get_reference_time('unix') * 1000,

Choose a reason for hiding this comment

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

line too long (80 > 79 characters)

data.append({
ATTR_FORECAST_TIME: entry.get_reference_time('unix') * 1000,
ATTR_FORECAST_TEMP: round(entry.get_temperature('celsius').get('day')),
ATTR_FORECAST_TEMP_LOW: round(entry.get_temperature('celsius').get('night')),

Choose a reason for hiding this comment

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

line too long (97 > 79 characters)

if self._mode == 'daily':
data.append({
ATTR_FORECAST_TIME: entry.get_reference_time('unix') * 1000,
ATTR_FORECAST_TEMP: round(entry.get_temperature('celsius').get('day')),

Choose a reason for hiding this comment

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

line too long (91 > 79 characters)

})
if self._mode == 'daily':
data.append({
ATTR_FORECAST_TIME: entry.get_reference_time('unix') * 1000,

Choose a reason for hiding this comment

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

line too long (80 > 79 characters)

@@ -132,23 +140,37 @@ def wind_bearing(self):

@property
def attribution(self):
"""Return the attribution."""
return ATTRIBUTION
"""Return the attribution. Passing different attributes to correctly display the time in the frontend weather card"""

Choose a reason for hiding this comment

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

line too long (125 > 79 characters)

from homeassistant.const import (
CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, STATE_UNKNOWN,
CONF_API_KEY, CONF_MODE, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, STATE_UNKNOWN,

Choose a reason for hiding this comment

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

line too long (85 > 79 characters)

ATTR_FORECAST_TEMP: round(entry.get_temperature('celsius').get('day')),
ATTR_FORECAST_TEMP_LOW: round(entry.get_temperature('celsius').get('night')),
ATTR_FORECAST_WIND_SPEED: round(entry.get_wind().get('speed')),
ATTR_FORECAST_WIND_BEARING: round(entry.get_wind().get('deg')),

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

ATTR_FORECAST_TIME: entry.get_reference_time('unix') * 1000,
ATTR_FORECAST_TEMP: round(entry.get_temperature('celsius').get('day')),
ATTR_FORECAST_TEMP_LOW: round(entry.get_temperature('celsius').get('night')),
ATTR_FORECAST_WIND_SPEED: round(entry.get_wind().get('speed')),

Choose a reason for hiding this comment

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

line too long (83 > 79 characters)

@Yevgenium Yevgenium closed this Jun 9, 2018
@ghost ghost removed the in progress label Jun 9, 2018
@Yevgenium Yevgenium deleted the patch-1 branch June 9, 2018 06:54
@Yevgenium Yevgenium restored the patch-1 branch June 9, 2018 06:56
@Yevgenium Yevgenium reopened this Jun 9, 2018
@ghost ghost added the in progress label Jun 9, 2018
@Yevgenium Yevgenium changed the title Added daily and hourly modes Added daily and hourly modes to Openweathermap Jun 9, 2018
@@ -49,6 +55,7 @@

PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_API_KEY): cv.string,
vol.Optional(CONF_MODE, default='hourly'): vol.In(FORECAST_MODE),
Copy link
Member

Choose a reason for hiding this comment

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

Keep it alphabetically ordered.

ATTR_FORECAST_WIND_BEARING = 'wind_bearing'

ATTRIBUTION_DAILY = "Weather data provided by OpenWeatherMap"
ATTRIBUTION_HOURLY = "Data provided by OpenWeatherMap"
Copy link
Member

Choose a reason for hiding this comment

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

One attribution is enough.

result = ATTRIBUTION_DAILY
else:
result = ATTRIBUTION_HOURLY
return result
Copy link
Member

Choose a reason for hiding this comment

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

This is a hack and must be removed. It's a frontend issue and must be addressed there.

@fabaff fabaff merged commit 716ab04 into home-assistant:dev Jun 10, 2018
@ghost ghost removed the in progress label Jun 10, 2018
@balloob balloob mentioned this pull request Jun 22, 2018
@Yevgenium Yevgenium deleted the patch-1 branch June 22, 2018 19:45
@home-assistant home-assistant locked and limited conversation to collaborators Dec 10, 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