async def test_warning_deprecated_connection_class(opp, caplog): """Test that we log a warning when the connection_class is used.""" discovery_function = Mock() with patch.dict(config_entries.HANDLERS): config_entry_flow.register_discovery_flow( "test", "Test", discovery_function, connection_class="local_polling") assert "integration is setting a connection_class" in caplog.text
def discovery_flow_conf(opp): """Register a handler.""" handler_conf = {"discovered": False} async def has_discovered_devices(opp): """Mock if we have discovered devices.""" return handler_conf["discovered"] with patch.dict(config_entries.HANDLERS): config_entry_flow.register_discovery_flow("test", "Test", has_discovered_devices) yield handler_conf
"""Config flow for Wemo.""" import pywemo from openpeerpower.helpers import config_entry_flow from . import DOMAIN async def _async_has_devices(opp): """Return if there are devices that can be discovered.""" return bool(await opp.async_add_executor_job(pywemo.discover_devices)) config_entry_flow.register_discovery_flow(DOMAIN, "Wemo", _async_has_devices)
"""Config flow for NEW_NAME.""" import my_pypi_dependency from openpeerpower import config_entries from openpeerpower.helpers import config_entry_flow from .const import DOMAIN async def _async_has_devices(opp) -> bool: """Return if there are devices that can be discovered.""" # TODO Check if there are any devices that can be discovered in the network. devices = await opp.async_add_executor_job(my_pypi_dependency.discover) return len(devices) > 0 config_entry_flow.register_discovery_flow( DOMAIN, "NEW_NAME", _async_has_devices, config_entries.CONN_CLASS_UNKNOWN )
"""Config flow for Gree.""" from greeclimate.discovery import Discovery from openpeerpower.helpers import config_entry_flow from .const import DISCOVERY_TIMEOUT, DOMAIN async def _async_has_devices(opp) -> bool: """Return if there are devices that can be discovered.""" gree_discovery = Discovery(DISCOVERY_TIMEOUT) devices = await gree_discovery.scan(wait_for=DISCOVERY_TIMEOUT) return len(devices) > 0 config_entry_flow.register_discovery_flow(DOMAIN, "Gree Climate", _async_has_devices)
async def _async_has_devices(opp): controller_ready = asyncio.Event() @callback def dispatch_discovered(_): controller_ready.set() async_dispatcher_connect(opp, DISPATCH_CONTROLLER_DISCOVERED, dispatch_discovered) disco = await async_start_discovery_service(opp) with suppress(asyncio.TimeoutError): async with timeout(TIMEOUT_DISCOVERY): await controller_ready.wait() if not disco.pi_disco.controllers: await async_stop_discovery_service(opp) _LOGGER.debug("No controllers found") return False _LOGGER.debug("Controllers %s", disco.pi_disco.controllers) return True config_entry_flow.register_discovery_flow(IZONE, "iZone Aircon", _async_has_devices)
"""Config flow for iOS.""" from openpeerpower.helpers import config_entry_flow from .const import DOMAIN config_entry_flow.register_discovery_flow( DOMAIN, "Open Peer Power iOS", lambda *_: True )
"""Config flow for TP-Link.""" from openpeerpower.helpers import config_entry_flow from .common import async_get_discoverable_devices from .const import DOMAIN config_entry_flow.register_discovery_flow( DOMAIN, "TP-Link Smart Home", async_get_discoverable_devices, )
"""Config flow for Hisense AEH-W4A1 integration.""" from pyaehw4a1.aehw4a1 import AehW4a1 from openpeerpower.helpers import config_entry_flow from .const import DOMAIN async def _async_has_devices(opp): """Return if there are devices that can be discovered.""" aehw4a1_ip_addresses = await AehW4a1().discovery() return len(aehw4a1_ip_addresses) > 0 config_entry_flow.register_discovery_flow(DOMAIN, "Hisense AEH-W4A1", _async_has_devices)