From 11f121b0083fbe97a23312ce06838c26da766045 Mon Sep 17 00:00:00 2001 From: bsmappee <58250533+bsmappee@users.noreply.github.com> Date: Wed, 26 Aug 2020 00:37:53 +0200 Subject: [PATCH] Implement local discovery of Smappee series-2 devices and improvements (#38728) * prepare local api support for Smappee2-series * Series-2 devices are now supported * remove switch scan_interval --- homeassistant/components/smappee/config_flow.py | 15 ++++++++++++--- homeassistant/components/smappee/const.py | 2 ++ homeassistant/components/smappee/manifest.json | 2 +- homeassistant/components/smappee/switch.py | 2 -- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/smappee/test_config_flow.py | 2 +- 7 files changed, 18 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/smappee/config_flow.py b/homeassistant/components/smappee/config_flow.py index 32f74aa9736..26a47815f34 100644 --- a/homeassistant/components/smappee/config_flow.py +++ b/homeassistant/components/smappee/config_flow.py @@ -8,7 +8,14 @@ from homeassistant.const import CONF_HOST, CONF_IP_ADDRESS from homeassistant.helpers import config_entry_oauth2_flow from . import api -from .const import CONF_HOSTNAME, CONF_SERIALNUMBER, DOMAIN, ENV_CLOUD, ENV_LOCAL +from .const import ( + CONF_HOSTNAME, + CONF_SERIALNUMBER, + DOMAIN, + ENV_CLOUD, + ENV_LOCAL, + SUPPORTED_LOCAL_DEVICES, +) _LOGGER = logging.getLogger(__name__) @@ -35,7 +42,7 @@ class SmappeeFlowHandler( async def async_step_zeroconf(self, discovery_info): """Handle zeroconf discovery.""" - if not discovery_info[CONF_HOSTNAME].startswith("Smappee1"): + if not discovery_info[CONF_HOSTNAME].startswith(SUPPORTED_LOCAL_DEVICES): # We currently only support Energy and Solar models (legacy) return self.async_abort(reason="invalid_mdns") @@ -152,7 +159,9 @@ class SmappeeFlowHandler( if config_item["key"] == "mdnsHostName": serial_number = config_item["value"] - if serial_number is None or not serial_number.startswith("Smappee1"): + if serial_number is None or not serial_number.startswith( + SUPPORTED_LOCAL_DEVICES + ): # We currently only support Energy and Solar models (legacy) return self.async_abort(reason="invalid_mdns") diff --git a/homeassistant/components/smappee/const.py b/homeassistant/components/smappee/const.py index 531327b8369..2c69f1ccb96 100644 --- a/homeassistant/components/smappee/const.py +++ b/homeassistant/components/smappee/const.py @@ -14,6 +14,8 @@ ENV_LOCAL = "local" SMAPPEE_PLATFORMS = ["binary_sensor", "sensor", "switch"] +SUPPORTED_LOCAL_DEVICES = ("Smappee1", "Smappee2") + MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=20) AUTHORIZE_URL = { diff --git a/homeassistant/components/smappee/manifest.json b/homeassistant/components/smappee/manifest.json index fe0b0de281c..1d918c06cc0 100644 --- a/homeassistant/components/smappee/manifest.json +++ b/homeassistant/components/smappee/manifest.json @@ -5,7 +5,7 @@ "documentation": "https://www.home-assistant.io/integrations/smappee", "dependencies": ["http"], "requirements": [ - "pysmappee==0.2.9" + "pysmappee==0.2.10" ], "codeowners": [ "@bsmappee" diff --git a/homeassistant/components/smappee/switch.py b/homeassistant/components/smappee/switch.py index a845386e71c..4d158df852a 100644 --- a/homeassistant/components/smappee/switch.py +++ b/homeassistant/components/smappee/switch.py @@ -1,5 +1,4 @@ """Support for interacting with Smappee Comport Plugs, Switches and Output Modules.""" -from datetime import timedelta import logging from homeassistant.components.switch import SwitchEntity @@ -10,7 +9,6 @@ _LOGGER = logging.getLogger(__name__) SWITCH_PREFIX = "Switch" ICON = "mdi:toggle-switch" -SCAN_INTERVAL = timedelta(seconds=5) async def async_setup_entry(hass, config_entry, async_add_entities): diff --git a/requirements_all.txt b/requirements_all.txt index d2f43817c20..e543e325592 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1633,7 +1633,7 @@ pyskyqhub==0.1.1 pysma==0.3.5 # homeassistant.components.smappee -pysmappee==0.2.9 +pysmappee==0.2.10 # homeassistant.components.smartthings pysmartapp==0.3.2 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index f1815470aa7..3b5d1765455 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -771,7 +771,7 @@ pysignalclirestapi==0.3.4 pysma==0.3.5 # homeassistant.components.smappee -pysmappee==0.2.9 +pysmappee==0.2.10 # homeassistant.components.smartthings pysmartapp==0.3.2 diff --git a/tests/components/smappee/test_config_flow.py b/tests/components/smappee/test_config_flow.py index 38f3ac480ef..92e5ebfb7e9 100644 --- a/tests/components/smappee/test_config_flow.py +++ b/tests/components/smappee/test_config_flow.py @@ -119,7 +119,7 @@ async def test_full_user_wrong_mdns(hass): """Test we abort user flow if unsupported mDNS name got resolved.""" with patch("pysmappee.api.SmappeeLocalApi.logon", return_value={}), patch( "pysmappee.api.SmappeeLocalApi.load_advanced_config", - return_value=[{"key": "mdnsHostName", "value": "Smappee2006000212"}], + return_value=[{"key": "mdnsHostName", "value": "Smappee5010000001"}], ), patch( "pysmappee.api.SmappeeLocalApi.load_command_control_config", return_value=[] ), patch(