From f807a3a89050ed83655ed6bca09d9c8a1acdb0ac Mon Sep 17 00:00:00 2001 From: Ryan Bahm Date: Sat, 14 Oct 2017 11:45:32 -0700 Subject: [PATCH] Darksky enhancements (#9851) * Correct capitalization inconsistency in DarkSky All two-word sensors ("Precip Intensity," "Nearest Storm Bearing," etc) in Darksky uses title case for the friendly name of the sensor, with the exception of "Dew point." * Implement UV Index in Darksky * Fixed whitespace for Tox compliance * Add unit for UV Index. Per recommendation of reviewer, added 'UV Index' as a CONST in const.py, then used that const in both DarkSky and ISY994. It looks like BloomSky might also support UV Index and it should probably be standardized. --- homeassistant/components/sensor/darksky.py | 10 +++++++--- homeassistant/components/sensor/isy994.py | 4 ++-- homeassistant/const.py | 3 +++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/sensor/darksky.py b/homeassistant/components/sensor/darksky.py index a10a276bf0f..39a258c5e6a 100644 --- a/homeassistant/components/sensor/darksky.py +++ b/homeassistant/components/sensor/darksky.py @@ -14,7 +14,7 @@ from requests.exceptions import ConnectionError as ConnectError, \ from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.const import ( CONF_API_KEY, CONF_NAME, CONF_MONITORED_CONDITIONS, ATTR_ATTRIBUTION, - CONF_LATITUDE, CONF_LONGITUDE) + CONF_LATITUDE, CONF_LONGITUDE, UNIT_UV_INDEX) from homeassistant.helpers.entity import Entity from homeassistant.util import Throttle import homeassistant.helpers.config_validation as cv @@ -62,7 +62,7 @@ SENSOR_TYPES = { 'apparent_temperature': ['Apparent Temperature', '°C', '°F', '°C', '°C', '°C', 'mdi:thermometer', ['currently', 'hourly']], - 'dew_point': ['Dew point', '°C', '°F', '°C', '°C', '°C', + 'dew_point': ['Dew Point', '°C', '°F', '°C', '°C', '°C', 'mdi:thermometer', ['currently', 'hourly', 'daily']], 'wind_speed': ['Wind Speed', 'm/s', 'mph', 'km/h', 'mph', 'mph', 'mdi:weather-windy', ['currently', 'hourly', 'daily']], @@ -96,6 +96,10 @@ SENSOR_TYPES = { 'precip_intensity_max': ['Daily Max Precip Intensity', 'mm', 'in', 'mm', 'mm', 'mm', 'mdi:thermometer', ['currently', 'hourly', 'daily']], + 'uv_index': ['UV Index', + UNIT_UV_INDEX, UNIT_UV_INDEX, UNIT_UV_INDEX, + UNIT_UV_INDEX, UNIT_UV_INDEX, 'mdi:weather-sunny', + ['currently', 'hourly', 'daily']], } CONDITION_PICTURES = { @@ -305,7 +309,7 @@ class DarkSkySensor(Entity): 'temperature_min', 'temperature_max', 'apparent_temperature_min', 'apparent_temperature_max', - 'pressure', 'ozone']): + 'pressure', 'ozone', 'uvIndex']): return round(state, 1) return state diff --git a/homeassistant/components/sensor/isy994.py b/homeassistant/components/sensor/isy994.py index 57995a831f3..f64fa6191e2 100644 --- a/homeassistant/components/sensor/isy994.py +++ b/homeassistant/components/sensor/isy994.py @@ -9,7 +9,7 @@ from typing import Callable # noqa import homeassistant.components.isy994 as isy from homeassistant.const import ( - TEMP_CELSIUS, TEMP_FAHRENHEIT, STATE_OFF, STATE_ON) + TEMP_CELSIUS, TEMP_FAHRENHEIT, STATE_OFF, STATE_ON, UNIT_UV_INDEX) from homeassistant.helpers.typing import ConfigType _LOGGER = logging.getLogger(__name__) @@ -77,7 +77,7 @@ UOM_FRIENDLY_NAME = { '64': 'shindo', '65': 'SML', '69': 'gal', - '71': 'UV index', + '71': UNIT_UV_INDEX, '72': 'V', '73': 'W', '74': 'W/m²', diff --git a/homeassistant/const.py b/homeassistant/const.py index 2e3aeb4c334..349261242d5 100644 --- a/homeassistant/const.py +++ b/homeassistant/const.py @@ -279,6 +279,9 @@ MASS_KILOGRAMS = 'kg' # type: str MASS_OUNCES = 'oz' # type: str MASS_POUNDS = 'lb' # type: str +# UV Index units +UNIT_UV_INDEX = 'UV index' # type: str + # Contains the information that is discovered ATTR_DISCOVERED = 'discovered'