mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
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
@ -98,7 +98,7 @@ async def discover_devices(hass, hass_config):
|
|||||||
|
|
||||||
Currently it is only run at startup.
|
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():
|
for server_name, server in hass.data[DOMAIN][SUPLA_SERVERS].items():
|
||||||
|
|
||||||
@ -146,13 +146,12 @@ async def discover_devices(hass, hass_config):
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
channel["server_name"] = server_name
|
channel["server_name"] = server_name
|
||||||
component_configs.setdefault(component_name, []).append(
|
component_config = component_configs.setdefault(component_name, {})
|
||||||
{
|
component_config[f"{server_name}_{channel_id}"] = {
|
||||||
"channel_id": channel_id,
|
"channel_id": channel_id,
|
||||||
"server_name": server_name,
|
"server_name": server_name,
|
||||||
"function_name": channel["function"]["name"],
|
"function_name": channel["function"]["name"],
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
# Load discovered devices
|
# Load discovered devices
|
||||||
for component_name, config in component_configs.items():
|
for component_name, config in component_configs.items():
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
"""Support for Supla cover - curtains, rollershutters, entry gate etc."""
|
"""Support for Supla cover - curtains, rollershutters, entry gate etc."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
|
||||||
from homeassistant.components.cover import ATTR_POSITION, CoverDeviceClass, CoverEntity
|
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
|
from . import DOMAIN, SUPLA_COORDINATORS, SUPLA_SERVERS, SuplaChannel
|
||||||
|
|
||||||
@ -12,15 +17,20 @@ SUPLA_SHUTTER = "CONTROLLINGTHEROLLERSHUTTER"
|
|||||||
SUPLA_GATE = "CONTROLLINGTHEGATE"
|
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."""
|
"""Set up the Supla covers."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
_LOGGER.debug("Discovery: %s", pformat(discovery_info))
|
_LOGGER.debug("Discovery: %s", pformat(discovery_info))
|
||||||
|
|
||||||
entities = []
|
entities: list[CoverEntity] = []
|
||||||
for device in discovery_info:
|
for device in discovery_info.values():
|
||||||
device_name = device["function_name"]
|
device_name = device["function_name"]
|
||||||
server_name = device["server_name"]
|
server_name = device["server_name"]
|
||||||
|
|
||||||
|
@ -1,15 +1,25 @@
|
|||||||
"""Support for Supla switch."""
|
"""Support for Supla switch."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
|
|
||||||
from homeassistant.components.switch import SwitchEntity
|
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
|
from . import DOMAIN, SUPLA_COORDINATORS, SUPLA_SERVERS, SuplaChannel
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_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."""
|
"""Set up the Supla switches."""
|
||||||
if discovery_info is None:
|
if discovery_info is None:
|
||||||
return
|
return
|
||||||
@ -17,7 +27,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
|
|||||||
_LOGGER.debug("Discovery: %s", pformat(discovery_info))
|
_LOGGER.debug("Discovery: %s", pformat(discovery_info))
|
||||||
|
|
||||||
entities = []
|
entities = []
|
||||||
for device in discovery_info:
|
for device in discovery_info.values():
|
||||||
server_name = device["server_name"]
|
server_name = device["server_name"]
|
||||||
|
|
||||||
entities.append(
|
entities.append(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user