Add wind gust (fixes #17766) (#17774)

This commit is contained in:
Fabian Affolter 2018-10-25 09:33:23 +02:00 committed by GitHub
parent bd23145331
commit aa157e17f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,20 +4,20 @@ Support for Dark Sky weather service.
For more details about this platform, please refer to the documentation at For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.darksky/ https://home-assistant.io/components/sensor.darksky/
""" """
import logging
from datetime import timedelta from datetime import timedelta
import logging
from requests.exceptions import (
ConnectionError as ConnectError, HTTPError, Timeout)
import voluptuous as vol import voluptuous as vol
from requests.exceptions import ConnectionError as ConnectError, \
HTTPError, Timeout
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import ( from homeassistant.const import (
CONF_API_KEY, CONF_NAME, CONF_MONITORED_CONDITIONS, ATTR_ATTRIBUTION, ATTR_ATTRIBUTION, CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE,
CONF_LATITUDE, CONF_LONGITUDE, UNIT_UV_INDEX) CONF_MONITORED_CONDITIONS, CONF_NAME, UNIT_UV_INDEX)
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle from homeassistant.util import Throttle
import homeassistant.helpers.config_validation as cv
REQUIREMENTS = ['python-forecastio==1.4.0'] REQUIREMENTS = ['python-forecastio==1.4.0']
@ -82,6 +82,9 @@ SENSOR_TYPES = {
'mdi:weather-windy', ['currently', 'hourly', 'daily']], 'mdi:weather-windy', ['currently', 'hourly', 'daily']],
'wind_bearing': ['Wind Bearing', '°', '°', '°', '°', '°', 'mdi:compass', 'wind_bearing': ['Wind Bearing', '°', '°', '°', '°', '°', 'mdi:compass',
['currently', 'hourly', 'daily']], ['currently', 'hourly', 'daily']],
'wind_gust': ['Wind Gust', 'm/s', 'mph', 'km/h', 'mph', 'mph',
'mdi:weather-windy-variant',
['currently', 'hourly', 'daily']],
'cloud_cover': ['Cloud Coverage', '%', '%', '%', '%', '%', 'cloud_cover': ['Cloud Coverage', '%', '%', '%', '%', '%',
'mdi:weather-partlycloudy', 'mdi:weather-partlycloudy',
['currently', 'hourly', 'daily']], ['currently', 'hourly', 'daily']],
@ -146,12 +149,9 @@ CONDITION_PICTURES = {
# Language Supported Codes # Language Supported Codes
LANGUAGE_CODES = [ LANGUAGE_CODES = [
'ar', 'az', 'be', 'bg', 'bs', 'ca', 'ar', 'az', 'be', 'bg', 'bs', 'ca', 'cs', 'da', 'de', 'el', 'en', 'es',
'cs', 'da', 'de', 'el', 'en', 'es', 'et', 'fi', 'fr', 'hr', 'hu', 'id', 'is', 'it', 'ja', 'ka', 'kw', 'nb',
'et', 'fi', 'fr', 'hr', 'hu', 'id', 'nl', 'pl', 'pt', 'ro', 'ru', 'sk', 'sl', 'sr', 'sv', 'tet', 'tr', 'uk',
'is', 'it', 'ja', 'ka', 'kw', 'nb',
'nl', 'pl', 'pt', 'ro', 'ru', 'sk',
'sl', 'sr', 'sv', 'tet', 'tr', 'uk',
'x-pig-latin', 'zh', 'zh-tw', 'x-pig-latin', 'zh', 'zh-tw',
] ]
@ -179,6 +179,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
latitude = config.get(CONF_LATITUDE, hass.config.latitude) latitude = config.get(CONF_LATITUDE, hass.config.latitude)
longitude = config.get(CONF_LONGITUDE, hass.config.longitude) longitude = config.get(CONF_LONGITUDE, hass.config.longitude)
language = config.get(CONF_LANGUAGE) language = config.get(CONF_LANGUAGE)
interval = config.get(CONF_UPDATE_INTERVAL)
if CONF_UNITS in config: if CONF_UNITS in config:
units = config[CONF_UNITS] units = config[CONF_UNITS]
@ -188,18 +189,14 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
units = 'us' units = 'us'
forecast_data = DarkSkyData( forecast_data = DarkSkyData(
api_key=config.get(CONF_API_KEY, None), api_key=config.get(CONF_API_KEY, None), latitude=latitude,
latitude=latitude, longitude=longitude, units=units, language=language, interval=interval)
longitude=longitude,
units=units,
language=language,
interval=config.get(CONF_UPDATE_INTERVAL))
forecast_data.update() forecast_data.update()
forecast_data.update_currently() forecast_data.update_currently()
# If connection failed don't setup platform. # If connection failed don't setup platform.
if forecast_data.data is None: if forecast_data.data is None:
return False return
name = config.get(CONF_NAME) name = config.get(CONF_NAME)
@ -207,8 +204,7 @@ def setup_platform(hass, config, add_entities, discovery_info=None):
sensors = [] sensors = []
for variable in config[CONF_MONITORED_CONDITIONS]: for variable in config[CONF_MONITORED_CONDITIONS]:
if variable in DEPRECATED_SENSOR_TYPES: if variable in DEPRECATED_SENSOR_TYPES:
_LOGGER.warning("Monitored condition %s is deprecated", _LOGGER.warning("Monitored condition %s is deprecated", variable)
variable)
sensors.append(DarkSkySensor(forecast_data, variable, name)) sensors.append(DarkSkySensor(forecast_data, variable, name))
if forecast is not None and 'daily' in SENSOR_TYPES[variable][7]: if forecast is not None and 'daily' in SENSOR_TYPES[variable][7]:
for forecast_day in forecast: for forecast_day in forecast:
@ -360,8 +356,7 @@ class DarkSkySensor(Entity):
if self.type in ['dew_point', 'temperature', 'apparent_temperature', if self.type in ['dew_point', 'temperature', 'apparent_temperature',
'temperature_min', 'temperature_max', 'temperature_min', 'temperature_max',
'apparent_temperature_min', 'apparent_temperature_min',
'apparent_temperature_max', 'apparent_temperature_max', 'precip_accumulation',
'precip_accumulation',
'pressure', 'ozone', 'uvIndex']: 'pressure', 'ozone', 'uvIndex']:
return round(state, 1) return round(state, 1)
return state return state
@ -371,7 +366,7 @@ def convert_to_camel(data):
""" """
Convert snake case (foo_bar_bat) to camel case (fooBarBat). Convert snake case (foo_bar_bat) to camel case (fooBarBat).
This is not pythonic, but needed for certain situations This is not pythonic, but needed for certain situations.
""" """
components = data.split('_') components = data.split('_')
return components[0] + "".join(x.title() for x in components[1:]) return components[0] + "".join(x.title() for x in components[1:])
@ -380,8 +375,8 @@ def convert_to_camel(data):
class DarkSkyData: class DarkSkyData:
"""Get the latest data from Darksky.""" """Get the latest data from Darksky."""
def __init__(self, api_key, latitude, longitude, units, language, def __init__(
interval): self, api_key, latitude, longitude, units, language, interval):
"""Initialize the data object.""" """Initialize the data object."""
self._api_key = api_key self._api_key = api_key
self.latitude = latitude self.latitude = latitude