2020)
2121
2222from pyoverkiz .auth import Credentials , build_auth_strategy
23- from pyoverkiz .const import LOCAL_API_PATH , SUPPORTED_SERVERS
23+ from pyoverkiz .const import SUPPORTED_SERVERS
2424from pyoverkiz .enums import APIType , CommandMode , Server
2525from pyoverkiz .exceptions import (
2626 AccessDeniedToGatewayException ,
@@ -128,13 +128,12 @@ def _create_local_ssl_context() -> ssl.SSLContext:
128128class OverkizClient :
129129 """Interface class for the Overkiz API."""
130130
131- server : ServerConfig
131+ server_config : ServerConfig
132132 setup : Setup | None
133133 devices : list [Device ]
134134 gateways : list [Gateway ]
135135 event_listener_id : str | None
136136 session : ClientSession
137- api_type : APIType
138137 _ssl : ssl .SSLContext | bool = True
139138
140139 def __init__ (
@@ -151,7 +150,7 @@ def __init__(
151150 :param server: ServerConfig
152151 :param session: optional ClientSession
153152 """
154- self .server = self ._normalize_server (server )
153+ self .server_config = self ._normalize_server (server )
155154
156155 self .setup : Setup | None = None
157156 self .devices : list [Device ] = []
@@ -161,23 +160,22 @@ def __init__(
161160 self .session = session if session else ClientSession ()
162161 self ._ssl = verify_ssl
163162
164- if LOCAL_API_PATH in self .server .endpoint :
165- self .api_type = APIType .LOCAL
163+ if self .server_config .type == APIType .LOCAL and verify_ssl :
164+ # To avoid security issues while authentication to local API, we add the following authority to
165+ # our HTTPS client trust store: https://ca.overkiz.com/overkiz-root-ca-2048.crt
166+ self ._ssl = SSL_CONTEXT_LOCAL_API
166167
167- if verify_ssl :
168- # To avoid security issues while authentication to local API, we add the following authority to
169- # our HTTPS client trust store: https://ca.overkiz.com/overkiz-root-ca-2048.crt
170- self ._ssl = SSL_CONTEXT_LOCAL_API
171-
172- # Disable strict validation introduced in Python 3.13, which doesn't
173- # work with Overkiz self-signed gateway certificates
174- self ._ssl .verify_flags &= ~ ssl .VERIFY_X509_STRICT
175- else :
176- self .api_type = APIType .CLOUD
168+ # Disable strict validation introduced in Python 3.13, which doesn't
169+ # work with Overkiz self-signed gateway certificates
170+ self ._ssl .verify_flags &= ~ ssl .VERIFY_X509_STRICT
177171
178172 inferred_server_key = server_key or self ._resolve_server_key ()
179173 self ._auth = build_auth_strategy (
180- inferred_server_key , self .server , credentials , self .session , self ._ssl
174+ inferred_server_key ,
175+ self .server_config ,
176+ credentials ,
177+ self .session ,
178+ self ._ssl ,
181179 )
182180
183181 async def __aenter__ (self ) -> OverkizClient :
@@ -211,10 +209,13 @@ def _normalize_server(server: ServerConfig | Server | str) -> ServerConfig:
211209 def _resolve_server_key (self ) -> Server :
212210 """Infer a `Server` enum for the current server configuration."""
213211 for key , value in SUPPORTED_SERVERS .items ():
214- if self .server is value or self .server .endpoint == value .endpoint :
212+ if (
213+ self .server_config is value
214+ or self .server_config .endpoint == value .endpoint
215+ ):
215216 return Server (key )
216217
217- if self .api_type == APIType .LOCAL :
218+ if self .server_config . type == APIType .LOCAL :
218219 return Server (Server .SOMFY_DEVELOPER_MODE )
219220
220221 raise OverkizException (
@@ -603,7 +604,7 @@ async def __get(self, path: str) -> Any:
603604 headers = dict (self ._auth .auth_headers (path ))
604605
605606 async with self .session .get (
606- f"{ self .server .endpoint } { path } " ,
607+ f"{ self .server_config .endpoint } { path } " ,
607608 headers = headers ,
608609 ssl = self ._ssl ,
609610 ) as response :
@@ -618,7 +619,7 @@ async def __post(
618619 headers = dict (self ._auth .auth_headers (path ))
619620
620621 async with self .session .post (
621- f"{ self .server .endpoint } { path } " ,
622+ f"{ self .server_config .endpoint } { path } " ,
622623 data = data ,
623624 json = payload ,
624625 headers = headers ,
@@ -633,7 +634,7 @@ async def __delete(self, path: str) -> None:
633634 headers = dict (self ._auth .auth_headers (path ))
634635
635636 async with self .session .delete (
636- f"{ self .server .endpoint } { path } " ,
637+ f"{ self .server_config .endpoint } { path } " ,
637638 headers = headers ,
638639 ssl = self ._ssl ,
639640 ) as response :
0 commit comments