44
55from synology_dsm import SynologyDSM
66from synology_dsm .exceptions import (
7+ SynologyDSMException ,
78 SynologyDSMLogin2SAFailedException ,
89 SynologyDSMLogin2SARequiredException ,
910 SynologyDSMLoginInvalidException ,
11+ SynologyDSMRequestException ,
1012)
1113import voluptuous as vol
1214
1315from homeassistant import config_entries , exceptions
1416from homeassistant .components import ssdp
1517from homeassistant .const import (
16- CONF_API_VERSION ,
1718 CONF_DISKS ,
1819 CONF_HOST ,
1920 CONF_NAME ,
2324 CONF_USERNAME ,
2425)
2526
26- from .const import (
27- CONF_VOLUMES ,
28- DEFAULT_DSM_VERSION ,
29- DEFAULT_PORT ,
30- DEFAULT_PORT_SSL ,
31- DEFAULT_SSL ,
32- )
27+ from .const import CONF_VOLUMES , DEFAULT_PORT , DEFAULT_PORT_SSL , DEFAULT_SSL
3328from .const import DOMAIN # pylint: disable=unused-import
3429
3530_LOGGER = logging .getLogger (__name__ )
@@ -56,12 +51,6 @@ def _ordered_shared_schema(schema_input):
5651 vol .Required (CONF_PASSWORD , default = schema_input .get (CONF_PASSWORD , "" )): str ,
5752 vol .Optional (CONF_PORT , default = schema_input .get (CONF_PORT , "" )): str ,
5853 vol .Optional (CONF_SSL , default = schema_input .get (CONF_SSL , DEFAULT_SSL )): bool ,
59- vol .Optional (
60- CONF_API_VERSION ,
61- default = schema_input .get (CONF_API_VERSION , DEFAULT_DSM_VERSION ),
62- ): vol .All (
63- vol .Coerce (int ), vol .In ([5 , 6 ]), # DSM versions supported by the library
64- ),
6554 }
6655
6756
@@ -111,7 +100,6 @@ async def async_step_user(self, user_input=None):
111100 username = user_input [CONF_USERNAME ]
112101 password = user_input [CONF_PASSWORD ]
113102 use_ssl = user_input .get (CONF_SSL , DEFAULT_SSL )
114- api_version = user_input .get (CONF_API_VERSION , DEFAULT_DSM_VERSION )
115103 otp_code = user_input .get (CONF_OTP_CODE )
116104
117105 if not port :
@@ -120,9 +108,7 @@ async def async_step_user(self, user_input=None):
120108 else :
121109 port = DEFAULT_PORT
122110
123- api = SynologyDSM (
124- host , port , username , password , use_ssl , dsm_version = api_version ,
125- )
111+ api = SynologyDSM (host , port , username , password , use_ssl )
126112
127113 try :
128114 serial = await self .hass .async_add_executor_job (
@@ -134,8 +120,12 @@ async def async_step_user(self, user_input=None):
134120 errors [CONF_OTP_CODE ] = "otp_failed"
135121 user_input [CONF_OTP_CODE ] = None
136122 return await self .async_step_2sa (user_input , errors )
137- except ( SynologyDSMLoginInvalidException , InvalidAuth ) :
123+ except SynologyDSMLoginInvalidException :
138124 errors [CONF_USERNAME ] = "login"
125+ except SynologyDSMRequestException :
126+ errors [CONF_HOST ] = "connection"
127+ except SynologyDSMException :
128+ errors ["base" ] = "unknown"
139129 except InvalidData :
140130 errors ["base" ] = "missing_data"
141131
@@ -152,7 +142,6 @@ async def async_step_user(self, user_input=None):
152142 CONF_SSL : use_ssl ,
153143 CONF_USERNAME : username ,
154144 CONF_PASSWORD : password ,
155- CONF_API_VERSION : api_version ,
156145 }
157146 if otp_code :
158147 config_data ["device_token" ] = api .device_token
@@ -216,28 +205,21 @@ def _host_already_configured(self, hostname):
216205
217206def _login_and_fetch_syno_info (api , otp_code ):
218207 """Login to the NAS and fetch basic data."""
219- if not api .login (otp_code ):
220- raise InvalidAuth
221-
222208 # These do i/o
223- information = api .information
209+ api .login ( otp_code )
224210 utilisation = api .utilisation
225211 storage = api .storage
226212
227213 if (
228- information .serial is None
214+ api . information .serial is None
229215 or utilisation .cpu_user_load is None
230216 or storage .disks_ids is None
231217 or storage .volumes_ids is None
232218 ):
233219 raise InvalidData
234220
235- return information .serial
221+ return api . information .serial
236222
237223
238224class InvalidData (exceptions .HomeAssistantError ):
239225 """Error to indicate we get invalid data from the nas."""
240-
241-
242- class InvalidAuth (exceptions .HomeAssistantError ):
243- """Error to indicate there is invalid auth."""
0 commit comments