async def test_get_entries(hass, client): """Test get entries.""" with patch.dict(HANDLERS, clear=True): @HANDLERS.register("comp1") class Comp1ConfigFlow: """Config flow with options flow.""" @staticmethod @callback def async_get_options_flow(config, options): """Get options flow.""" pass hass.helpers.config_entry_flow.register_discovery_flow( "comp2", "Comp 2", lambda: None, core_ce.CONN_CLASS_ASSUMED) entry = MockConfigEntry( domain="comp1", title="Test 1", source="bla", connection_class=core_ce.CONN_CLASS_LOCAL_POLL, ) entry.supports_unload = True entry.add_to_hass(hass) MockConfigEntry( domain="comp2", title="Test 2", source="bla2", state=core_ce.ENTRY_STATE_LOADED, connection_class=core_ce.CONN_CLASS_ASSUMED, ).add_to_hass(hass) resp = await client.get("/api/config/config_entries/entry") assert resp.status == 200 data = await resp.json() for entry in data: entry.pop("entry_id") assert data == [ { "domain": "comp1", "title": "Test 1", "source": "bla", "state": "not_loaded", "connection_class": "local_poll", "supports_options": True, "supports_unload": True, }, { "domain": "comp2", "title": "Test 2", "source": "bla2", "state": "loaded", "connection_class": "assumed", "supports_options": False, "supports_unload": False, }, ]
async def test_get_entries(hass, client): """Test get entries.""" with patch.dict(HANDLERS, clear=True): @HANDLERS.register("comp1") class Comp1ConfigFlow: """Config flow with options flow.""" @staticmethod @callback def async_get_options_flow(config, options): """Get options flow.""" pass hass.helpers.config_entry_flow.register_discovery_flow( "comp2", "Comp 2", lambda: None ) entry = MockConfigEntry( domain="comp1", title="Test 1", source="bla", ) entry.supports_unload = True entry.add_to_hass(hass) MockConfigEntry( domain="comp2", title="Test 2", source="bla2", state=core_ce.ConfigEntryState.SETUP_ERROR, reason="Unsupported API", ).add_to_hass(hass) MockConfigEntry( domain="comp3", title="Test 3", source="bla3", disabled_by=core_ce.DISABLED_USER, ).add_to_hass(hass) resp = await client.get("/api/config/config_entries/entry") assert resp.status == HTTPStatus.OK data = await resp.json() for entry in data: entry.pop("entry_id") assert data == [ { "domain": "comp1", "title": "Test 1", "source": "bla", "state": core_ce.ConfigEntryState.NOT_LOADED.value, "supports_options": True, "supports_unload": True, "pref_disable_new_entities": False, "pref_disable_polling": False, "disabled_by": None, "reason": None, }, { "domain": "comp2", "title": "Test 2", "source": "bla2", "state": core_ce.ConfigEntryState.SETUP_ERROR.value, "supports_options": False, "supports_unload": False, "pref_disable_new_entities": False, "pref_disable_polling": False, "disabled_by": None, "reason": "Unsupported API", }, { "domain": "comp3", "title": "Test 3", "source": "bla3", "state": core_ce.ConfigEntryState.NOT_LOADED.value, "supports_options": False, "supports_unload": False, "pref_disable_new_entities": False, "pref_disable_polling": False, "disabled_by": core_ce.DISABLED_USER, "reason": None, }, ]
async def test_get_entries(hass, client, clear_handlers): """Test get entries.""" mock_integration(hass, MockModule("comp1")) mock_integration( hass, MockModule("comp2", partial_manifest={"integration_type": "helper"})) mock_integration(hass, MockModule("comp3")) @HANDLERS.register("comp1") class Comp1ConfigFlow: """Config flow with options flow.""" @staticmethod @callback def async_get_options_flow(config_entry): """Get options flow.""" pass @classmethod @callback def async_supports_options_flow(cls, config_entry): """Return options flow support for this handler.""" return True config_entry_flow.register_discovery_flow("comp2", "Comp 2", lambda: None) entry = MockConfigEntry( domain="comp1", title="Test 1", source="bla", ) entry.supports_unload = True entry.add_to_hass(hass) MockConfigEntry( domain="comp2", title="Test 2", source="bla2", state=core_ce.ConfigEntryState.SETUP_ERROR, reason="Unsupported API", ).add_to_hass(hass) MockConfigEntry( domain="comp3", title="Test 3", source="bla3", disabled_by=core_ce.ConfigEntryDisabler.USER, ).add_to_hass(hass) resp = await client.get("/api/config/config_entries/entry") assert resp.status == HTTPStatus.OK data = await resp.json() for entry in data: entry.pop("entry_id") assert data == [ { "domain": "comp1", "title": "Test 1", "source": "bla", "state": core_ce.ConfigEntryState.NOT_LOADED.value, "supports_options": True, "supports_remove_device": False, "supports_unload": True, "pref_disable_new_entities": False, "pref_disable_polling": False, "disabled_by": None, "reason": None, }, { "domain": "comp2", "title": "Test 2", "source": "bla2", "state": core_ce.ConfigEntryState.SETUP_ERROR.value, "supports_options": False, "supports_remove_device": False, "supports_unload": False, "pref_disable_new_entities": False, "pref_disable_polling": False, "disabled_by": None, "reason": "Unsupported API", }, { "domain": "comp3", "title": "Test 3", "source": "bla3", "state": core_ce.ConfigEntryState.NOT_LOADED.value, "supports_options": False, "supports_remove_device": False, "supports_unload": False, "pref_disable_new_entities": False, "pref_disable_polling": False, "disabled_by": core_ce.ConfigEntryDisabler.USER, "reason": None, }, ] resp = await client.get("/api/config/config_entries/entry?domain=comp3") assert resp.status == HTTPStatus.OK data = await resp.json() assert len(data) == 1 assert data[0]["domain"] == "comp3" resp = await client.get( "/api/config/config_entries/entry?domain=comp3&type=helper") assert resp.status == HTTPStatus.OK data = await resp.json() assert len(data) == 0 resp = await client.get( "/api/config/config_entries/entry?domain=comp3&type=integration") assert resp.status == HTTPStatus.OK data = await resp.json() assert len(data) == 1 resp = await client.get("/api/config/config_entries/entry?type=integration" ) assert resp.status == HTTPStatus.OK data = await resp.json() assert len(data) == 2 assert data[0]["domain"] == "comp1" assert data[1]["domain"] == "comp3"