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
This commit is contained in:
bsmappee 2020-08-26 00:37:53 +02:00 committed by GitHub
parent c87e03ee6f
commit 11f121b008
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 9 deletions

View file

@ -8,7 +8,14 @@ from homeassistant.const import CONF_HOST, CONF_IP_ADDRESS
from homeassistant.helpers import config_entry_oauth2_flow from homeassistant.helpers import config_entry_oauth2_flow
from . import api 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__) _LOGGER = logging.getLogger(__name__)
@ -35,7 +42,7 @@ class SmappeeFlowHandler(
async def async_step_zeroconf(self, discovery_info): async def async_step_zeroconf(self, discovery_info):
"""Handle zeroconf discovery.""" """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) # We currently only support Energy and Solar models (legacy)
return self.async_abort(reason="invalid_mdns") return self.async_abort(reason="invalid_mdns")
@ -152,7 +159,9 @@ class SmappeeFlowHandler(
if config_item["key"] == "mdnsHostName": if config_item["key"] == "mdnsHostName":
serial_number = config_item["value"] 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) # We currently only support Energy and Solar models (legacy)
return self.async_abort(reason="invalid_mdns") return self.async_abort(reason="invalid_mdns")

View file

@ -14,6 +14,8 @@ ENV_LOCAL = "local"
SMAPPEE_PLATFORMS = ["binary_sensor", "sensor", "switch"] SMAPPEE_PLATFORMS = ["binary_sensor", "sensor", "switch"]
SUPPORTED_LOCAL_DEVICES = ("Smappee1", "Smappee2")
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=20) MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=20)
AUTHORIZE_URL = { AUTHORIZE_URL = {

View file

@ -5,7 +5,7 @@
"documentation": "https://www.home-assistant.io/integrations/smappee", "documentation": "https://www.home-assistant.io/integrations/smappee",
"dependencies": ["http"], "dependencies": ["http"],
"requirements": [ "requirements": [
"pysmappee==0.2.9" "pysmappee==0.2.10"
], ],
"codeowners": [ "codeowners": [
"@bsmappee" "@bsmappee"

View file

@ -1,5 +1,4 @@
"""Support for interacting with Smappee Comport Plugs, Switches and Output Modules.""" """Support for interacting with Smappee Comport Plugs, Switches and Output Modules."""
from datetime import timedelta
import logging import logging
from homeassistant.components.switch import SwitchEntity from homeassistant.components.switch import SwitchEntity
@ -10,7 +9,6 @@ _LOGGER = logging.getLogger(__name__)
SWITCH_PREFIX = "Switch" SWITCH_PREFIX = "Switch"
ICON = "mdi:toggle-switch" ICON = "mdi:toggle-switch"
SCAN_INTERVAL = timedelta(seconds=5)
async def async_setup_entry(hass, config_entry, async_add_entities): async def async_setup_entry(hass, config_entry, async_add_entities):

View file

@ -1633,7 +1633,7 @@ pyskyqhub==0.1.1
pysma==0.3.5 pysma==0.3.5
# homeassistant.components.smappee # homeassistant.components.smappee
pysmappee==0.2.9 pysmappee==0.2.10
# homeassistant.components.smartthings # homeassistant.components.smartthings
pysmartapp==0.3.2 pysmartapp==0.3.2

View file

@ -771,7 +771,7 @@ pysignalclirestapi==0.3.4
pysma==0.3.5 pysma==0.3.5
# homeassistant.components.smappee # homeassistant.components.smappee
pysmappee==0.2.9 pysmappee==0.2.10
# homeassistant.components.smartthings # homeassistant.components.smartthings
pysmartapp==0.3.2 pysmartapp==0.3.2

View file

@ -119,7 +119,7 @@ async def test_full_user_wrong_mdns(hass):
"""Test we abort user flow if unsupported mDNS name got resolved.""" """Test we abort user flow if unsupported mDNS name got resolved."""
with patch("pysmappee.api.SmappeeLocalApi.logon", return_value={}), patch( with patch("pysmappee.api.SmappeeLocalApi.logon", return_value={}), patch(
"pysmappee.api.SmappeeLocalApi.load_advanced_config", "pysmappee.api.SmappeeLocalApi.load_advanced_config",
return_value=[{"key": "mdnsHostName", "value": "Smappee2006000212"}], return_value=[{"key": "mdnsHostName", "value": "Smappee5010000001"}],
), patch( ), patch(
"pysmappee.api.SmappeeLocalApi.load_command_control_config", return_value=[] "pysmappee.api.SmappeeLocalApi.load_command_control_config", return_value=[]
), patch( ), patch(