Move list to dict in supla discovery (#63805)
* Move list to dict in supla discovery * Adjust key Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
parent
65f21891db
commit
3763407046
3 changed files with 32 additions and 13 deletions
|
@ -98,7 +98,7 @@ async def discover_devices(hass, hass_config):
|
|||
|
||||
Currently it is only run at startup.
|
||||
"""
|
||||
component_configs: dict[Platform, list[dict]] = {}
|
||||
component_configs: dict[Platform, dict[str, dict]] = {}
|
||||
|
||||
for server_name, server in hass.data[DOMAIN][SUPLA_SERVERS].items():
|
||||
|
||||
|
@ -146,13 +146,12 @@ async def discover_devices(hass, hass_config):
|
|||
continue
|
||||
|
||||
channel["server_name"] = server_name
|
||||
component_configs.setdefault(component_name, []).append(
|
||||
{
|
||||
"channel_id": channel_id,
|
||||
"server_name": server_name,
|
||||
"function_name": channel["function"]["name"],
|
||||
}
|
||||
)
|
||||
component_config = component_configs.setdefault(component_name, {})
|
||||
component_config[f"{server_name}_{channel_id}"] = {
|
||||
"channel_id": channel_id,
|
||||
"server_name": server_name,
|
||||
"function_name": channel["function"]["name"],
|
||||
}
|
||||
|
||||
# Load discovered devices
|
||||
for component_name, config in component_configs.items():
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
"""Support for Supla cover - curtains, rollershutters, entry gate etc."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from pprint import pformat
|
||||
|
||||
from homeassistant.components.cover import ATTR_POSITION, CoverDeviceClass, CoverEntity
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN, SUPLA_COORDINATORS, SUPLA_SERVERS, SuplaChannel
|
||||
|
||||
|
@ -12,15 +17,20 @@ SUPLA_SHUTTER = "CONTROLLINGTHEROLLERSHUTTER"
|
|||
SUPLA_GATE = "CONTROLLINGTHEGATE"
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Supla covers."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
||||
_LOGGER.debug("Discovery: %s", pformat(discovery_info))
|
||||
|
||||
entities = []
|
||||
for device in discovery_info:
|
||||
entities: list[CoverEntity] = []
|
||||
for device in discovery_info.values():
|
||||
device_name = device["function_name"]
|
||||
server_name = device["server_name"]
|
||||
|
||||
|
|
|
@ -1,15 +1,25 @@
|
|||
"""Support for Supla switch."""
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from pprint import pformat
|
||||
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
|
||||
from . import DOMAIN, SUPLA_COORDINATORS, SUPLA_SERVERS, SuplaChannel
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the Supla switches."""
|
||||
if discovery_info is None:
|
||||
return
|
||||
|
@ -17,7 +27,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||
_LOGGER.debug("Discovery: %s", pformat(discovery_info))
|
||||
|
||||
entities = []
|
||||
for device in discovery_info:
|
||||
for device in discovery_info.values():
|
||||
server_name = device["server_name"]
|
||||
|
||||
entities.append(
|
||||
|
|
Loading…
Add table
Reference in a new issue