Add 'moon_phase' to Dark Sky sensor (#16179)
This commit is contained in:
parent
647b3ff0fe
commit
69cea6001f
1 changed files with 12 additions and 7 deletions
|
@ -33,10 +33,12 @@ DEFAULT_LANGUAGE = 'en'
|
||||||
|
|
||||||
DEFAULT_NAME = 'Dark Sky'
|
DEFAULT_NAME = 'Dark Sky'
|
||||||
|
|
||||||
DEPRECATED_SENSOR_TYPES = {'apparent_temperature_max',
|
DEPRECATED_SENSOR_TYPES = {
|
||||||
'apparent_temperature_min',
|
'apparent_temperature_max',
|
||||||
'temperature_max',
|
'apparent_temperature_min',
|
||||||
'temperature_min'}
|
'temperature_max',
|
||||||
|
'temperature_min',
|
||||||
|
}
|
||||||
|
|
||||||
# Sensor types are defined like so:
|
# Sensor types are defined like so:
|
||||||
# Name, si unit, us unit, ca unit, uk unit, uk2 unit
|
# Name, si unit, us unit, ca unit, uk unit, uk2 unit
|
||||||
|
@ -125,6 +127,8 @@ SENSOR_TYPES = {
|
||||||
UNIT_UV_INDEX, UNIT_UV_INDEX, UNIT_UV_INDEX,
|
UNIT_UV_INDEX, UNIT_UV_INDEX, UNIT_UV_INDEX,
|
||||||
UNIT_UV_INDEX, UNIT_UV_INDEX, 'mdi:weather-sunny',
|
UNIT_UV_INDEX, UNIT_UV_INDEX, 'mdi:weather-sunny',
|
||||||
['currently', 'hourly', 'daily']],
|
['currently', 'hourly', 'daily']],
|
||||||
|
'moon_phase': ['Moon Phase', None, None, None, None, None,
|
||||||
|
'mdi:weather-night', ['daily']],
|
||||||
}
|
}
|
||||||
|
|
||||||
CONDITION_PICTURES = {
|
CONDITION_PICTURES = {
|
||||||
|
@ -203,7 +207,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]:
|
||||||
|
@ -316,7 +320,8 @@ class DarkSkySensor(Entity):
|
||||||
'apparent_temperature_max',
|
'apparent_temperature_max',
|
||||||
'apparent_temperature_high',
|
'apparent_temperature_high',
|
||||||
'precip_intensity_max',
|
'precip_intensity_max',
|
||||||
'precip_accumulation']):
|
'precip_accumulation',
|
||||||
|
'moon_phase']):
|
||||||
self.forecast_data.update_daily()
|
self.forecast_data.update_daily()
|
||||||
daily = self.forecast_data.data_daily
|
daily = self.forecast_data.data_daily
|
||||||
if self.type == 'daily_summary':
|
if self.type == 'daily_summary':
|
||||||
|
@ -407,7 +412,7 @@ class DarkSkyData:
|
||||||
self._api_key, self.latitude, self.longitude, units=self.units,
|
self._api_key, self.latitude, self.longitude, units=self.units,
|
||||||
lang=self.language)
|
lang=self.language)
|
||||||
except (ConnectError, HTTPError, Timeout, ValueError) as error:
|
except (ConnectError, HTTPError, Timeout, ValueError) as error:
|
||||||
_LOGGER.error("Unable to connect to Dark Sky. %s", error)
|
_LOGGER.error("Unable to connect to Dark Sky: %s", error)
|
||||||
self.data = None
|
self.data = None
|
||||||
self.unit_system = self.data and self.data.json['flags']['units']
|
self.unit_system = self.data and self.data.json['flags']['units']
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue