Process AdGuard review comments (#49274)

This commit is contained in:
Franck Nijhof 2021-04-15 23:34:49 +02:00 committed by GitHub
parent a981b86b15
commit eb008e533e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 24 deletions

View File

@ -68,9 +68,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
except AdGuardHomeConnectionError as exception: except AdGuardHomeConnectionError as exception:
raise ConfigEntryNotReady from exception raise ConfigEntryNotReady from exception
for component in PLATFORMS: for platform in PLATFORMS:
hass.async_create_task( hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, component) hass.config_entries.async_forward_entry_setup(entry, platform)
) )
async def add_url(call) -> None: async def add_url(call) -> None:

View File

@ -16,6 +16,7 @@ from homeassistant.const import (
CONF_USERNAME, CONF_USERNAME,
CONF_VERIFY_SSL, CONF_VERIFY_SSL,
) )
from homeassistant.data_entry_flow import FlowResultDict
from homeassistant.helpers.aiohttp_client import async_get_clientsession from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import DOMAIN from .const import DOMAIN
@ -31,7 +32,7 @@ class AdGuardHomeFlowHandler(ConfigFlow, domain=DOMAIN):
async def _show_setup_form( async def _show_setup_form(
self, errors: dict[str, str] | None = None self, errors: dict[str, str] | None = None
) -> dict[str, Any]: ) -> FlowResultDict:
"""Show the setup form to the user.""" """Show the setup form to the user."""
return self.async_show_form( return self.async_show_form(
step_id="user", step_id="user",
@ -50,7 +51,7 @@ class AdGuardHomeFlowHandler(ConfigFlow, domain=DOMAIN):
async def _show_hassio_form( async def _show_hassio_form(
self, errors: dict[str, str] | None = None self, errors: dict[str, str] | None = None
) -> dict[str, Any]: ) -> FlowResultDict:
"""Show the Hass.io confirmation form to the user.""" """Show the Hass.io confirmation form to the user."""
return self.async_show_form( return self.async_show_form(
step_id="hassio_confirm", step_id="hassio_confirm",
@ -61,7 +62,7 @@ class AdGuardHomeFlowHandler(ConfigFlow, domain=DOMAIN):
async def async_step_user( async def async_step_user(
self, user_input: dict[str, Any] | None = None self, user_input: dict[str, Any] | None = None
) -> dict[str, Any]: ) -> FlowResultDict:
"""Handle a flow initiated by the user.""" """Handle a flow initiated by the user."""
if user_input is None: if user_input is None:
return await self._show_setup_form(user_input) return await self._show_setup_form(user_input)
@ -72,7 +73,7 @@ class AdGuardHomeFlowHandler(ConfigFlow, domain=DOMAIN):
entry.data[CONF_HOST] == user_input[CONF_HOST] entry.data[CONF_HOST] == user_input[CONF_HOST]
and entry.data[CONF_PORT] == user_input[CONF_PORT] and entry.data[CONF_PORT] == user_input[CONF_PORT]
): ):
return self.async_abort(reason="single_instance_allowed") return self.async_abort(reason="already_configured")
errors = {} errors = {}
@ -106,7 +107,7 @@ class AdGuardHomeFlowHandler(ConfigFlow, domain=DOMAIN):
}, },
) )
async def async_step_hassio(self, discovery_info: dict[str, Any]) -> dict[str, Any]: async def async_step_hassio(self, discovery_info: dict[str, Any]) -> FlowResultDict:
"""Prepare configuration for a Hass.io AdGuard Home add-on. """Prepare configuration for a Hass.io AdGuard Home add-on.
This flow is triggered by the discovery component. This flow is triggered by the discovery component.
@ -124,7 +125,7 @@ class AdGuardHomeFlowHandler(ConfigFlow, domain=DOMAIN):
cur_entry.data[CONF_HOST] == discovery_info[CONF_HOST] cur_entry.data[CONF_HOST] == discovery_info[CONF_HOST]
and cur_entry.data[CONF_PORT] == discovery_info[CONF_PORT] and cur_entry.data[CONF_PORT] == discovery_info[CONF_PORT]
): ):
return self.async_abort(reason="single_instance_allowed") return self.async_abort(reason="already_configured")
is_loaded = cur_entry.state == config_entries.ENTRY_STATE_LOADED is_loaded = cur_entry.state == config_entries.ENTRY_STATE_LOADED
@ -147,8 +148,8 @@ class AdGuardHomeFlowHandler(ConfigFlow, domain=DOMAIN):
async def async_step_hassio_confirm( async def async_step_hassio_confirm(
self, user_input: dict[str, Any] | None = None self, user_input: dict[str, Any] | None = None
) -> dict[str, Any]: ) -> FlowResultDict:
"""Confirm Hass.io discovery.""" """Confirm Supervisor discovery."""
if user_input is None: if user_input is None:
return await self._show_hassio_form() return await self._show_hassio_form()

