mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Bump pypck to 0.8.1 (#133646)
Co-authored-by: Robert Resch <robert@resch.dev>
This commit is contained in:
parent
ad7a334147
commit
92195ff77d
@ -6,7 +6,14 @@ from functools import partial
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
import pypck
|
import pypck
|
||||||
from pypck.connection import PchkConnectionManager
|
from pypck.connection import (
|
||||||
|
PchkAuthenticationError,
|
||||||
|
PchkConnectionFailedError,
|
||||||
|
PchkConnectionManager,
|
||||||
|
PchkConnectionRefusedError,
|
||||||
|
PchkLcnNotConnectedError,
|
||||||
|
PchkLicenseError,
|
||||||
|
)
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
@ -20,6 +27,7 @@ from homeassistant.const import (
|
|||||||
Platform,
|
Platform,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
from homeassistant.exceptions import ConfigEntryNotReady
|
||||||
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
from homeassistant.helpers import config_validation as cv, device_registry as dr
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
@ -81,24 +89,21 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
settings=settings,
|
settings=settings,
|
||||||
connection_id=config_entry.entry_id,
|
connection_id=config_entry.entry_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# establish connection to PCHK server
|
# establish connection to PCHK server
|
||||||
await lcn_connection.async_connect(timeout=15)
|
await lcn_connection.async_connect(timeout=15)
|
||||||
except pypck.connection.PchkAuthenticationError:
|
except (
|
||||||
_LOGGER.warning('Authentication on PCHK "%s" failed', config_entry.title)
|
PchkAuthenticationError,
|
||||||
return False
|
PchkLicenseError,
|
||||||
except pypck.connection.PchkLicenseError:
|
PchkConnectionRefusedError,
|
||||||
_LOGGER.warning(
|
PchkConnectionFailedError,
|
||||||
(
|
PchkLcnNotConnectedError,
|
||||||
'Maximum number of connections on PCHK "%s" was '
|
) as ex:
|
||||||
"reached. An additional license key is required"
|
await lcn_connection.async_close()
|
||||||
),
|
raise ConfigEntryNotReady(
|
||||||
config_entry.title,
|
f"Unable to connect to {config_entry.title}: {ex}"
|
||||||
)
|
) from ex
|
||||||
return False
|
|
||||||
except TimeoutError:
|
|
||||||
_LOGGER.warning('Connection to PCHK "%s" failed', config_entry.title)
|
|
||||||
return False
|
|
||||||
|
|
||||||
_LOGGER.debug('LCN connected to "%s"', config_entry.title)
|
_LOGGER.debug('LCN connected to "%s"', config_entry.title)
|
||||||
hass.data[DOMAIN][config_entry.entry_id] = {
|
hass.data[DOMAIN][config_entry.entry_id] = {
|
||||||
@ -106,6 +111,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
DEVICE_CONNECTIONS: {},
|
DEVICE_CONNECTIONS: {},
|
||||||
ADD_ENTITIES_CALLBACKS: {},
|
ADD_ENTITIES_CALLBACKS: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
# Update config_entry with LCN device serials
|
# Update config_entry with LCN device serials
|
||||||
await async_update_config_entry(hass, config_entry)
|
await async_update_config_entry(hass, config_entry)
|
||||||
|
|
||||||
@ -121,6 +127,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
|||||||
input_received = partial(
|
input_received = partial(
|
||||||
async_host_input_received, hass, config_entry, device_registry
|
async_host_input_received, hass, config_entry, device_registry
|
||||||
)
|
)
|
||||||
|
|
||||||
lcn_connection.register_for_inputs(input_received)
|
lcn_connection.register_for_inputs(input_received)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -96,7 +96,10 @@ async def validate_connection(data: ConfigType) -> str | None:
|
|||||||
host_name,
|
host_name,
|
||||||
)
|
)
|
||||||
error = "license_error"
|
error = "license_error"
|
||||||
except (TimeoutError, ConnectionRefusedError):
|
except (
|
||||||
|
pypck.connection.PchkConnectionFailedError,
|
||||||
|
pypck.connection.PchkConnectionRefusedError,
|
||||||
|
):
|
||||||
_LOGGER.warning('Connection to PCHK "%s" failed', host_name)
|
_LOGGER.warning('Connection to PCHK "%s" failed', host_name)
|
||||||
error = "connection_refused"
|
error = "connection_refused"
|
||||||
|
|
||||||
|
@ -8,5 +8,5 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/lcn",
|
"documentation": "https://www.home-assistant.io/integrations/lcn",
|
||||||
"iot_class": "local_push",
|
"iot_class": "local_push",
|
||||||
"loggers": ["pypck"],
|
"loggers": ["pypck"],
|
||||||
"requirements": ["pypck==0.7.24", "lcn-frontend==0.2.2"]
|
"requirements": ["pypck==0.8.1", "lcn-frontend==0.2.2"]
|
||||||
}
|
}
|
||||||
|
@ -2174,7 +2174,7 @@ pypalazzetti==0.1.15
|
|||||||
pypca==0.0.7
|
pypca==0.0.7
|
||||||
|
|
||||||
# homeassistant.components.lcn
|
# homeassistant.components.lcn
|
||||||
pypck==0.7.24
|
pypck==0.8.1
|
||||||
|
|
||||||
# homeassistant.components.pjlink
|
# homeassistant.components.pjlink
|
||||||
pypjlink2==1.2.1
|
pypjlink2==1.2.1
|
||||||
|
@ -1767,7 +1767,7 @@ pyownet==0.10.0.post1
|
|||||||
pypalazzetti==0.1.15
|
pypalazzetti==0.1.15
|
||||||
|
|
||||||
# homeassistant.components.lcn
|
# homeassistant.components.lcn
|
||||||
pypck==0.7.24
|
pypck==0.8.1
|
||||||
|
|
||||||
# homeassistant.components.pjlink
|
# homeassistant.components.pjlink
|
||||||
pypjlink2==1.2.1
|
pypjlink2==1.2.1
|
||||||
|
@ -2,7 +2,12 @@
|
|||||||
|
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from pypck.connection import PchkAuthenticationError, PchkLicenseError
|
from pypck.connection import (
|
||||||
|
PchkAuthenticationError,
|
||||||
|
PchkConnectionFailedError,
|
||||||
|
PchkConnectionRefusedError,
|
||||||
|
PchkLicenseError,
|
||||||
|
)
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries, data_entry_flow
|
from homeassistant import config_entries, data_entry_flow
|
||||||
@ -98,7 +103,8 @@ async def test_step_user_existing_host(
|
|||||||
[
|
[
|
||||||
(PchkAuthenticationError, {CONF_BASE: "authentication_error"}),
|
(PchkAuthenticationError, {CONF_BASE: "authentication_error"}),
|
||||||
(PchkLicenseError, {CONF_BASE: "license_error"}),
|
(PchkLicenseError, {CONF_BASE: "license_error"}),
|
||||||
(TimeoutError, {CONF_BASE: "connection_refused"}),
|
(PchkConnectionFailedError, {CONF_BASE: "connection_refused"}),
|
||||||
|
(PchkConnectionRefusedError, {CONF_BASE: "connection_refused"}),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_step_user_error(
|
async def test_step_user_error(
|
||||||
@ -149,7 +155,8 @@ async def test_step_reconfigure(hass: HomeAssistant, entry: MockConfigEntry) ->
|
|||||||
[
|
[
|
||||||
(PchkAuthenticationError, {CONF_BASE: "authentication_error"}),
|
(PchkAuthenticationError, {CONF_BASE: "authentication_error"}),
|
||||||
(PchkLicenseError, {CONF_BASE: "license_error"}),
|
(PchkLicenseError, {CONF_BASE: "license_error"}),
|
||||||
(TimeoutError, {CONF_BASE: "connection_refused"}),
|
(PchkConnectionFailedError, {CONF_BASE: "connection_refused"}),
|
||||||
|
(PchkConnectionRefusedError, {CONF_BASE: "connection_refused"}),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_step_reconfigure_error(
|
async def test_step_reconfigure_error(
|
||||||
|
@ -2,7 +2,13 @@
|
|||||||
|
|
||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
from pypck.connection import PchkAuthenticationError, PchkLicenseError
|
from pypck.connection import (
|
||||||
|
PchkAuthenticationError,
|
||||||
|
PchkConnectionFailedError,
|
||||||
|
PchkConnectionRefusedError,
|
||||||
|
PchkLcnNotConnectedError,
|
||||||
|
PchkLicenseError,
|
||||||
|
)
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -84,21 +90,30 @@ async def test_async_setup_entry_update(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"exception", [PchkAuthenticationError, PchkLicenseError, TimeoutError]
|
"exception",
|
||||||
|
[
|
||||||
|
PchkAuthenticationError,
|
||||||
|
PchkLicenseError,
|
||||||
|
PchkConnectionRefusedError,
|
||||||
|
PchkConnectionFailedError,
|
||||||
|
PchkLcnNotConnectedError,
|
||||||
|
],
|
||||||
)
|
)
|
||||||
async def test_async_setup_entry_raises_authentication_error(
|
async def test_async_setup_entry_fails(
|
||||||
hass: HomeAssistant, entry: MockConfigEntry, exception: Exception
|
hass: HomeAssistant, entry: MockConfigEntry, exception: Exception
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that an authentication error is handled properly."""
|
"""Test that an error is handled properly."""
|
||||||
with patch(
|
with (
|
||||||
"homeassistant.components.lcn.PchkConnectionManager.async_connect",
|
patch(
|
||||||
side_effect=exception,
|
"homeassistant.components.lcn.PchkConnectionManager.async_connect",
|
||||||
|
side_effect=exception,
|
||||||
|
),
|
||||||
):
|
):
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert entry.state is ConfigEntryState.SETUP_ERROR
|
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||||
|
|
||||||
|
|
||||||
@patch("homeassistant.components.lcn.PchkConnectionManager", MockPchkConnectionManager)
|
@patch("homeassistant.components.lcn.PchkConnectionManager", MockPchkConnectionManager)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user