diff --git a/homeassistant/components/ambient_station/__init__.py b/homeassistant/components/ambient_station/__init__.py index 58389dd183189e..c61e15dfeb5731 100644 --- a/homeassistant/components/ambient_station/__init__.py +++ b/homeassistant/components/ambient_station/__init__.py @@ -26,6 +26,7 @@ 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 @@ def __init__(self, hass, config_entry, client): 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 @@ def on_subscribed(data): _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 3f02eb9f1e8282..1ed6dbd0db4aa0 100644 --- a/homeassistant/components/ambient_station/binary_sensor.py +++ b/homeassistant/components/ambient_station/binary_sensor.py @@ -19,7 +19,13 @@ 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 b2df34f2f28e34..21a6e514b3073e 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 56425221e0d334..0120799d6f2bfb 100644 --- a/homeassistant/components/ambient_station/sensor.py +++ b/homeassistant/components/ambient_station/sensor.py @@ -9,7 +9,13 @@ 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(