Skip to content

Commit

Permalink
Increase sleep in Risco setup (#77619)
Browse files Browse the repository at this point in the history
  • Loading branch information
OnFreund authored and balloob committed Sep 2, 2022
1 parent d6b2f0f commit 8c697b1
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 16 deletions.
4 changes: 4 additions & 0 deletions homeassistant/components/risco/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Unload a config entry."""
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
if is_local(entry):
local_data: LocalData = hass.data[DOMAIN][entry.entry_id]
await local_data.system.disconnect()

hass.data[DOMAIN].pop(entry.entry_id)

return unload_ok
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/risco/config_flow.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Config flow for Risco integration."""
from __future__ import annotations

import asyncio
from collections.abc import Mapping
import logging

Expand Down Expand Up @@ -32,7 +31,6 @@
DEFAULT_OPTIONS,
DOMAIN,
RISCO_STATES,
SLEEP_INTERVAL,
TYPE_LOCAL,
)

Expand Down Expand Up @@ -150,9 +148,6 @@ async def async_step_local(self, user_input=None):
await self.async_set_unique_id(info["title"])
self._abort_if_unique_id_configured()

# Risco can hang if we don't wait before creating a new connection
await asyncio.sleep(SLEEP_INTERVAL)

return self.async_create_entry(
title=info["title"], data={**user_input, **{CONF_TYPE: TYPE_LOCAL}}
)
Expand Down
2 changes: 0 additions & 2 deletions homeassistant/components/risco/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,3 @@
CONF_RISCO_STATES_TO_HA: DEFAULT_RISCO_STATES_TO_HA,
CONF_HA_STATES_TO_RISCO: DEFAULT_HA_STATES_TO_RISCO,
}

SLEEP_INTERVAL = 1
2 changes: 1 addition & 1 deletion homeassistant/components/risco/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Risco",
"config_flow": true,
"documentation": "https://www.home-assistant.io/integrations/risco",
"requirements": ["pyrisco==0.5.3"],
"requirements": ["pyrisco==0.5.4"],
"codeowners": ["@OnFreund"],
"quality_scale": "platinum",
"iot_class": "local_push",
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1814,7 +1814,7 @@ pyrecswitch==1.0.2
pyrepetierng==0.1.0

# homeassistant.components.risco
pyrisco==0.5.3
pyrisco==0.5.4

# homeassistant.components.rituals_perfume_genie
pyrituals==0.0.6
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,7 @@ pyps4-2ndscreen==1.3.1
pyqwikswitch==0.93

# homeassistant.components.risco
pyrisco==0.5.3
pyrisco==0.5.4

# homeassistant.components.rituals_perfume_genie
pyrituals==0.0.6
Expand Down
3 changes: 3 additions & 0 deletions tests/components/risco/test_alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ async def test_local_setup(hass, two_part_local_alarm, setup_risco_local):
device = registry.async_get_device({(DOMAIN, TEST_SITE_UUID + "_1_local")})
assert device is not None
assert device.manufacturer == "Risco"
with patch("homeassistant.components.risco.RiscoLocal.disconnect") as mock_close:
await hass.config_entries.async_unload(setup_risco_local.entry_id)
mock_close.assert_awaited_once()


async def _check_local_state(
Expand Down
6 changes: 0 additions & 6 deletions tests/components/risco/test_config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ async def test_cloud_form(hass):
), patch(
"homeassistant.components.risco.config_flow.RiscoCloud.close"
) as mock_close, patch(
"homeassistant.components.risco.config_flow.SLEEP_INTERVAL",
0,
), patch(
"homeassistant.components.risco.async_setup_entry",
return_value=True,
) as mock_setup_entry:
Expand Down Expand Up @@ -168,9 +165,6 @@ async def test_local_form(hass):
), patch(
"homeassistant.components.risco.config_flow.RiscoLocal.disconnect"
) as mock_close, patch(
"homeassistant.components.risco.config_flow.SLEEP_INTERVAL",
0,
), patch(
"homeassistant.components.risco.async_setup_entry",
return_value=True,
) as mock_setup_entry:
Expand Down

0 comments on commit 8c697b1

Please sign in to comment.