mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
DarkSky weather / Fix states (#15174)
* DarkSky weather / Fix states * fix lint * fix tests
This commit is contained in:
parent
4fbe3bb070
commit
dbb786c548
@ -12,7 +12,8 @@ from requests.exceptions import (
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.weather import (
|
from homeassistant.components.weather import (
|
||||||
ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME, PLATFORM_SCHEMA, WeatherEntity)
|
ATTR_FORECAST_TEMP, ATTR_FORECAST_TIME, ATTR_FORECAST_CONDITION,
|
||||||
|
PLATFORM_SCHEMA, WeatherEntity)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, TEMP_CELSIUS,
|
CONF_API_KEY, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, TEMP_CELSIUS,
|
||||||
TEMP_FAHRENHEIT)
|
TEMP_FAHRENHEIT)
|
||||||
@ -25,6 +26,22 @@ _LOGGER = logging.getLogger(__name__)
|
|||||||
|
|
||||||
ATTRIBUTION = "Powered by Dark Sky"
|
ATTRIBUTION = "Powered by Dark Sky"
|
||||||
|
|
||||||
|
MAP_CONDITION = {
|
||||||
|
'clear-day': 'sunny',
|
||||||
|
'clear-night': 'clear-night',
|
||||||
|
'rain': 'rainy',
|
||||||
|
'snow': 'snowy',
|
||||||
|
'sleet': 'snowy-rainy',
|
||||||
|
'wind': 'windy',
|
||||||
|
'fog': 'fog',
|
||||||
|
'cloudy': 'cloudy',
|
||||||
|
'partly-cloudy-day': 'partlycloudy',
|
||||||
|
'partly-cloudy-night': 'partlycloudy',
|
||||||
|
'hail': 'hail',
|
||||||
|
'thunderstorm': 'lightning',
|
||||||
|
'tornado': None,
|
||||||
|
}
|
||||||
|
|
||||||
CONF_UNITS = 'units'
|
CONF_UNITS = 'units'
|
||||||
|
|
||||||
DEFAULT_NAME = 'Dark Sky'
|
DEFAULT_NAME = 'Dark Sky'
|
||||||
@ -108,7 +125,7 @@ class DarkSkyWeather(WeatherEntity):
|
|||||||
@property
|
@property
|
||||||
def condition(self):
|
def condition(self):
|
||||||
"""Return the weather condition."""
|
"""Return the weather condition."""
|
||||||
return self._ds_currently.get('summary')
|
return MAP_CONDITION.get(self._ds_currently.get('icon'))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def forecast(self):
|
def forecast(self):
|
||||||
@ -116,8 +133,11 @@ class DarkSkyWeather(WeatherEntity):
|
|||||||
return [{
|
return [{
|
||||||
ATTR_FORECAST_TIME:
|
ATTR_FORECAST_TIME:
|
||||||
datetime.fromtimestamp(entry.d.get('time')).isoformat(),
|
datetime.fromtimestamp(entry.d.get('time')).isoformat(),
|
||||||
ATTR_FORECAST_TEMP: entry.d.get('temperature')}
|
ATTR_FORECAST_TEMP:
|
||||||
for entry in self._ds_hourly.data]
|
entry.d.get('temperature'),
|
||||||
|
ATTR_FORECAST_CONDITION:
|
||||||
|
MAP_CONDITION.get(entry.d.get('icon'))
|
||||||
|
} for entry in self._ds_hourly.data]
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Get the latest data from Dark Sky."""
|
"""Get the latest data from Dark Sky."""
|
||||||
|
@ -48,4 +48,4 @@ class TestDarkSky(unittest.TestCase):
|
|||||||
self.assertEqual(mock_get_forecast.call_count, 1)
|
self.assertEqual(mock_get_forecast.call_count, 1)
|
||||||
|
|
||||||
state = self.hass.states.get('weather.test')
|
state = self.hass.states.get('weather.test')
|
||||||
self.assertEqual(state.state, 'Clear')
|
self.assertEqual(state.state, 'sunny')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user