def pywemo_bridge_light_fixture(pywemo_device): """Fixture for Bridge.Light WeMoDevice instances.""" light = create_autospec(pywemo.ouimeaux_device.bridge.Light) light.uniqueID = pywemo_device.serialnumber light.name = pywemo_device.name pywemo_device.Lights = {pywemo_device.serialnumber: light} return light
def create_device(counter): """Create a unique mock Motion detector device for each counter value.""" device = create_autospec(pywemo.Motion, instance=True) device.host = f"{MOCK_HOST}_{counter}" device.port = MOCK_PORT + counter device.name = f"{MOCK_NAME}_{counter}" device.serialnumber = f"{MOCK_SERIAL_NUMBER}_{counter}" device.model_name = "Motion" device.get_state.return_value = 0 # Default to Off return device
def pywemo_device_fixture(pywemo_registry, pywemo_model): """Fixture for WeMoDevice instances.""" device = create_autospec(getattr(pywemo, pywemo_model)) device.host = MOCK_HOST device.port = MOCK_PORT device.name = MOCK_NAME device.serialnumber = MOCK_SERIAL_NUMBER device.model_name = pywemo_model url = f"http://{MOCK_HOST}:{MOCK_PORT}/setup.xml" with patch("pywemo.setup_url_for_address", return_value=url), patch( "pywemo.discovery.device_from_description", return_value=device): yield device
def pywemo_registry_fixture(): """Fixture for SubscriptionRegistry instances.""" registry = create_autospec(pywemo.SubscriptionRegistry) registry.callbacks = {} def on_func(device, type_filter, callback): registry.callbacks[device.name] = callback registry.on.side_effect = on_func with patch("pywemo.SubscriptionRegistry", return_value=registry): yield registry
def pywemo_registry_fixture(): """Fixture for SubscriptionRegistry instances.""" registry = create_autospec(pywemo.SubscriptionRegistry, instance=True) registry.callbacks = {} registry.semaphore = asyncio.Semaphore(value=0) def on_func(device, type_filter, callback): registry.callbacks[device.name] = callback registry.semaphore.release() registry.on.side_effect = on_func with patch("pywemo.SubscriptionRegistry", return_value=registry): yield registry