From 40fa4463de411a1092213a4c7cc9239982e8aef2 Mon Sep 17 00:00:00 2001 From: Aaron Bach Date: Fri, 21 Jun 2019 23:12:16 -0600 Subject: [PATCH] Change Ambient solar radiation units to lx (#24690) --- homeassistant/components/ambient_station/__init__.py | 2 +- homeassistant/components/ambient_station/sensor.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/ambient_station/__init__.py b/homeassistant/components/ambient_station/__init__.py index 44cc7655498bc0..40487040474377 100644 --- a/homeassistant/components/ambient_station/__init__.py +++ b/homeassistant/components/ambient_station/__init__.py @@ -183,7 +183,7 @@ TYPE_SOILTEMP7F: ('Soil Temp 7', '°F', TYPE_SENSOR, 'temperature'), TYPE_SOILTEMP8F: ('Soil Temp 8', '°F', TYPE_SENSOR, 'temperature'), TYPE_SOILTEMP9F: ('Soil Temp 9', '°F', TYPE_SENSOR, 'temperature'), - TYPE_SOLARRADIATION: ('Solar Rad', 'W/m^2', TYPE_SENSOR, None), + TYPE_SOLARRADIATION: ('Solar Rad', 'lx', TYPE_SENSOR, 'illuminance'), TYPE_TEMP10F: ('Temp 10', '°F', TYPE_SENSOR, 'temperature'), TYPE_TEMP1F: ('Temp 1', '°F', TYPE_SENSOR, 'temperature'), TYPE_TEMP2F: ('Temp 2', '°F', TYPE_SENSOR, 'temperature'), diff --git a/homeassistant/components/ambient_station/sensor.py b/homeassistant/components/ambient_station/sensor.py index 8d103a22a5e3af..dcab3d7e50edc6 100644 --- a/homeassistant/components/ambient_station/sensor.py +++ b/homeassistant/components/ambient_station/sensor.py @@ -3,7 +3,7 @@ from homeassistant.const import ATTR_NAME -from . import SENSOR_TYPES, AmbientWeatherEntity +from . import SENSOR_TYPES, TYPE_SOLARRADIATION, AmbientWeatherEntity from .const import ATTR_LAST_DATA, DATA_CLIENT, DOMAIN, TYPE_SENSOR _LOGGER = logging.getLogger(__name__) @@ -61,5 +61,13 @@ def unit_of_measurement(self): async def async_update(self): """Fetch new state data for the sensor.""" - self._state = self._ambient.stations[ + new_state = self._ambient.stations[ self._mac_address][ATTR_LAST_DATA].get(self._sensor_type) + + if self._sensor_type == TYPE_SOLARRADIATION: + # Ambient's units for solar radiation (illuminance) are + # W/m^2; since those aren't commonly used in the HASS + # world, transform them to lx: + self._state = round(float(new_state)/0.0079) + else: + self._state = new_state