View File

@ -96,7 +96,7 @@ class AdGuardHomeSensor(AdGuardHomeDeviceEntity, SensorEntity):
class AdGuardHomeDNSQueriesSensor(AdGuardHomeSensor): class AdGuardHomeDNSQueriesSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home DNS Queries sensor.""" """Defines a AdGuard Home DNS Queries sensor."""
def __init__(self, adguard: AdGuardHome, entry: ConfigEntry): def __init__(self, adguard: AdGuardHome, entry: ConfigEntry) -> None:
"""Initialize AdGuard Home sensor.""" """Initialize AdGuard Home sensor."""
super().__init__( super().__init__(
adguard, adguard,
@ -115,7 +115,7 @@ class AdGuardHomeDNSQueriesSensor(AdGuardHomeSensor):
class AdGuardHomeBlockedFilteringSensor(AdGuardHomeSensor): class AdGuardHomeBlockedFilteringSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home blocked by filtering sensor.""" """Defines a AdGuard Home blocked by filtering sensor."""
def __init__(self, adguard: AdGuardHome, entry: ConfigEntry): def __init__(self, adguard: AdGuardHome, entry: ConfigEntry) -> None:
"""Initialize AdGuard Home sensor.""" """Initialize AdGuard Home sensor."""
super().__init__( super().__init__(
adguard, adguard,
@ -135,7 +135,7 @@ class AdGuardHomeBlockedFilteringSensor(AdGuardHomeSensor):
class AdGuardHomePercentageBlockedSensor(AdGuardHomeSensor): class AdGuardHomePercentageBlockedSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home blocked percentage sensor.""" """Defines a AdGuard Home blocked percentage sensor."""
def __init__(self, adguard: AdGuardHome, entry: ConfigEntry): def __init__(self, adguard: AdGuardHome, entry: ConfigEntry) -> None:
"""Initialize AdGuard Home sensor.""" """Initialize AdGuard Home sensor."""
super().__init__( super().__init__(
adguard, adguard,
@ -155,7 +155,7 @@ class AdGuardHomePercentageBlockedSensor(AdGuardHomeSensor):
class AdGuardHomeReplacedParentalSensor(AdGuardHomeSensor): class AdGuardHomeReplacedParentalSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home replaced by parental control sensor.""" """Defines a AdGuard Home replaced by parental control sensor."""
def __init__(self, adguard: AdGuardHome, entry: ConfigEntry): def __init__(self, adguard: AdGuardHome, entry: ConfigEntry) -> None:
"""Initialize AdGuard Home sensor.""" """Initialize AdGuard Home sensor."""
super().__init__( super().__init__(
adguard, adguard,
@ -174,7 +174,7 @@ class AdGuardHomeReplacedParentalSensor(AdGuardHomeSensor):
class AdGuardHomeReplacedSafeBrowsingSensor(AdGuardHomeSensor): class AdGuardHomeReplacedSafeBrowsingSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home replaced by safe browsing sensor.""" """Defines a AdGuard Home replaced by safe browsing sensor."""
def __init__(self, adguard: AdGuardHome, entry: ConfigEntry): def __init__(self, adguard: AdGuardHome, entry: ConfigEntry) -> None:
"""Initialize AdGuard Home sensor.""" """Initialize AdGuard Home sensor."""
super().__init__( super().__init__(
adguard, adguard,
@ -193,7 +193,7 @@ class AdGuardHomeReplacedSafeBrowsingSensor(AdGuardHomeSensor):
class AdGuardHomeReplacedSafeSearchSensor(AdGuardHomeSensor): class AdGuardHomeReplacedSafeSearchSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home replaced by safe search sensor.""" """Defines a AdGuard Home replaced by safe search sensor."""
def __init__(self, adguard: AdGuardHome, entry: ConfigEntry): def __init__(self, adguard: AdGuardHome, entry: ConfigEntry) -> None:
"""Initialize AdGuard Home sensor.""" """Initialize AdGuard Home sensor."""
super().__init__( super().__init__(
adguard, adguard,
@ -212,7 +212,7 @@ class AdGuardHomeReplacedSafeSearchSensor(AdGuardHomeSensor):
class AdGuardHomeAverageProcessingTimeSensor(AdGuardHomeSensor): class AdGuardHomeAverageProcessingTimeSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home average processing time sensor.""" """Defines a AdGuard Home average processing time sensor."""
def __init__(self, adguard: AdGuardHome, entry: ConfigEntry): def __init__(self, adguard: AdGuardHome, entry: ConfigEntry) -> None:
"""Initialize AdGuard Home sensor.""" """Initialize AdGuard Home sensor."""
super().__init__( super().__init__(
adguard, adguard,
@ -232,7 +232,7 @@ class AdGuardHomeAverageProcessingTimeSensor(AdGuardHomeSensor):
class AdGuardHomeRulesCountSensor(AdGuardHomeSensor): class AdGuardHomeRulesCountSensor(AdGuardHomeSensor):
"""Defines a AdGuard Home rules count sensor.""" """Defines a AdGuard Home rules count sensor."""
def __init__(self, adguard: AdGuardHome, entry: ConfigEntry): def __init__(self, adguard: AdGuardHome, entry: ConfigEntry) -> None:
"""Initialize AdGuard Home sensor.""" """Initialize AdGuard Home sensor."""
super().__init__( super().__init__(
adguard, adguard,

View File

@ -22,7 +22,7 @@
}, },
"abort": { "abort": {
"existing_instance_updated": "Updated existing configuration.", "existing_instance_updated": "Updated existing configuration.",
"single_instance_allowed": "[%key:common::config_flow::abort::single_instance_allowed%]" "already_configured": "[%key:common::config_flow::abort::already_configured_service%]"
} }
} }
} }

View File

@ -1,8 +1,8 @@
{ {
"config": { "config": {
"abort": { "abort": {
"existing_instance_updated": "Updated existing configuration.", "already_configured": "Service is already configured",
"single_instance_allowed": "Already configured. Only a single configuration possible." "existing_instance_updated": "Updated existing configuration."
}, },
"error": { "error": {
"cannot_connect": "Failed to connect" "cannot_connect": "Failed to connect"

View File

@ -102,10 +102,10 @@ async def test_integration_already_exists(hass: HomeAssistant) -> None:
context={"source": "user"}, context={"source": "user"},
) )
assert result["type"] == "abort" assert result["type"] == "abort"
assert result["reason"] == "single_instance_allowed" assert result["reason"] == "already_configured"
async def test_hassio_single_instance(hass: HomeAssistant) -> None: async def test_hassio_already_configured(hass: HomeAssistant) -> None:
"""Test we only allow a single config flow.""" """Test we only allow a single config flow."""
MockConfigEntry( MockConfigEntry(
domain=DOMAIN, data={"host": "mock-adguard", "port": "3000"} domain=DOMAIN, data={"host": "mock-adguard", "port": "3000"}
@ -117,7 +117,7 @@ async def test_hassio_single_instance(hass: HomeAssistant) -> None:
context={"source": "hassio"}, context={"source": "hassio"},
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT assert result["type"] == data_entry_flow.RESULT_TYPE_ABORT
assert result["reason"] == "single_instance_allowed" assert result["reason"] == "already_configured"
async def test_hassio_update_instance_not_running(hass: HomeAssistant) -> None: async def test_hassio_update_instance_not_running(hass: HomeAssistant) -> None: