Skip to content

Commit 92195ff

Browse files
alengwenusedenhaus
andauthored
Bump pypck to 0.8.1 (#133646)
Co-authored-by: Robert Resch <[email protected]>
1 parent ad7a334 commit 92195ff

File tree

7 files changed

+63
-31
lines changed

7 files changed

+63
-31
lines changed

homeassistant/components/lcn/__init__.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
import logging
77

88
import pypck
9-
from pypck.connection import PchkConnectionManager
9+
from pypck.connection import (
10+
PchkAuthenticationError,
11+
PchkConnectionFailedError,
12+
PchkConnectionManager,
13+
PchkConnectionRefusedError,
14+
PchkLcnNotConnectedError,
15+
PchkLicenseError,
16+
)
1017

1118
from homeassistant.config_entries import ConfigEntry
1219
from homeassistant.const import (
@@ -20,6 +27,7 @@
2027
Platform,
2128
)
2229
from homeassistant.core import HomeAssistant
30+
from homeassistant.exceptions import ConfigEntryNotReady
2331
from homeassistant.helpers import config_validation as cv, device_registry as dr
2432
from homeassistant.helpers.typing import ConfigType
2533

@@ -81,31 +89,29 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
8189
settings=settings,
8290
connection_id=config_entry.entry_id,
8391
)
92+
8493
try:
8594
# establish connection to PCHK server
8695
await lcn_connection.async_connect(timeout=15)
87-
except pypck.connection.PchkAuthenticationError:
88-
_LOGGER.warning('Authentication on PCHK "%s" failed', config_entry.title)
89-
return False
90-
except pypck.connection.PchkLicenseError:
91-
_LOGGER.warning(
92-
(
93-
'Maximum number of connections on PCHK "%s" was '
94-
"reached. An additional license key is required"
95-
),
96-
config_entry.title,
97-
)
98-
return False
99-
except TimeoutError:
100-
_LOGGER.warning('Connection to PCHK "%s" failed', config_entry.title)
101-
return False
96+
except (
97+
PchkAuthenticationError,
98+
PchkLicenseError,
99+
PchkConnectionRefusedError,
100+
PchkConnectionFailedError,
101+
PchkLcnNotConnectedError,
102+
) as ex:
103+
await lcn_connection.async_close()
104+
raise ConfigEntryNotReady(
105+
f"Unable to connect to {config_entry.title}: {ex}"
106+
) from ex
102107

103108
_LOGGER.debug('LCN connected to "%s"', config_entry.title)
104109
hass.data[DOMAIN][config_entry.entry_id] = {
105110
CONNECTION: lcn_connection,
106111
DEVICE_CONNECTIONS: {},
107112
ADD_ENTITIES_CALLBACKS: {},
108113
}
114+
109115
# Update config_entry with LCN device serials
110116
await async_update_config_entry(hass, config_entry)
111117

@@ -121,6 +127,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
121127
input_received = partial(
122128
async_host_input_received, hass, config_entry, device_registry
123129
)
130+
124131
lcn_connection.register_for_inputs(input_received)
125132

126133
return True

homeassistant/components/lcn/config_flow.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ async def validate_connection(data: ConfigType) -> str | None:
9696
host_name,
9797
)
9898
error = "license_error"
99-
except (TimeoutError, ConnectionRefusedError):
99+
except (
100+
pypck.connection.PchkConnectionFailedError,
101+
pypck.connection.PchkConnectionRefusedError,
102+
):
100103
_LOGGER.warning('Connection to PCHK "%s" failed', host_name)
101104
error = "connection_refused"
102105

homeassistant/components/lcn/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"documentation": "https://www.home-assistant.io/integrations/lcn",
99
"iot_class": "local_push",
1010
"loggers": ["pypck"],
11-
"requirements": ["pypck==0.7.24", "lcn-frontend==0.2.2"]
11+
"requirements": ["pypck==0.8.1", "lcn-frontend==0.2.2"]
1212
}

requirements_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,7 @@ pypalazzetti==0.1.15
21742174
pypca==0.0.7
21752175

21762176
# homeassistant.components.lcn
2177-
pypck==0.7.24
2177+
pypck==0.8.1
21782178

