mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Fix sensor type creation with multiple Ambient weather stations (#30850)
This commit is contained in:
parent
7da84dca76
commit
9bfcd04a4f
@ -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"]
|
||||
),
|
||||
|
@ -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(
|
||||
|
@ -2,6 +2,7 @@
|
||||
DOMAIN = "ambient_station"
|
||||
|
||||
ATTR_LAST_DATA = "last_data"
|
||||
ATTR_MONITORED_CONDITIONS = "monitored_conditions"
|
||||
|
||||
CONF_APP_KEY = "app_key"
|
||||
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user