async def test_register_then_add_devices(hass): """Test that add_devices work after register_add_entities.""" host = "1.2.3.4" entry = MockConfigEntry(domain=dynalite.DOMAIN, data={dynalite.CONF_HOST: host}) entry.add_to_hass(hass) with patch("homeassistant.components.dynalite.bridge.DynaliteDevices" ) as mock_dyn_dev: mock_dyn_dev().async_setup = CoroutineMock(return_value=True) assert await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() new_device_func = mock_dyn_dev.mock_calls[1][2]["new_device_func"] # Now with devices device1 = Mock() device1.category = "light" device1.name = "NAME" device1.unique_id = "unique1" device2 = Mock() device2.category = "switch" device2.name = "NAME2" device2.unique_id = "unique2" new_device_func([device1, device2]) await hass.async_block_till_done() assert hass.states.get("light.name") assert hass.states.get("switch.name2")
def create_mock_device(platform, spec): """Create a dynalite mock device for a platform according to a spec.""" device = Mock(spec=spec) device.category = platform device.unique_id = "UNIQUE" device.name = "NAME" device.device_class = "Device Class" return device