Clean up homematicip cloud (#19481)
* Better logging, remove unused method, re-try handling fix. Other minor fixes. * fix test * typo fix
This commit is contained in:
parent
b2081c579b
commit
18b7f74ad7
2 changed files with 13 additions and 23 deletions
|
@ -96,7 +96,7 @@ class HomematicipHAP:
|
||||||
self.config_entry.data.get(HMIPC_NAME)
|
self.config_entry.data.get(HMIPC_NAME)
|
||||||
)
|
)
|
||||||
except HmipcConnectionError:
|
except HmipcConnectionError:
|
||||||
retry_delay = 2 ** min(tries + 1, 6)
|
retry_delay = 2 ** min(tries, 8)
|
||||||
_LOGGER.error("Error connecting to HomematicIP with HAP %s. "
|
_LOGGER.error("Error connecting to HomematicIP with HAP %s. "
|
||||||
"Retrying in %d seconds",
|
"Retrying in %d seconds",
|
||||||
self.config_entry.data.get(HMIPC_HAPID), retry_delay)
|
self.config_entry.data.get(HMIPC_HAPID), retry_delay)
|
||||||
|
@ -138,6 +138,8 @@ class HomematicipHAP:
|
||||||
self._accesspoint_connected = False
|
self._accesspoint_connected = False
|
||||||
self.set_all_to_unavailable()
|
self.set_all_to_unavailable()
|
||||||
elif not self._accesspoint_connected:
|
elif not self._accesspoint_connected:
|
||||||
|
# Now the HOME_CHANGED event has fired indicating the access
|
||||||
|
# point has reconnected to the cloud again.
|
||||||
# Explicitly getting an update as device states might have
|
# Explicitly getting an update as device states might have
|
||||||
# changed during access point disconnect."""
|
# changed during access point disconnect."""
|
||||||
|
|
||||||
|
@ -173,43 +175,30 @@ class HomematicipHAP:
|
||||||
for device in self.home.devices:
|
for device in self.home.devices:
|
||||||
device.fire_update_event()
|
device.fire_update_event()
|
||||||
|
|
||||||
async def _handle_connection(self):
|
|
||||||
"""Handle websocket connection."""
|
|
||||||
from homematicip.base.base_connection import HmipConnectionError
|
|
||||||
|
|
||||||
try:
|
|
||||||
await self.home.get_current_state()
|
|
||||||
except HmipConnectionError:
|
|
||||||
return
|
|
||||||
hmip_events = await self.home.enable_events()
|
|
||||||
try:
|
|
||||||
await hmip_events
|
|
||||||
except HmipConnectionError:
|
|
||||||
return
|
|
||||||
|
|
||||||
async def async_connect(self):
|
async def async_connect(self):
|
||||||
"""Start WebSocket connection."""
|
"""Start WebSocket connection."""
|
||||||
from homematicip.base.base_connection import HmipConnectionError
|
from homematicip.base.base_connection import HmipConnectionError
|
||||||
|
|
||||||
tries = 0
|
tries = 0
|
||||||
while True:
|
while True:
|
||||||
|
retry_delay = 2 ** min(tries, 8)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await self.home.get_current_state()
|
await self.home.get_current_state()
|
||||||
hmip_events = await self.home.enable_events()
|
hmip_events = await self.home.enable_events()
|
||||||
tries = 0
|
tries = 0
|
||||||
await hmip_events
|
await hmip_events
|
||||||
except HmipConnectionError:
|
except HmipConnectionError:
|
||||||
pass
|
_LOGGER.error("Error connecting to HomematicIP with HAP %s. "
|
||||||
|
"Retrying in %d seconds",
|
||||||
|
self.config_entry.data.get(HMIPC_HAPID),
|
||||||
|
retry_delay)
|
||||||
|
|
||||||
if self._ws_close_requested:
|
if self._ws_close_requested:
|
||||||
break
|
break
|
||||||
self._ws_close_requested = False
|
self._ws_close_requested = False
|
||||||
|
|
||||||
tries += 1
|
tries += 1
|
||||||
retry_delay = 2 ** min(tries + 1, 6)
|
|
||||||
_LOGGER.error("Error connecting to HomematicIP with HAP %s. "
|
|
||||||
"Retrying in %d seconds",
|
|
||||||
self.config_entry.data.get(HMIPC_HAPID), retry_delay)
|
|
||||||
try:
|
try:
|
||||||
self._retry_task = self.hass.async_create_task(asyncio.sleep(
|
self._retry_task = self.hass.async_create_task(asyncio.sleep(
|
||||||
retry_delay, loop=self.hass.loop))
|
retry_delay, loop=self.hass.loop))
|
||||||
|
@ -224,7 +213,7 @@ class HomematicipHAP:
|
||||||
self._retry_setup.cancel()
|
self._retry_setup.cancel()
|
||||||
if self._retry_task is not None:
|
if self._retry_task is not None:
|
||||||
self._retry_task.cancel()
|
self._retry_task.cancel()
|
||||||
self.home.disable_events()
|
await self.home.disable_events()
|
||||||
_LOGGER.info("Closed connection to HomematicIP cloud server")
|
_LOGGER.info("Closed connection to HomematicIP cloud server")
|
||||||
for component in COMPONENTS:
|
for component in COMPONENTS:
|
||||||
await self.hass.config_entries.async_forward_entry_unload(
|
await self.hass.config_entries.async_forward_entry_unload(
|
||||||
|
|
|
@ -3,7 +3,7 @@ from unittest.mock import Mock, patch
|
||||||
|
|
||||||
from homeassistant.components.homematicip_cloud import hap as hmipc
|
from homeassistant.components.homematicip_cloud import hap as hmipc
|
||||||
from homeassistant.components.homematicip_cloud import const, errors
|
from homeassistant.components.homematicip_cloud import const, errors
|
||||||
from tests.common import mock_coro
|
from tests.common import mock_coro, mock_coro_func
|
||||||
|
|
||||||
|
|
||||||
async def test_auth_setup(hass):
|
async def test_auth_setup(hass):
|
||||||
|
@ -95,6 +95,7 @@ async def test_hap_reset_unloads_entry_if_setup():
|
||||||
hass = Mock()
|
hass = Mock()
|
||||||
entry = Mock()
|
entry = Mock()
|
||||||
home = Mock()
|
home = Mock()
|
||||||
|
home.disable_events = mock_coro_func()
|
||||||
entry.data = {
|
entry.data = {
|
||||||
hmipc.HMIPC_HAPID: 'ABC123',
|
hmipc.HMIPC_HAPID: 'ABC123',
|
||||||
hmipc.HMIPC_AUTHTOKEN: '123',
|
hmipc.HMIPC_AUTHTOKEN: '123',
|
||||||
|
|
Loading…
Add table
Reference in a new issue