diff --git a/homeassistant/components/ambient_station/__init__.py b/homeassistant/components/ambient_station/__init__.py index 58389dd1831..c61e15dfeb5 100644 --- a/homeassistant/components/ambient_station/__init__.py +++ b/homeassistant/components/ambient_station/__init__.py @@ -26,6 +26,7 @@ from homeassistant.helpers.event import async_call_later from .config_flow import configured_instances from .const import ( ATTR_LAST_DATA, + ATTR_MONITORED_CONDITIONS, CONF_APP_KEY, DATA_CLIENT, DOMAIN, @@ -341,7 +342,6 @@ class AmbientStation: self._watchdog_listener = None self._ws_reconnect_delay = DEFAULT_SOCKET_MIN_RETRY self.client = client - self.monitored_conditions = [] self.stations = {} async def _attempt_connect(self): @@ -398,19 +398,19 @@ class AmbientStation: _LOGGER.debug("New station subscription: %s", data) - self.monitored_conditions = [ + # Only create entities based on the data coming through the socket. + # If the user is monitoring brightness (in W/m^2), make sure we also + # add a calculated sensor for the same data measured in lx: + monitored_conditions = [ k for k in station["lastData"] if k in SENSOR_TYPES ] - - # If the user is monitoring brightness (in W/m^2), - # make sure we also add a calculated sensor for the - # same data measured in lx: - if TYPE_SOLARRADIATION in self.monitored_conditions: - self.monitored_conditions.append(TYPE_SOLARRADIATION_LX) + if TYPE_SOLARRADIATION in monitored_conditions: + monitored_conditions.append(TYPE_SOLARRADIATION_LX) self.stations[station["macAddress"]] = { ATTR_LAST_DATA: station["lastData"], ATTR_LOCATION: station.get("info", {}).get("location"), + ATTR_MONITORED_CONDITIONS: monitored_conditions, ATTR_NAME: station.get("info", {}).get( "name", station["macAddress"] ), diff --git a/homeassistant/components/ambient_station/binary_sensor.py b/homeassistant/components/ambient_station/binary_sensor.py index 3f02eb9f1e8..1ed6dbd0db4 100644 --- a/homeassistant/components/ambient_station/binary_sensor.py +++ b/homeassistant/components/ambient_station/binary_sensor.py @@ -19,7 +19,13 @@ from . import ( TYPE_BATTOUT, AmbientWeatherEntity, ) -from .const import ATTR_LAST_DATA, DATA_CLIENT, DOMAIN, TYPE_BINARY_SENSOR +from .const import ( + ATTR_LAST_DATA, + ATTR_MONITORED_CONDITIONS, + DATA_CLIENT, + DOMAIN, + TYPE_BINARY_SENSOR, +) _LOGGER = logging.getLogger(__name__) @@ -35,7 +41,7 @@ async def async_setup_entry(hass, entry, async_add_entities): binary_sensor_list = [] for mac_address, station in ambient.stations.items(): - for condition in ambient.monitored_conditions: + for condition in station[ATTR_MONITORED_CONDITIONS]: name, _, kind, device_class = SENSOR_TYPES[condition] if kind == TYPE_BINARY_SENSOR: binary_sensor_list.append( diff --git a/homeassistant/components/ambient_station/const.py b/homeassistant/components/ambient_station/const.py index b2df34f2f28..21a6e514b30 100644 --- a/homeassistant/components/ambient_station/const.py +++ b/homeassistant/components/ambient_station/const.py @@ -2,6 +2,7 @@ DOMAIN = "ambient_station" ATTR_LAST_DATA = "last_data" +ATTR_MONITORED_CONDITIONS = "monitored_conditions" CONF_APP_KEY = "app_key" diff --git a/homeassistant/components/ambient_station/sensor.py b/homeassistant/components/ambient_station/sensor.py index 56425221e0d..0120799d6f2 100644 --- a/homeassistant/components/ambient_station/sensor.py +++ b/homeassistant/components/ambient_station/sensor.py @@ -9,7 +9,13 @@ from . import ( TYPE_SOLARRADIATION_LX, AmbientWeatherEntity, ) -from .const import ATTR_LAST_DATA, DATA_CLIENT, DOMAIN, TYPE_SENSOR +from .const import ( + ATTR_LAST_DATA, + ATTR_MONITORED_CONDITIONS, + DATA_CLIENT, + DOMAIN, + TYPE_SENSOR, +) _LOGGER = logging.getLogger(__name__) @@ -25,7 +31,7 @@ async def async_setup_entry(hass, entry, async_add_entities): sensor_list = [] for mac_address, station in ambient.stations.items(): - for condition in ambient.monitored_conditions: + for condition in station[ATTR_MONITORED_CONDITIONS]: name, unit, kind, device_class = SENSOR_TYPES[condition] if kind == TYPE_SENSOR: sensor_list.append(