hass-core/homeassistant/components/switcher_kis/utils.py
YogevBokobza 3e1da876c6
Add Switcher Runner S11 support (#123578)
* switcher start s11 integration

* switcher linting

* switcher starting reauth logic

* switcher fix linting

* switcher fix linting

* switcher remove get_circuit_number

* switcher adding support for validate token

* switcher fix initial auth for new devices and fix strings

* switcher fix linting

* switcher fix utils

* Revert "switcher fix utils"

This reverts commit b162a943b94fb0a581140feb21fe871df578c16a.

* switcher revert and test

* switcher fix validate logic and strings

* switcher add tests to improve coverage

* switcher adding tests

* switcher adding test

* switcher revert back things

* switcher fix based on requested changes

* switcher tests fixes

* switcher fix based on requested changes

* switcher remove single_instance_allowed code and added tests

* Update config_flow.py

* switcher fix comment

* switcher fix tests

* switcher lint

* switcehr fix based on requested changes

* switche fix lint

* switcher small rename fix

* switcher fix based on requested changes

* switcher fix based on requested changes

* switcher fix based on requested changes

* Update tests/components/switcher_kis/test_config_flow.py

Co-authored-by: Shay Levy <levyshay1@gmail.com>

* Update tests/components/switcher_kis/test_config_flow.py

Co-authored-by: Shay Levy <levyshay1@gmail.com>

* Update tests/components/switcher_kis/test_config_flow.py

Co-authored-by: Shay Levy <levyshay1@gmail.com>

* Update tests/components/switcher_kis/test_config_flow.py

---------

Co-authored-by: Shay Levy <levyshay1@gmail.com>
2024-09-20 23:19:57 +03:00

44 lines
1.3 KiB
Python

"""Switcher integration helpers functions."""
from __future__ import annotations
import asyncio
import logging
from aioswitcher.api.remotes import SwitcherBreezeRemoteManager
from aioswitcher.bridge import SwitcherBase, SwitcherBridge
from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers import singleton
from .const import DISCOVERY_TIME_SEC
_LOGGER = logging.getLogger(__name__)
async def async_discover_devices() -> dict[str, SwitcherBase]:
"""Discover Switcher devices."""
_LOGGER.debug("Starting discovery")
discovered_devices = {}
@callback
def on_device_data_callback(device: SwitcherBase) -> None:
"""Use as a callback for device data."""
if device.device_id in discovered_devices:
return
discovered_devices[device.device_id] = device
bridge = SwitcherBridge(on_device_data_callback)
await bridge.start()
await asyncio.sleep(DISCOVERY_TIME_SEC)
await bridge.stop()
_LOGGER.debug("Finished discovery, discovered devices: %s", len(discovered_devices))
return discovered_devices
@singleton.singleton("switcher_breeze_remote_manager")
def get_breeze_remote_manager(hass: HomeAssistant) -> SwitcherBreezeRemoteManager:
"""Get Switcher Breeze remote manager."""
return SwitcherBreezeRemoteManager()