21792179
# homeassistant.components.pjlink
21802180
pypjlink2==1.2.1

requirements_test_all.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1767,7 +1767,7 @@ pyownet==0.10.0.post1
17671767
pypalazzetti==0.1.15
17681768

17691769
# homeassistant.components.lcn
1770-
pypck==0.7.24
1770+
pypck==0.8.1
17711771

17721772
# homeassistant.components.pjlink
17731773
pypjlink2==1.2.1

tests/components/lcn/test_config_flow.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
from unittest.mock import patch
44

5-
from pypck.connection import PchkAuthenticationError, PchkLicenseError
5+
from pypck.connection import (
6+
PchkAuthenticationError,
7+
PchkConnectionFailedError,
8+
PchkConnectionRefusedError,
9+
PchkLicenseError,
10+
)
611
import pytest
712

813
from homeassistant import config_entries, data_entry_flow
@@ -98,7 +103,8 @@ async def test_step_user_existing_host(
98103
[
99104
(PchkAuthenticationError, {CONF_BASE: "authentication_error"}),
100105
(PchkLicenseError, {CONF_BASE: "license_error"}),
101-
(TimeoutError, {CONF_BASE: "connection_refused"}),
106+
(PchkConnectionFailedError, {CONF_BASE: "connection_refused"}),
107+
(PchkConnectionRefusedError, {CONF_BASE: "connection_refused"}),
102108
],
103109
)
104110
async def test_step_user_error(
@@ -149,7 +155,8 @@ async def test_step_reconfigure(hass: HomeAssistant, entry: MockConfigEntry) ->
149155
[
150156
(PchkAuthenticationError, {CONF_BASE: "authentication_error"}),
151157
(PchkLicenseError, {CONF_BASE: "license_error"}),
152-
(TimeoutError, {CONF_BASE: "connection_refused"}),
158+
(PchkConnectionFailedError, {CONF_BASE: "connection_refused"}),
159+
(PchkConnectionRefusedError, {CONF_BASE: "connection_refused"}),
153160
],
154161
)
155162
async def test_step_reconfigure_error(

tests/components/lcn/test_init.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33
from unittest.mock import Mock, patch
44

5-
from pypck.connection import PchkAuthenticationError, PchkLicenseError
5+
from pypck.connection import (
6+
PchkAuthenticationError,
7+
PchkConnectionFailedError,
8+
PchkConnectionRefusedError,
9+
PchkLcnNotConnectedError,
10+
PchkLicenseError,
11+
)
612
import pytest
713

814
from homeassistant import config_entries
@@ -84,21 +90,30 @@ async def test_async_setup_entry_update(
8490

8591

8692
@pytest.mark.parametrize(
87-
"exception", [PchkAuthenticationError, PchkLicenseError, TimeoutError]
93+
"exception",
94+
[
95+
PchkAuthenticationError,
96+
PchkLicenseError,
97+
PchkConnectionRefusedError,
98+
PchkConnectionFailedError,
99+
PchkLcnNotConnectedError,
100+
],
88101
)
89-
async def test_async_setup_entry_raises_authentication_error(
102+
async def test_async_setup_entry_fails(
90103
hass: HomeAssistant, entry: MockConfigEntry, exception: Exception
91104
) -> None:
92-
"""Test that an authentication error is handled properly."""
93-
with patch(
94-
"homeassistant.components.lcn.PchkConnectionManager.async_connect",
95-
side_effect=exception,
105+
"""Test that an error is handled properly."""
106+
with (
107+
patch(
108+
"homeassistant.components.lcn.PchkConnectionManager.async_connect",
109+
side_effect=exception,
110+
),
96111
):
97112
entry.add_to_hass(hass)
98113
await hass.config_entries.async_setup(entry.entry_id)
99114
await hass.async_block_till_done()
100115

101-
assert entry.state is ConfigEntryState.SETUP_ERROR
116+
assert entry.state is ConfigEntryState.SETUP_RETRY
102117

103118

104119
@patch("homeassistant.components.lcn.PchkConnectionManager", MockPchkConnectionManager)

0 commit comments

Comments
 (0)