Clean up Ondilo config flow (#116931)

pull/116991/head^2
Joost Lekkerkerker 2024-05-07 14:15:56 +02:00 committed by GitHub
parent 16d86e5d4c
commit 1559562c26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 12 additions and 11 deletions

View File

@ -5,7 +5,8 @@ from homeassistant.const import Platform
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers import config_entry_oauth2_flow
from . import api, config_flow from .api import OndiloClient
from .config_flow import OndiloIcoOAuth2FlowHandler
from .const import DOMAIN from .const import DOMAIN
from .coordinator import OndiloIcoCoordinator from .coordinator import OndiloIcoCoordinator
from .oauth_impl import OndiloOauth2Implementation from .oauth_impl import OndiloOauth2Implementation
@ -16,7 +17,7 @@ PLATFORMS = [Platform.SENSOR]
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Ondilo ICO from a config entry.""" """Set up Ondilo ICO from a config entry."""
config_flow.OAuth2FlowHandler.async_register_implementation( OndiloIcoOAuth2FlowHandler.async_register_implementation(
hass, hass,
OndiloOauth2Implementation(hass), OndiloOauth2Implementation(hass),
) )
@ -27,9 +28,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
) )
) )
coordinator = OndiloIcoCoordinator( coordinator = OndiloIcoCoordinator(hass, OndiloClient(hass, entry, implementation))
hass, api.OndiloClient(hass, entry, implementation)
)
await coordinator.async_config_entry_first_refresh() await coordinator.async_config_entry_first_refresh()

View File

@ -1,21 +1,23 @@
"""Config flow for Ondilo ICO.""" """Config flow for Ondilo ICO."""
import logging import logging
from typing import Any
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.config_entries import ConfigFlowResult
from homeassistant.helpers.config_entry_oauth2_flow import AbstractOAuth2FlowHandler
from .const import DOMAIN from .const import DOMAIN
from .oauth_impl import OndiloOauth2Implementation from .oauth_impl import OndiloOauth2Implementation
class OAuth2FlowHandler( class OndiloIcoOAuth2FlowHandler(AbstractOAuth2FlowHandler, domain=DOMAIN):
config_entry_oauth2_flow.AbstractOAuth2FlowHandler, domain=DOMAIN
):
"""Config flow to handle Ondilo ICO OAuth2 authentication.""" """Config flow to handle Ondilo ICO OAuth2 authentication."""
DOMAIN = DOMAIN DOMAIN = DOMAIN
async def async_step_user(self, user_input=None): async def async_step_user(
self, user_input: dict[str, Any] | None = None
) -> ConfigFlowResult:
"""Handle a flow initialized by the user.""" """Handle a flow initialized by the user."""
await self.async_set_unique_id(DOMAIN) await self.async_set_unique_id(DOMAIN)

View File

@ -35,7 +35,7 @@ def mock_ondilo_client(
"""Mock a Homeassistant Ondilo client.""" """Mock a Homeassistant Ondilo client."""
with ( with (
patch( patch(
"homeassistant.components.ondilo_ico.api.OndiloClient", "homeassistant.components.ondilo_ico.OndiloClient",
autospec=True, autospec=True,
) as mock_ondilo, ) as mock_ondilo,
): ):