From 08622129427f1b037bf7d37b5926fbe2466b0bba Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 25 Apr 2021 00:41:40 -1000 Subject: [PATCH] Switch screenlogic discovery to use async version (#49650) --- .../components/screenlogic/climate.py | 2 +- .../components/screenlogic/config_flow.py | 4 ++-- .../components/screenlogic/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- .../components/screenlogic/test_config_flow.py | 18 +++++++++++------- 6 files changed, 17 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/screenlogic/climate.py b/homeassistant/components/screenlogic/climate.py index b50879bfd49..fac03ea577a 100644 --- a/homeassistant/components/screenlogic/climate.py +++ b/homeassistant/components/screenlogic/climate.py @@ -89,7 +89,7 @@ class ScreenLogicClimate(ScreenlogicEntity, ClimateEntity, RestoreEntity): @property def temperature_unit(self) -> str: """Return the unit of measurement.""" - if self.config_data["is_celcius"]["value"] == 1: + if self.config_data["is_celsius"]["value"] == 1: return TEMP_CELSIUS return TEMP_FAHRENHEIT diff --git a/homeassistant/components/screenlogic/config_flow.py b/homeassistant/components/screenlogic/config_flow.py index fb33bd7e227..05eaedf5ab7 100644 --- a/homeassistant/components/screenlogic/config_flow.py +++ b/homeassistant/components/screenlogic/config_flow.py @@ -1,7 +1,7 @@ """Config flow for ScreenLogic.""" import logging -from screenlogicpy import ScreenLogicError, discover +from screenlogicpy import ScreenLogicError, discovery from screenlogicpy.const import SL_GATEWAY_IP, SL_GATEWAY_NAME, SL_GATEWAY_PORT from screenlogicpy.requests import login import voluptuous as vol @@ -27,7 +27,7 @@ async def async_discover_gateways_by_unique_id(hass): """Discover gateways and return a dict of them by unique id.""" discovered_gateways = {} try: - hosts = await hass.async_add_executor_job(discover) + hosts = await discovery.async_discover() _LOGGER.debug("Discovered hosts: %s", hosts) except ScreenLogicError as ex: _LOGGER.debug(ex) diff --git a/homeassistant/components/screenlogic/manifest.json b/homeassistant/components/screenlogic/manifest.json index e4d1be9bfb4..abef9ec99ed 100644 --- a/homeassistant/components/screenlogic/manifest.json +++ b/homeassistant/components/screenlogic/manifest.json @@ -3,7 +3,7 @@ "name": "Pentair ScreenLogic", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/screenlogic", - "requirements": ["screenlogicpy==0.3.0"], + "requirements": ["screenlogicpy==0.4.1"], "codeowners": ["@dieselrabbit"], "dhcp": [ { diff --git a/requirements_all.txt b/requirements_all.txt index aa8d605f997..47bd4ab7499 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2033,7 +2033,7 @@ scapy==2.4.5 schiene==0.23 # homeassistant.components.screenlogic -screenlogicpy==0.3.0 +screenlogicpy==0.4.1 # homeassistant.components.scsgate scsgate==0.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 5fd213671d7..7ca01cdfe68 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1082,7 +1082,7 @@ samsungtvws==1.6.0 scapy==2.4.5 # homeassistant.components.screenlogic -screenlogicpy==0.3.0 +screenlogicpy==0.4.1 # homeassistant.components.emulated_kasa # homeassistant.components.sense diff --git a/tests/components/screenlogic/test_config_flow.py b/tests/components/screenlogic/test_config_flow.py index f64e35a28b6..a24ce36e7a1 100644 --- a/tests/components/screenlogic/test_config_flow.py +++ b/tests/components/screenlogic/test_config_flow.py @@ -30,7 +30,7 @@ async def test_flow_discovery(hass): """Test the flow works with basic discovery.""" await setup.async_setup_component(hass, "persistent_notification", {}) with patch( - "homeassistant.components.screenlogic.config_flow.discover", + "homeassistant.components.screenlogic.config_flow.discovery.async_discover", return_value=[ { SL_GATEWAY_IP: "1.1.1.1", @@ -74,7 +74,7 @@ async def test_flow_discover_none(hass): """Test when nothing is discovered.""" await setup.async_setup_component(hass, "persistent_notification", {}) with patch( - "homeassistant.components.screenlogic.config_flow.discover", + "homeassistant.components.screenlogic.config_flow.discovery.async_discover", return_value=[], ): result = await hass.config_entries.flow.async_init( @@ -90,7 +90,7 @@ async def test_flow_discover_error(hass): """Test when discovery errors.""" await setup.async_setup_component(hass, "persistent_notification", {}) with patch( - "homeassistant.components.screenlogic.config_flow.discover", + "homeassistant.components.screenlogic.config_flow.discovery.async_discover", side_effect=ScreenLogicError("Fake error"), ): result = await hass.config_entries.flow.async_init( @@ -182,7 +182,7 @@ async def test_form_manual_entry(hass): """Test we get the form.""" await setup.async_setup_component(hass, "persistent_notification", {}) with patch( - "homeassistant.components.screenlogic.config_flow.discover", + "homeassistant.components.screenlogic.config_flow.discovery.async_discover", return_value=[ { SL_GATEWAY_IP: "1.1.1.1", @@ -241,9 +241,13 @@ async def test_form_manual_entry(hass): async def test_form_cannot_connect(hass): """Test we handle cannot connect error.""" - result = await hass.config_entries.flow.async_init( - DOMAIN, context={"source": config_entries.SOURCE_USER} - ) + with patch( + "homeassistant.components.screenlogic.config_flow.discovery.async_discover", + return_value=[], + ): + result = await hass.config_entries.flow.async_init( + DOMAIN, context={"source": config_entries.SOURCE_USER} + ) with patch( "homeassistant.components.screenlogic.config_flow.login.create_socket",