Bump Nettigo Air Monitor backend library to version 5.0.0 (#147812)

This commit is contained in:
Maciej Bieniek 2025-07-01 15:39:29 +02:00 committed by Franck Nijhof
parent 748cc6386d
commit f85fc7173f
No known key found for this signature in database
GPG Key ID: AB33ADACE7101952
8 changed files with 94 additions and 213 deletions

View File

@ -44,15 +44,6 @@ async def async_setup_entry(hass: HomeAssistant, entry: NAMConfigEntry) -> bool:
translation_key="device_communication_error", translation_key="device_communication_error",
translation_placeholders={"device": entry.title}, translation_placeholders={"device": entry.title},
) from err ) from err
try:
await nam.async_check_credentials()
except (ApiError, ClientError) as err:
raise ConfigEntryNotReady(
translation_domain=DOMAIN,
translation_key="device_communication_error",
translation_placeholders={"device": entry.title},
) from err
except AuthFailedError as err: except AuthFailedError as err:
raise ConfigEntryAuthFailed( raise ConfigEntryAuthFailed(
translation_domain=DOMAIN, translation_domain=DOMAIN,

View File

@ -3,7 +3,6 @@
from __future__ import annotations from __future__ import annotations
from collections.abc import Mapping from collections.abc import Mapping
from dataclasses import dataclass
import logging import logging
from typing import Any from typing import Any
@ -26,15 +25,6 @@ from homeassistant.helpers.service_info.zeroconf import ZeroconfServiceInfo
from .const import DOMAIN from .const import DOMAIN
@dataclass
class NamConfig:
"""NAM device configuration class."""
mac_address: str
auth_enabled: bool
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
AUTH_SCHEMA = vol.Schema( AUTH_SCHEMA = vol.Schema(
@ -42,29 +32,14 @@ AUTH_SCHEMA = vol.Schema(
) )
async def async_get_config(hass: HomeAssistant, host: str) -> NamConfig: async def async_get_nam(
"""Get device MAC address and auth_enabled property."""
websession = async_get_clientsession(hass)
options = ConnectionOptions(host)
nam = await NettigoAirMonitor.create(websession, options)
mac = await nam.async_get_mac_address()
return NamConfig(mac, nam.auth_enabled)
async def async_check_credentials(
hass: HomeAssistant, host: str, data: dict[str, Any] hass: HomeAssistant, host: str, data: dict[str, Any]
) -> None: ) -> NettigoAirMonitor:
"""Check if credentials are valid.""" """Get NAM client."""
websession = async_get_clientsession(hass) websession = async_get_clientsession(hass)
options = ConnectionOptions(host, data.get(CONF_USERNAME), data.get(CONF_PASSWORD)) options = ConnectionOptions(host, data.get(CONF_USERNAME), data.get(CONF_PASSWORD))
nam = await NettigoAirMonitor.create(websession, options) return await NettigoAirMonitor.create(websession, options)
await nam.async_check_credentials()
class NAMFlowHandler(ConfigFlow, domain=DOMAIN): class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
@ -72,8 +47,8 @@ class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
VERSION = 1 VERSION = 1
_config: NamConfig
host: str host: str
auth_enabled: bool = False
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
@ -85,21 +60,20 @@ class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
self.host = user_input[CONF_HOST] self.host = user_input[CONF_HOST]
try: try:
config = await async_get_config(self.hass, self.host) nam = await async_get_nam(self.hass, self.host, {})
except (ApiError, ClientConnectorError, TimeoutError): except (ApiError, ClientConnectorError, TimeoutError):
errors["base"] = "cannot_connect" errors["base"] = "cannot_connect"
except CannotGetMacError: except CannotGetMacError:
return self.async_abort(reason="device_unsupported") return self.async_abort(reason="device_unsupported")
except AuthFailedError:
return await self.async_step_credentials()
except Exception: except Exception:
_LOGGER.exception("Unexpected exception") _LOGGER.exception("Unexpected exception")
errors["base"] = "unknown" errors["base"] = "unknown"
else: else:
await self.async_set_unique_id(format_mac(config.mac_address)) await self.async_set_unique_id(format_mac(nam.mac))
self._abort_if_unique_id_configured({CONF_HOST: self.host}) self._abort_if_unique_id_configured({CONF_HOST: self.host})
if config.auth_enabled is True:
return await self.async_step_credentials()
return self.async_create_entry( return self.async_create_entry(
title=self.host, title=self.host,
data=user_input, data=user_input,
@ -119,7 +93,7 @@ class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
if user_input is not None: if user_input is not None:
try: try:
await async_check_credentials(self.hass, self.host, user_input) nam = await async_get_nam(self.hass, self.host, user_input)
except AuthFailedError: except AuthFailedError:
errors["base"] = "invalid_auth" errors["base"] = "invalid_auth"
except (ApiError, ClientConnectorError, TimeoutError): except (ApiError, ClientConnectorError, TimeoutError):
@ -128,6 +102,9 @@ class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
_LOGGER.exception("Unexpected exception") _LOGGER.exception("Unexpected exception")
errors["base"] = "unknown" errors["base"] = "unknown"
else: else:
await self.async_set_unique_id(format_mac(nam.mac))
self._abort_if_unique_id_configured({CONF_HOST: self.host})
return self.async_create_entry( return self.async_create_entry(
title=self.host, title=self.host,
data={**user_input, CONF_HOST: self.host}, data={**user_input, CONF_HOST: self.host},
@ -148,14 +125,16 @@ class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
self._async_abort_entries_match({CONF_HOST: self.host}) self._async_abort_entries_match({CONF_HOST: self.host})
try: try:
self._config = await async_get_config(self.hass, self.host) nam = await async_get_nam(self.hass, self.host, {})
except (ApiError, ClientConnectorError, TimeoutError): except (ApiError, ClientConnectorError, TimeoutError):
return self.async_abort(reason="cannot_connect") return self.async_abort(reason="cannot_connect")
except CannotGetMacError: except CannotGetMacError:
return self.async_abort(reason="device_unsupported") return self.async_abort(reason="device_unsupported")
except AuthFailedError:
self.auth_enabled = True
return await self.async_step_confirm_discovery()
await self.async_set_unique_id(format_mac(self._config.mac_address)) await self.async_set_unique_id(format_mac(nam.mac))
self._abort_if_unique_id_configured({CONF_HOST: self.host})
return await self.async_step_confirm_discovery() return await self.async_step_confirm_discovery()
@ -171,7 +150,7 @@ class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
data={CONF_HOST: self.host}, data={CONF_HOST: self.host},
) )
if self._config.auth_enabled is True: if self.auth_enabled is True:
return await self.async_step_credentials() return await self.async_step_credentials()
self._set_confirm_only() self._set_confirm_only()
@ -198,7 +177,7 @@ class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
if user_input is not None: if user_input is not None:
try: try:
await async_check_credentials(self.hass, self.host, user_input) await async_get_nam(self.hass, self.host, user_input)
except ( except (
ApiError, ApiError,
AuthFailedError, AuthFailedError,
@ -228,11 +207,11 @@ class NAMFlowHandler(ConfigFlow, domain=DOMAIN):
if user_input is not None: if user_input is not None:
try: try:
config = await async_get_config(self.hass, user_input[CONF_HOST]) nam = await async_get_nam(self.hass, user_input[CONF_HOST], {})
except (ApiError, ClientConnectorError, TimeoutError): except (ApiError, ClientConnectorError, TimeoutError):
errors["base"] = "cannot_connect" errors["base"] = "cannot_connect"
else: else:
await self.async_set_unique_id(format_mac(config.mac_address)) await self.async_set_unique_id(format_mac(nam.mac))
self._abort_if_unique_id_mismatch(reason="another_device") self._abort_if_unique_id_mismatch(reason="another_device")
return self.async_update_reload_and_abort( return self.async_update_reload_and_abort(

View File

@ -7,7 +7,7 @@
"integration_type": "device", "integration_type": "device",
"iot_class": "local_polling", "iot_class": "local_polling",
"loggers": ["nettigo_air_monitor"], "loggers": ["nettigo_air_monitor"],
"requirements": ["nettigo-air-monitor==4.1.0"], "requirements": ["nettigo-air-monitor==5.0.0"],
"zeroconf": [ "zeroconf": [
{ {
"type": "_http._tcp.local.", "type": "_http._tcp.local.",

2
requirements_all.txt generated
View File

@ -1497,7 +1497,7 @@ netdata==1.3.0
netmap==0.7.0.2 netmap==0.7.0.2
# homeassistant.components.nam # homeassistant.components.nam
nettigo-air-monitor==4.1.0 nettigo-air-monitor==5.0.0
# homeassistant.components.neurio_energy # homeassistant.components.neurio_energy
neurio==0.3.1 neurio==0.3.1

View File

@ -1283,7 +1283,7 @@ nessclient==1.2.0
netmap==0.7.0.2 netmap==0.7.0.2
# homeassistant.components.nam # homeassistant.components.nam
nettigo-air-monitor==4.1.0 nettigo-air-monitor==5.0.0
# homeassistant.components.nexia # homeassistant.components.nexia
nexia==2.10.0 nexia==2.10.0

View File

@ -33,7 +33,10 @@ async def init_integration(
update_response = Mock(json=AsyncMock(return_value=nam_data)) update_response = Mock(json=AsyncMock(return_value=nam_data))
with ( with (
patch("homeassistant.components.nam.NettigoAirMonitor.initialize"), patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
return_value="aa:bb:cc:dd:ee:ff",
),
patch( patch(
"homeassistant.components.nam.NettigoAirMonitor._async_http_request", "homeassistant.components.nam.NettigoAirMonitor._async_http_request",
return_value=update_response, return_value=update_response,

View File

@ -1,7 +1,8 @@
"""Define tests for the Nettigo Air Monitor config flow.""" """Define tests for the Nettigo Air Monitor config flow."""
from collections.abc import Generator
from ipaddress import ip_address from ipaddress import ip_address
from unittest.mock import patch from unittest.mock import AsyncMock, patch
from nettigo_air_monitor import ApiError, AuthFailedError, CannotGetMacError from nettigo_air_monitor import ApiError, AuthFailedError, CannotGetMacError
import pytest import pytest
@ -26,11 +27,21 @@ DISCOVERY_INFO = ZeroconfServiceInfo(
) )
VALID_CONFIG = {"host": "10.10.2.3"} VALID_CONFIG = {"host": "10.10.2.3"}
VALID_AUTH = {"username": "fake_username", "password": "fake_password"} VALID_AUTH = {"username": "fake_username", "password": "fake_password"}
DEVICE_CONFIG = {"www_basicauth_enabled": False}
DEVICE_CONFIG_AUTH = {"www_basicauth_enabled": True}
async def test_form_create_entry_without_auth(hass: HomeAssistant) -> None: @pytest.fixture
def mock_setup_entry() -> Generator[AsyncMock]:
"""Override async_setup_entry."""
with patch(
"homeassistant.components.nam.async_setup_entry",
return_value=True,
) as mock_setup_entry:
yield mock_setup_entry
async def test_form_create_entry_without_auth(
hass: HomeAssistant, mock_setup_entry: AsyncMock
) -> None:
"""Test that the user step without auth works.""" """Test that the user step without auth works."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER} DOMAIN, context={"source": SOURCE_USER}
@ -39,18 +50,9 @@ async def test_form_create_entry_without_auth(hass: HomeAssistant) -> None:
assert result["step_id"] == "user" assert result["step_id"] == "user"
assert result["errors"] == {} assert result["errors"] == {}
with ( with patch(
patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", return_value="aa:bb:cc:dd:ee:ff",
return_value=DEVICE_CONFIG,
),
patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
return_value="aa:bb:cc:dd:ee:ff",
),
patch(
"homeassistant.components.nam.async_setup_entry", return_value=True
) as mock_setup_entry,
): ):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
@ -64,7 +66,9 @@ async def test_form_create_entry_without_auth(hass: HomeAssistant) -> None:
assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1
async def test_form_create_entry_with_auth(hass: HomeAssistant) -> None: async def test_form_create_entry_with_auth(
hass: HomeAssistant, mock_setup_entry: AsyncMock
) -> None:
"""Test that the user step with auth works.""" """Test that the user step with auth works."""
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": SOURCE_USER} DOMAIN, context={"source": SOURCE_USER}
@ -73,18 +77,9 @@ async def test_form_create_entry_with_auth(hass: HomeAssistant) -> None:
assert result["step_id"] == "user" assert result["step_id"] == "user"
assert result["errors"] == {} assert result["errors"] == {}
with ( with patch(
patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", side_effect=[AuthFailedError("Authorization has failed"), "aa:bb:cc:dd:ee:ff"],
return_value=DEVICE_CONFIG_AUTH,
),
patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
return_value="aa:bb:cc:dd:ee:ff",
),
patch(
"homeassistant.components.nam.async_setup_entry", return_value=True
) as mock_setup_entry,
): ):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
@ -121,23 +116,17 @@ async def test_reauth_successful(hass: HomeAssistant) -> None:
assert result["type"] is FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reauth_confirm" assert result["step_id"] == "reauth_confirm"
with ( with patch(
patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", return_value="aa:bb:cc:dd:ee:ff",
return_value=DEVICE_CONFIG_AUTH,
),
patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
return_value="aa:bb:cc:dd:ee:ff",
),
): ):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
user_input=VALID_AUTH, user_input=VALID_AUTH,
) )
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_successful" assert result["reason"] == "reauth_successful"
async def test_reauth_unsuccessful(hass: HomeAssistant) -> None: async def test_reauth_unsuccessful(hass: HomeAssistant) -> None:
@ -154,7 +143,7 @@ async def test_reauth_unsuccessful(hass: HomeAssistant) -> None:
assert result["step_id"] == "reauth_confirm" assert result["step_id"] == "reauth_confirm"
with patch( with patch(
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
side_effect=ApiError("API Error"), side_effect=ApiError("API Error"),
): ):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
@ -162,8 +151,8 @@ async def test_reauth_unsuccessful(hass: HomeAssistant) -> None:
user_input=VALID_AUTH, user_input=VALID_AUTH,
) )
assert result["type"] is FlowResultType.ABORT assert result["type"] is FlowResultType.ABORT
assert result["reason"] == "reauth_unsuccessful" assert result["reason"] == "reauth_unsuccessful"
@pytest.mark.parametrize( @pytest.mark.parametrize(
@ -178,15 +167,9 @@ async def test_reauth_unsuccessful(hass: HomeAssistant) -> None:
async def test_form_with_auth_errors(hass: HomeAssistant, error) -> None: async def test_form_with_auth_errors(hass: HomeAssistant, error) -> None:
"""Test we handle errors when auth is required.""" """Test we handle errors when auth is required."""
exc, base_error = error exc, base_error = error
with ( with patch(
patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", side_effect=AuthFailedError("Authorization has failed"),
side_effect=AuthFailedError("Auth Error"),
),
patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
return_value="aa:bb:cc:dd:ee:ff",
),
): ):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -198,7 +181,7 @@ async def test_form_with_auth_errors(hass: HomeAssistant, error) -> None:
assert result["step_id"] == "credentials" assert result["step_id"] == "credentials"
with patch( with patch(
"homeassistant.components.nam.NettigoAirMonitor.initialize", "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
side_effect=exc, side_effect=exc,
): ):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
@ -236,10 +219,6 @@ async def test_form_errors(hass: HomeAssistant, error) -> None:
async def test_form_abort(hass: HomeAssistant) -> None: async def test_form_abort(hass: HomeAssistant) -> None:
"""Test we handle abort after error.""" """Test we handle abort after error."""
with ( with (
patch(
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials",
return_value=DEVICE_CONFIG,
),
patch( patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address", "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
side_effect=CannotGetMacError("Cannot get MAC address from device"), side_effect=CannotGetMacError("Cannot get MAC address from device"),
@ -266,15 +245,9 @@ async def test_form_already_configured(hass: HomeAssistant) -> None:
DOMAIN, context={"source": SOURCE_USER} DOMAIN, context={"source": SOURCE_USER}
) )
with ( with patch(
patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", return_value="aa:bb:cc:dd:ee:ff",
return_value=DEVICE_CONFIG,
),
patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
return_value="aa:bb:cc:dd:ee:ff",
),
): ):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
@ -288,17 +261,11 @@ async def test_form_already_configured(hass: HomeAssistant) -> None:
assert entry.data["host"] == "1.1.1.1" assert entry.data["host"] == "1.1.1.1"
async def test_zeroconf(hass: HomeAssistant) -> None: async def test_zeroconf(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> None:
"""Test we get the form.""" """Test we get the form."""
with ( with patch(
patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", return_value="aa:bb:cc:dd:ee:ff",
return_value=DEVICE_CONFIG,
),
patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
return_value="aa:bb:cc:dd:ee:ff",
),
): ):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -316,15 +283,8 @@ async def test_zeroconf(hass: HomeAssistant) -> None:
assert context["title_placeholders"]["host"] == "10.10.2.3" assert context["title_placeholders"]["host"] == "10.10.2.3"
assert context["confirm_only"] is True assert context["confirm_only"] is True
with patch( result = await hass.config_entries.flow.async_configure(result["flow_id"], {})
"homeassistant.components.nam.async_setup_entry", await hass.async_block_till_done()
return_value=True,
) as mock_setup_entry:
result = await hass.config_entries.flow.async_configure(
result["flow_id"],
{},
)
await hass.async_block_till_done()
assert result["type"] is FlowResultType.CREATE_ENTRY assert result["type"] is FlowResultType.CREATE_ENTRY
assert result["title"] == "10.10.2.3" assert result["title"] == "10.10.2.3"
@ -332,17 +292,13 @@ async def test_zeroconf(hass: HomeAssistant) -> None:
assert len(mock_setup_entry.mock_calls) == 1 assert len(mock_setup_entry.mock_calls) == 1
async def test_zeroconf_with_auth(hass: HomeAssistant) -> None: async def test_zeroconf_with_auth(
hass: HomeAssistant, mock_setup_entry: AsyncMock
) -> None:
"""Test that the zeroconf step with auth works.""" """Test that the zeroconf step with auth works."""
with ( with patch(
patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", side_effect=AuthFailedError("Auth Error"),
side_effect=AuthFailedError("Auth Error"),
),
patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
return_value="aa:bb:cc:dd:ee:ff",
),
): ):
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, DOMAIN,
@ -360,18 +316,9 @@ async def test_zeroconf_with_auth(hass: HomeAssistant) -> None:
assert result["errors"] == {} assert result["errors"] == {}
assert context["title_placeholders"]["host"] == "10.10.2.3" assert context["title_placeholders"]["host"] == "10.10.2.3"
with ( with patch(
patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", return_value="aa:bb:cc:dd:ee:ff",
return_value=DEVICE_CONFIG_AUTH,
),
patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
return_value="aa:bb:cc:dd:ee:ff",
),
patch(
"homeassistant.components.nam.async_setup_entry", return_value=True
) as mock_setup_entry,
): ):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
@ -447,15 +394,9 @@ async def test_reconfigure_successful(hass: HomeAssistant) -> None:
assert result["type"] is FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure" assert result["step_id"] == "reconfigure"
with ( with patch(
patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", return_value="aa:bb:cc:dd:ee:ff",
return_value=DEVICE_CONFIG_AUTH,
),
patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
return_value="aa:bb:cc:dd:ee:ff",
),
): ):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
@ -491,7 +432,7 @@ async def test_reconfigure_not_successful(hass: HomeAssistant) -> None:
assert result["step_id"] == "reconfigure" assert result["step_id"] == "reconfigure"
with patch( with patch(
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
side_effect=ApiError("API Error"), side_effect=ApiError("API Error"),
): ):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
@ -503,15 +444,9 @@ async def test_reconfigure_not_successful(hass: HomeAssistant) -> None:
assert result["step_id"] == "reconfigure" assert result["step_id"] == "reconfigure"
assert result["errors"] == {"base": "cannot_connect"} assert result["errors"] == {"base": "cannot_connect"}
with ( with patch(
patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", return_value="aa:bb:cc:dd:ee:ff",
return_value=DEVICE_CONFIG_AUTH,
),
patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
return_value="aa:bb:cc:dd:ee:ff",
),
): ):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],
@ -546,15 +481,9 @@ async def test_reconfigure_not_the_same_device(hass: HomeAssistant) -> None:
assert result["type"] is FlowResultType.FORM assert result["type"] is FlowResultType.FORM
assert result["step_id"] == "reconfigure" assert result["step_id"] == "reconfigure"
with ( with patch(
patch( "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", return_value="aa:bb:cc:dd:ee:ff",
return_value=DEVICE_CONFIG_AUTH,
),
patch(
"homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
return_value="aa:bb:cc:dd:ee:ff",
),
): ):
result = await hass.config_entries.flow.async_configure( result = await hass.config_entries.flow.async_configure(
result["flow_id"], result["flow_id"],

View File

@ -44,27 +44,6 @@ async def test_config_not_ready(hass: HomeAssistant) -> None:
assert entry.state is ConfigEntryState.SETUP_RETRY assert entry.state is ConfigEntryState.SETUP_RETRY
async def test_config_not_ready_while_checking_credentials(hass: HomeAssistant) -> None:
"""Test for setup failure if the connection fails while checking credentials."""
entry = MockConfigEntry(
domain=DOMAIN,
title="10.10.2.3",
unique_id="aa:bb:cc:dd:ee:ff",
data={"host": "10.10.2.3"},
)
entry.add_to_hass(hass)
with (
patch("homeassistant.components.nam.NettigoAirMonitor.initialize"),
patch(
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials",
side_effect=ApiError("API Error"),
),
):
await hass.config_entries.async_setup(entry.entry_id)
assert entry.state is ConfigEntryState.SETUP_RETRY
async def test_config_auth_failed(hass: HomeAssistant) -> None: async def test_config_auth_failed(hass: HomeAssistant) -> None:
"""Test for setup failure if the auth fails.""" """Test for setup failure if the auth fails."""
entry = MockConfigEntry( entry = MockConfigEntry(
@ -76,7 +55,7 @@ async def test_config_auth_failed(hass: HomeAssistant) -> None:
entry.add_to_hass(hass) entry.add_to_hass(hass)
with patch( with patch(
"homeassistant.components.nam.NettigoAirMonitor.async_check_credentials", "homeassistant.components.nam.NettigoAirMonitor.async_get_mac_address",
side_effect=AuthFailedError("Authorization has failed"), side_effect=AuthFailedError("Authorization has failed"),
): ):
await hass.config_entries.async_setup(entry.entry_id) await hass.config_entries.async_setup(entry.entry_id)