mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 12:47:08 +00:00
Process AdGuard review comments (#49274)
This commit is contained in:
parent
a981b86b15
commit
eb008e533e
@ -68,9 +68,9 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
except AdGuardHomeConnectionError as exception:
|
||||
raise ConfigEntryNotReady from exception
|
||||
|
||||
for component in PLATFORMS:
|
||||
for platform in PLATFORMS:
|
||||
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:
|
||||
|
@ -16,6 +16,7 @@ from homeassistant.const import (
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
)
|
||||
from homeassistant.data_entry_flow import FlowResultDict
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from .const import DOMAIN
|
||||
@ -31,7 +32,7 @@ class AdGuardHomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
async def _show_setup_form(
|
||||
self, errors: dict[str, str] | None = None
|
||||
) -> dict[str, Any]:
|
||||
) -> FlowResultDict:
|
||||
"""Show the setup form to the user."""
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
@ -50,7 +51,7 @@ class AdGuardHomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
async def _show_hassio_form(
|
||||
self, errors: dict[str, str] | None = None
|
||||
) -> dict[str, Any]:
|
||||
) -> FlowResultDict:
|
||||
"""Show the Hass.io confirmation form to the user."""
|
||||
return self.async_show_form(
|
||||
step_id="hassio_confirm",
|
||||
@ -61,7 +62,7 @@ class AdGuardHomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> dict[str, Any]:
|
||||
) -> FlowResultDict:
|
||||
"""Handle a flow initiated by the user."""
|
||||
if user_input is None:
|
||||
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]
|
||||
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 = {}
|
||||
|
||||
@ -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.
|
||||
|
||||
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]
|
||||
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
|
||||
|
||||
@ -147,8 +148,8 @@ class AdGuardHomeFlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
async def async_step_hassio_confirm(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> dict[str, Any]:
|
||||
"""Confirm Hass.io discovery."""
|
||||
) -> FlowResultDict:
|
||||
"""Confirm Supervisor discovery."""
|
||||
if user_input is None:
|
||||
return await self._show_hassio_form()
|
||||
|
||||
|
@ -96,7 +96,7 @@ class AdGuardHomeSensor(AdGuardHomeDeviceEntity, SensorEntity):
|
||||
class AdGuardHomeDNSQueriesSensor(AdGuardHomeSensor):
|
||||
"""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."""
|
||||
super().__init__(
|
||||
adguard,
|
||||
@ -115,7 +115,7 @@ class AdGuardHomeDNSQueriesSensor(AdGuardHomeSensor):
|
||||
class AdGuardHomeBlockedFilteringSensor(AdGuardHomeSensor):
|
||||
"""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."""
|
||||
super().__init__(
|
||||
adguard,
|
||||
@ -135,7 +135,7 @@ class AdGuardHomeBlockedFilteringSensor(AdGuardHomeSensor):
|
||||
class AdGuardHomePercentageBlockedSensor(AdGuardHomeSensor):
|
||||
"""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."""
|
||||
super().__init__(
|
||||
adguard,
|
||||
@ -155,7 +155,7 @@ class AdGuardHomePercentageBlockedSensor(AdGuardHomeSensor):
|
||||
class AdGuardHomeReplacedParentalSensor(AdGuardHomeSensor):
|
||||
"""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."""
|
||||
super().__init__(
|
||||
adguard,
|
||||
@ -174,7 +174,7 @@ class AdGuardHomeReplacedParentalSensor(AdGuardHomeSensor):
|
||||
class AdGuardHomeReplacedSafeBrowsingSensor(AdGuardHomeSensor):
|
||||
"""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."""
|
||||
super().__init__(
|
||||
adguard,
|
||||
@ -193,7 +193,7 @@ class AdGuardHomeReplacedSafeBrowsingSensor(AdGuardHomeSensor):
|
||||
class AdGuardHomeReplacedSafeSearchSensor(AdGuardHomeSensor):
|
||||
"""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."""
|
||||
super().__init__(
|
||||
adguard,
|
||||
@ -212,7 +212,7 @@ class AdGuardHomeReplacedSafeSearchSensor(AdGuardHomeSensor):
|
||||
class AdGuardHomeAverageProcessingTimeSensor(AdGuardHomeSensor):
|
||||
"""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."""
|
||||
super().__init__(
|
||||
adguard,
|
||||
@ -232,7 +232,7 @@ class AdGuardHomeAverageProcessingTimeSensor(AdGuardHomeSensor):
|
||||
class AdGuardHomeRulesCountSensor(AdGuardHomeSensor):
|
||||
"""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."""
|
||||
super().__init__(
|
||||
adguard,
|
||||
|
@ -22,7 +22,7 @@
|
||||
},
|
||||
"abort": {
|
||||
"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%]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
{
|
||||
"config": {
|
||||
"abort": {
|
||||
"existing_instance_updated": "Updated existing configuration.",
|
||||
"single_instance_allowed": "Already configured. Only a single configuration possible."
|
||||
"already_configured": "Service is already configured",
|
||||
"existing_instance_updated": "Updated existing configuration."
|
||||
},
|
||||
"error": {
|
||||
"cannot_connect": "Failed to connect"
|
||||
|
@ -102,10 +102,10 @@ async def test_integration_already_exists(hass: HomeAssistant) -> None:
|
||||
context={"source": "user"},
|
||||
)
|
||||
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."""
|
||||
MockConfigEntry(
|
||||
domain=DOMAIN, data={"host": "mock-adguard", "port": "3000"}
|
||||
@ -117,7 +117,7 @@ async def test_hassio_single_instance(hass: HomeAssistant) -> None:
|
||||
context={"source": "hassio"},
|
||||
)
|
||||
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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user