Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions homeassistant/components/ambient_station/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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"]
),
Expand Down
10 changes: 8 additions & 2 deletions homeassistant/components/ambient_station/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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(
Expand Down
1 change: 1 addition & 0 deletions homeassistant/components/ambient_station/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
DOMAIN = "ambient_station"

ATTR_LAST_DATA = "last_data"
ATTR_MONITORED_CONDITIONS = "monitored_conditions"

CONF_APP_KEY = "app_key"

Expand Down
10 changes: 8 additions & 2 deletions homeassistant/components/ambient_station/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand All @@ -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(
Expand Down