6
6
import logging
7
7
8
8
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
+ )
10
17
11
18
from homeassistant .config_entries import ConfigEntry
12
19
from homeassistant .const import (
20
27
Platform ,
21
28
)
22
29
from homeassistant .core import HomeAssistant
30
+ from homeassistant .exceptions import ConfigEntryNotReady
23
31
from homeassistant .helpers import config_validation as cv , device_registry as dr
24
32
from homeassistant .helpers .typing import ConfigType
25
33
@@ -81,31 +89,29 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
81
89
settings = settings ,
82
90
connection_id = config_entry .entry_id ,
83
91
)
92
+
84
93
try :
85
94
# establish connection to PCHK server
86
95
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
102
107
103
108
_LOGGER .debug ('LCN connected to "%s"' , config_entry .title )
104
109
hass .data [DOMAIN ][config_entry .entry_id ] = {
105
110
CONNECTION : lcn_connection ,
106
111
DEVICE_CONNECTIONS : {},
107
112
ADD_ENTITIES_CALLBACKS : {},
108
113
}
114
+
109
115
# Update config_entry with LCN device serials
110
116
await async_update_config_entry (hass , config_entry )
111
117
@@ -121,6 +127,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
121
127
input_received = partial (
122
128
async_host_input_received , hass , config_entry , device_registry
123
129
)
130
+
124
131
lcn_connection .register_for_inputs (input_received )
125
132
126
133
return True
0 commit comments