Move list to dict in iperf3 discovery (#64204)
parent
99481e2258
commit
265ebd17a3
|
@ -118,7 +118,11 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
|||
|
||||
hass.async_create_task(
|
||||
async_load_platform(
|
||||
hass, SENSOR_DOMAIN, DOMAIN, conf[CONF_MONITORED_CONDITIONS], config
|
||||
hass,
|
||||
SENSOR_DOMAIN,
|
||||
DOMAIN,
|
||||
{CONF_MONITORED_CONDITIONS: conf[CONF_MONITORED_CONDITIONS]},
|
||||
config,
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
"""Support for Iperf3 sensors."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription
|
||||
from homeassistant.const import ATTR_ATTRIBUTION
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.const import ATTR_ATTRIBUTION, CONF_MONITORED_CONDITIONS
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import ATTR_VERSION, DATA_UPDATED, DOMAIN as IPERF3_DOMAIN, SENSOR_TYPES
|
||||
|
||||
|
@ -16,13 +20,21 @@ ATTR_REMOTE_HOST = "Remote Server"
|
|||
ATTR_REMOTE_PORT = "Remote Port"
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info):
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Iperf3 sensor."""
|
||||
if not discovery_info:
|
||||
return
|
||||
|
||||
entities = [
|
||||
Iperf3Sensor(iperf3_host, description)
|
||||
for iperf3_host in hass.data[IPERF3_DOMAIN].values()
|
||||
for description in SENSOR_TYPES
|
||||
if description.key in discovery_info
|
||||
if description.key in discovery_info[CONF_MONITORED_CONDITIONS]
|
||||
]
|
||||
async_add_entities(entities, True)
|
||||
|
||||
|
|
Loading…
Reference in New Issue