mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 13:15:18 +02:00
Fix style errors from previous commit, fix test since adding daily for all supported types
This commit is contained in:
@@ -35,9 +35,11 @@ SENSOR_TYPES = {
|
||||
'summary': ['Summary', None, None, None, None, None, None, []],
|
||||
'minutely_summary': ['Minutely Summary',
|
||||
None, None, None, None, None, None, []],
|
||||
'hourly_summary': ['Hourly Summary', None, None, None, None, None, None, []],
|
||||
'hourly_summary': ['Hourly Summary', None, None, None, None, None, None,
|
||||
[]],
|
||||
'daily_summary': ['Daily Summary', None, None, None, None, None, None, []],
|
||||
'icon': ['Icon', None, None, None, None, None, None, ['currently', 'hourly', 'daily']],
|
||||
'icon': ['Icon', None, None, None, None, None, None,
|
||||
['currently', 'hourly', 'daily']],
|
||||
'nearest_storm_distance': ['Nearest Storm Distance',
|
||||
'km', 'm', 'km', 'km', 'm',
|
||||
'mdi:weather-lightning', ['currently']],
|
||||
@@ -45,7 +47,8 @@ SENSOR_TYPES = {
|
||||
'°', '°', '°', '°', '°',
|
||||
'mdi:weather-lightning', ['currently']],
|
||||
'precip_type': ['Precip', None, None, None, None, None,
|
||||
'mdi:weather-pouring', ['currently', 'minutely', 'hourly', 'daily']],
|
||||
'mdi:weather-pouring',
|
||||
['currently', 'minutely', 'hourly', 'daily']],
|
||||
'precip_intensity': ['Precip Intensity',
|
||||
'mm', 'in', 'mm', 'mm', 'mm', 'mdi:weather-rainy',
|
||||
['currently', 'minutely', 'hourly', 'daily']],
|
||||
@@ -65,7 +68,8 @@ SENSOR_TYPES = {
|
||||
'wind_bearing': ['Wind Bearing', '°', '°', '°', '°', '°', 'mdi:compass',
|
||||
['currently', 'hourly', 'daily']],
|
||||
'cloud_cover': ['Cloud Coverage', '%', '%', '%', '%', '%',
|
||||
'mdi:weather-partlycloudy', ['currently', 'hourly', 'daily']],
|
||||
'mdi:weather-partlycloudy',
|
||||
['currently', 'hourly', 'daily']],
|
||||
'humidity': ['Humidity', '%', '%', '%', '%', '%', 'mdi:water-percent',
|
||||
['currently', 'hourly', 'daily']],
|
||||
'pressure': ['Pressure', 'mbar', 'mbar', 'mbar', 'mbar', 'mbar',
|
||||
@@ -80,7 +84,8 @@ SENSOR_TYPES = {
|
||||
['currently', 'hourly', 'daily']],
|
||||
'apparent_temperature_min': ['Daily Low Apparent Temperature',
|
||||
'°C', '°F', '°C', '°C', '°C',
|
||||
'mdi:thermometer', ['currently', 'hourly', 'daily']],
|
||||
'mdi:thermometer',
|
||||
['currently', 'hourly', 'daily']],
|
||||
'temperature_max': ['Daily High Temperature',
|
||||
'°C', '°F', '°C', '°C', '°C', 'mdi:thermometer',
|
||||
['currently', 'hourly', 'daily']],
|
||||
@@ -100,7 +105,8 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
|
||||
vol.Optional(CONF_UNITS): vol.In(['auto', 'si', 'us', 'ca', 'uk', 'uk2']),
|
||||
vol.Optional(CONF_UPDATE_INTERVAL, default=timedelta(seconds=120)): (
|
||||
vol.All(cv.time_period, cv.positive_timedelta)),
|
||||
vol.Optional(CONF_FORECAST): vol.All(cv.ensure_list, [vol.Range(min=1, max=7)]),
|
||||
vol.Optional(CONF_FORECAST):
|
||||
vol.All(cv.ensure_list, [vol.Range(min=1, max=7)]),
|
||||
})
|
||||
|
||||
|
||||
@@ -111,7 +117,6 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
_LOGGER.error("Latitude or longitude not set in Home Assistant config")
|
||||
return False
|
||||
|
||||
|
||||
if CONF_UNITS in config:
|
||||
units = config[CONF_UNITS]
|
||||
elif hass.config.units.is_metric:
|
||||
@@ -224,19 +229,21 @@ class DarkSkySensor(Entity):
|
||||
hourly = self.forecast_data.data_hourly
|
||||
self._state = getattr(hourly, 'summary', '')
|
||||
else:
|
||||
if self.forecast_day > 0 or self.type in ['daily_summary',
|
||||
if self.forecast_day > 0 or (
|
||||
self.type in ['daily_summary',
|
||||
'temperature_min',
|
||||
'temperature_max',
|
||||
'apparent_temperature_min',
|
||||
'apparent_temperature_max',
|
||||
'precip_intensity_max']:
|
||||
'precip_intensity_max']):
|
||||
self.forecast_data.update_daily()
|
||||
daily = self.forecast_data.data_daily
|
||||
if self.type == 'daily_summary':
|
||||
self._state = getattr(daily, 'summary', '')
|
||||
else:
|
||||
if hasattr(daily, 'data'):
|
||||
self._state = self.get_state(daily.data[self.forecast_day])
|
||||
self._state = self.get_state(
|
||||
daily.data[self.forecast_day])
|
||||
else:
|
||||
self._state = 0
|
||||
else:
|
||||
|
@@ -81,4 +81,4 @@ class TestDarkSkySetup(unittest.TestCase):
|
||||
darksky.setup_platform(self.hass, self.config, self.add_entities)
|
||||
self.assertTrue(mock_get_forecast.called)
|
||||
self.assertEqual(mock_get_forecast.call_count, 1)
|
||||
self.assertEqual(len(self.entities), 5)
|
||||
self.assertEqual(len(self.entities), 7)
|
||||
|
Reference in New Issue
Block a user