From 1d24fb7ad9990aa804a18d33036f3e8da381bcc9 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Sun, 9 Jan 2022 11:27:42 +0100 Subject: [PATCH] Fix Netgear used method version (#63686) * Netgear fix used method version * add error message * fix imports * fix black * fix error mess * rename const --- .../components/netgear/config_flow.py | 8 +++---- homeassistant/components/netgear/const.py | 24 ++++++++++++++++--- homeassistant/components/netgear/router.py | 8 +++++++ tests/components/netgear/test_config_flow.py | 4 ++-- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/netgear/config_flow.py b/homeassistant/components/netgear/config_flow.py index 29a0bc40ed6..bcf51f1966d 100644 --- a/homeassistant/components/netgear/config_flow.py +++ b/homeassistant/components/netgear/config_flow.py @@ -22,8 +22,8 @@ from .const import ( DEFAULT_CONSIDER_HOME, DEFAULT_NAME, DOMAIN, - MODELS_V2, - ORBI_PORT, + MODELS_PORT_80, + PORT_80, ) from .errors import CannotLoginException from .router import get_api @@ -141,13 +141,13 @@ class NetgearFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): self._abort_if_unique_id_configured(updates=updated_data) updated_data[CONF_PORT] = DEFAULT_PORT - for model in MODELS_V2: + for model in MODELS_PORT_80: if discovery_info.upnp.get(ssdp.ATTR_UPNP_MODEL_NUMBER, "").startswith( model ) or discovery_info.upnp.get(ssdp.ATTR_UPNP_MODEL_NAME, "").startswith( model ): - updated_data[CONF_PORT] = ORBI_PORT + updated_data[CONF_PORT] = PORT_80 self.placeholders.update(updated_data) self.discovered = True diff --git a/homeassistant/components/netgear/const.py b/homeassistant/components/netgear/const.py index 44d14379eb5..d4cd5d7933e 100644 --- a/homeassistant/components/netgear/const.py +++ b/homeassistant/components/netgear/const.py @@ -12,8 +12,8 @@ CONF_CONSIDER_HOME = "consider_home" DEFAULT_CONSIDER_HOME = timedelta(seconds=180) DEFAULT_NAME = "Netgear router" -# update method V2 models -MODELS_V2 = [ +# models using port 80 instead of 5000 +MODELS_PORT_80 = [ "Orbi", "RBK", "RBR", @@ -31,7 +31,25 @@ MODELS_V2 = [ "SXR", "SXS", ] -ORBI_PORT = 80 +PORT_80 = 80 +# update method V2 models +MODELS_V2 = [ + "Orbi", + "RBK", + "RBR", + "RBS", + "RBW", + "LBK", + "LBR", + "CBK", + "CBR", + "SRC", + "SRK", + "SRS", + "SXK", + "SXR", + "SXS", +] # Icons DEVICE_ICONS = { diff --git a/homeassistant/components/netgear/router.py b/homeassistant/components/netgear/router.py index 40e26128d8d..dbfd0439a85 100644 --- a/homeassistant/components/netgear/router.py +++ b/homeassistant/components/netgear/router.py @@ -149,6 +149,14 @@ class NetgearRouter: if self.model.startswith(model): self.method_version = 2 + if self.method_version == 2: + if not self._api.get_attached_devices_2(): + _LOGGER.error( + "Netgear Model '%s' in MODELS_V2 list, but failed to get attached devices using V2", + self.model, + ) + self.method_version = 1 + async def async_setup(self) -> None: """Set up a Netgear router.""" await self.hass.async_add_executor_job(self._setup) diff --git a/tests/components/netgear/test_config_flow.py b/tests/components/netgear/test_config_flow.py index b26dce8d936..bdb68d79ab2 100644 --- a/tests/components/netgear/test_config_flow.py +++ b/tests/components/netgear/test_config_flow.py @@ -6,7 +6,7 @@ import pytest from homeassistant import data_entry_flow from homeassistant.components import ssdp -from homeassistant.components.netgear.const import CONF_CONSIDER_HOME, DOMAIN, ORBI_PORT +from homeassistant.components.netgear.const import CONF_CONSIDER_HOME, DOMAIN, PORT_80 from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_SSDP, SOURCE_USER from homeassistant.const import ( CONF_HOST, @@ -252,7 +252,7 @@ async def test_ssdp(hass, service): assert result["result"].unique_id == SERIAL assert result["title"] == TITLE assert result["data"].get(CONF_HOST) == HOST - assert result["data"].get(CONF_PORT) == ORBI_PORT + assert result["data"].get(CONF_PORT) == PORT_80 assert result["data"].get(CONF_SSL) == SSL assert result["data"].get(CONF_USERNAME) == DEFAULT_USER assert result["data"][CONF_PASSWORD] == PASSWORD