Skip to content

Commit 5c57e7d

Browse files
committed
Add local support for Somfy Europe
1 parent d2a1fee commit 5c57e7d

File tree

4 files changed

+79
-10
lines changed

4 files changed

+79
-10
lines changed

pyoverkiz/clients/overkiz.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,25 @@ async def login(self, register_event_listener: bool = True) -> bool:
9696
def _headers(self) -> dict[str, str]:
9797
return {}
9898

99-
async def get(self, path: str) -> Any:
99+
async def get(
100+
self,
101+
path: str,
102+
ssl: bool = True,
103+
) -> Any:
100104
"""Make a GET request to the OverKiz API"""
101105

102106
async with self.session.get(
103-
f"{self.endpoint}{path}",
104-
headers=self._headers,
107+
f"{self.endpoint}{path}", headers=self._headers, ssl=ssl
105108
) as response:
106109
await self.check_response(response)
107110
return await response.json()
108111

109112
async def post(
110-
self, path: str, payload: JSON | None = None, data: JSON | None = None
113+
self,
114+
path: str,
115+
payload: JSON | None = None,
116+
data: JSON | None = None,
117+
ssl: bool = True,
111118
) -> Any:
112119
"""Make a POST request to the OverKiz API"""
113120

@@ -116,16 +123,20 @@ async def post(
116123
data=data,
117124
json=payload,
118125
headers=self._headers,
126+
ssl=ssl,
119127
) as response:
120128
await self.check_response(response)
121129
return await response.json()
122130

123-
async def delete(self, path: str) -> None:
131+
async def delete(
132+
self,
133+
path: str,
134+
ssl: bool = True,
135+
) -> None:
124136
"""Make a DELETE request to the OverKiz API"""
125137

126138
async with self.session.delete(
127-
f"{self.endpoint}{path}",
128-
headers=self._headers,
139+
f"{self.endpoint}{path}", headers=self._headers, ssl=ssl
129140
) as response:
130141
await self.check_response(response)
131142

@@ -459,6 +470,7 @@ async def generate_local_token(self, gateway_id: str) -> str:
459470
Access scope : Full enduser API access (enduser/*)
460471
"""
461472
response = await self.get(f"config/{gateway_id}/local/tokens/generate")
473+
print(response)
462474

463475
return cast(str, response["token"])
464476

pyoverkiz/clients/somfy.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,25 @@ class SomfyClient(OverkizClient):
2424
def _headers(self) -> dict[str, str]:
2525
return {"Authorization": f"Bearer {self._access_token}"}
2626

27-
async def get(self, path: str) -> Any:
27+
async def get(self, path: str, ssl: bool = True) -> Any:
2828
"""Make a GET request to the OverKiz API"""
2929

3030
await self._refresh_token_if_expired()
3131
return await super().get(path)
3232

3333
async def post(
34-
self, path: str, payload: JSON | None = None, data: JSON | None = None
34+
self,
35+
path: str,
36+
payload: JSON | None = None,
37+
data: JSON | None = None,
38+
ssl: bool = True,
3539
) -> Any:
3640
"""Make a POST request to the OverKiz API"""
3741
if path != "login":
3842
await self._refresh_token_if_expired()
3943
return await super().post(path, payload=payload, data=data)
4044

41-
async def delete(self, path: str) -> None:
45+
async def delete(self, path: str, ssl: bool = True) -> None:
4246
"""Make a DELETE request to the OverKiz API"""
4347
await self._refresh_token_if_expired()
4448
return await super().delete(path)

pyoverkiz/clients/somfy_local.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from __future__ import annotations
2+
3+
from typing import Any
4+
5+
from pyoverkiz.clients.overkiz import OverkizClient
6+
from pyoverkiz.types import JSON
7+
8+
9+
class SomfyLocalClient(OverkizClient):
10+
async def _login(self, username: str, password: str) -> bool:
11+
"""There is no login for Somfy Local"""
12+
return True
13+
14+
@property
15+
def _headers(self) -> dict[str, str]:
16+
return {"Authorization": f"Bearer {self.password}"}
17+
18+
async def get(
19+
self,
20+
path: str,
21+
_ssl: bool = False,
22+
) -> Any:
23+
"""Make a GET request to the OverKiz API"""
24+
25+
return await super().get(path, ssl=False)
26+
27+
async def post(
28+
self,
29+
path: str,
30+
payload: JSON | None = None,
31+
data: JSON | None = None,
32+
_ssl: bool = False,
33+
) -> Any:
34+
"""Make a POST request to the OverKiz API"""
35+
return await super().post(path, payload=payload, data=data, ssl=False)
36+
37+
async def delete(
38+
self,
39+
path: str,
40+
_ssl: bool = False,
41+
) -> None:
42+
"""Make a DELETE request to the OverKiz API"""
43+
return await super().delete(path, ssl=False)

pyoverkiz/const.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from pyoverkiz.clients.nexity import NexityClient
1010
from pyoverkiz.clients.overkiz import OverkizClient
1111
from pyoverkiz.clients.somfy import SomfyClient
12+
from pyoverkiz.clients.somfy_local import SomfyLocalClient
1213

1314
SUPPORTED_SERVERS: dict[str, Callable[[str, str, ClientSession], OverkizClient]] = {
1415
"atlantic_cozytouch": lambda username, password, session: AtlanticCozytouchClient(
@@ -110,6 +111,15 @@
110111
username=username,
111112
password=password,
112113
),
114+
"somfy_europe_local": lambda gateway_id, token, session: SomfyLocalClient(
115+
name="Somfy Local(Europe)",
116+
endpoint=f"https://gateway-{gateway_id}.local:8443/enduser-mobile-web/1/enduserAPI/",
117+
manufacturer="Somfy",
118+
configuration_url=None,
119+
session=session,
120+
username=gateway_id, # not used
121+
password=token,
122+
),
113123
"somfy_america": lambda username, password, session: DefaultClient(
114124
name="Somfy (North America)",
115125
endpoint="https://ha401-1.overkiz.com/enduser-mobile-web/enduserAPI/",

0 commit comments

Comments
 (0)