Skip to content

Commit e369816

Browse files
committed
Fix missing session object
1 parent 170393b commit e369816

File tree

12 files changed

+62
-49
lines changed

12 files changed

+62
-49
lines changed

mypy.ini

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,22 @@ python_version = 3.8
33
show_error_codes = true
44
follow_imports = silent
55
ignore_missing_imports = true
6+
local_partial_types = true
67
strict_equality = true
8+
no_implicit_optional = true
79
warn_incomplete_stub = true
810
warn_redundant_casts = true
911
warn_unused_configs = true
1012
warn_unused_ignores = true
13+
enable_error_code = ignore-without-code, redundant-self, truthy-iterable
14+
disable_error_code = annotation-unchecked
15+
strict_concatenate = false
1116
check_untyped_defs = true
1217
disallow_incomplete_defs = true
1318
disallow_subclassing_any = true
1419
disallow_untyped_calls = true
15-
#disallow_untyped_decorators = true
20+
disallow_untyped_decorators = true
1621
disallow_untyped_defs = true
17-
no_implicit_optional = true
1822
warn_return_any = true
1923
warn_unreachable = true
2024

pyoverkiz/client.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,11 @@ async def refresh_listener(invocation: Mapping[str, Any]) -> None:
4444
await invocation["args"][0].register_event_listener()
4545

4646

47-
# pylint: disable=too-many-instance-attributes, too-many-branches
48-
49-
5047
class OverkizClient:
5148
"""Interface class for the Overkiz API"""
5249

50+
# pylint: disable=too-many-instance-attributes
51+
5352
username: str
5453
password: str
5554
server: OverkizServer
@@ -69,7 +68,6 @@ def __init__(
6968
password: str,
7069
server: OverkizServer,
7170
token: str | None = None,
72-
session: ClientSession | None = None,
7371
) -> None:
7472
"""
7573
Constructor
@@ -90,8 +88,6 @@ def __init__(
9088
self.gateways: list[Gateway] = []
9189
self.event_listener_id: str | None = None
9290

93-
self.session = session if session else ClientSession()
94-
9591
async def __aenter__(self) -> OverkizClient:
9692
return self
9793

@@ -108,7 +104,7 @@ async def close(self) -> None:
108104
if self.event_listener_id:
109105
await self.unregister_event_listener()
110106

111-
await self.session.close()
107+
await self.server.session.close()
112108

113109
async def login(
114110
self,

pyoverkiz/const.py

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,112 @@
11
from __future__ import annotations
22

3+
from typing import Callable
4+
5+
from aiohttp import ClientSession
6+
37
from pyoverkiz.servers.atlantic_cozytouch import AtlanticCozytouch
48
from pyoverkiz.servers.default import DefaultServer
59
from pyoverkiz.servers.nexity import NexityServer
610
from pyoverkiz.servers.overkiz_server import OverkizServer
711
from pyoverkiz.servers.somfy import SomfyServer
812

9-
SUPPORTED_SERVERS: dict[str, OverkizServer] = {
10-
"atlantic_cozytouch": AtlanticCozytouch(
13+
SUPPORTED_SERVERS: dict[str, Callable[[ClientSession], OverkizServer]] = {
14+
"atlantic_cozytouch": lambda session: AtlanticCozytouch(
1115
name="Atlantic Cozytouch",
1216
endpoint="https://ha110-1.overkiz.com/enduser-mobile-web/enduserAPI/",
1317
manufacturer="Atlantic",
1418
configuration_url=None,
19+
session=session,
1520
),
16-
"brandt": DefaultServer(
21+
"brandt": lambda session: DefaultServer(
1722
name="Brandt Smart Control",
1823
endpoint="https://ha3-1.overkiz.com/enduser-mobile-web/enduserAPI/",
1924
manufacturer="Brandt",
2025
configuration_url=None,
26+
session=session,
2127
),
22-
"flexom": DefaultServer(
28+
"flexom": lambda session: DefaultServer(
2329
name="Flexom",
2430
endpoint="https://ha108-1.overkiz.com/enduser-mobile-web/enduserAPI/",
2531
manufacturer="Bouygues",
2632
configuration_url=None,
33+
session=session,
2734
),
28-
"hexaom_hexaconnect": DefaultServer(
35+
"hexaom_hexaconnect": lambda session: DefaultServer(
2936
name="Hexaom HexaConnect",
3037
endpoint="https://ha5-1.overkiz.com/enduser-mobile-web/enduserAPI/",
3138
manufacturer="Hexaom",
3239
configuration_url=None,
40+
session=session,
3341
),
34-
"hi_kumo_asia": DefaultServer(
42+
"hi_kumo_asia": lambda session: DefaultServer(
3543
name="Hitachi Hi Kumo (Asia)",
3644
endpoint="https://ha203-1.overkiz.com/enduser-mobile-web/enduserAPI/",
3745
manufacturer="Hitachi",
3846
configuration_url=None,
47+
session=session,
3948
),
40-
"hi_kumo_europe": DefaultServer(
49+
"hi_kumo_europe": lambda session: DefaultServer(
4150
name="Hitachi Hi Kumo (Europe)",
4251
endpoint="https://ha117-1.overkiz.com/enduser-mobile-web/enduserAPI/",
4352
manufacturer="Hitachi",
4453
configuration_url=None,
54+
session=session,
4555
),
46-
"hi_kumo_oceania": DefaultServer(
56+
"hi_kumo_oceania": lambda session: DefaultServer(
4757
name="Hitachi Hi Kumo (Oceania)",
4858
endpoint="https://ha203-1.overkiz.com/enduser-mobile-web/enduserAPI/",
4959
manufacturer="Hitachi",
5060
configuration_url=None,
61+
session=session,
5162
),
52-
"nexity": NexityServer(
63+
"nexity": lambda session: NexityServer(
5364
name="Nexity Eugénie",
5465
endpoint="https://ha106-1.overkiz.com/enduser-mobile-web/enduserAPI/",
5566
manufacturer="Nexity",
5667
configuration_url=None,
68+
session=session,
5769
),
58-
"rexel": DefaultServer(
70+
"rexel": lambda session: DefaultServer(
5971
name="Rexel Energeasy Connect",
6072
endpoint="https://ha112-1.overkiz.com/enduser-mobile-web/enduserAPI/",
6173
manufacturer="Rexel",
6274
configuration_url="https://utilisateur.energeasyconnect.com/user/#/zone/equipements",
75+
session=session,
6376
),
64-
"simu_livein2": DefaultServer( # alias of https://tahomalink.com
77+
"simu_livein2": lambda session: DefaultServer( # alias of https://tahomalink.com
6578
name="SIMU (LiveIn2)",
6679
endpoint="https://ha101-1.overkiz.com/enduser-mobile-web/enduserAPI/",
6780
manufacturer="Somfy",
6881
configuration_url=None,
82+
session=session,
6983
),
70-
"somfy_europe": SomfyServer( # alias of https://tahomalink.com
84+
"somfy_europe": lambda session: SomfyServer( # alias of https://tahomalink.com
7185
name="Somfy (Europe)",
7286
endpoint="https://ha101-1.overkiz.com/enduser-mobile-web/enduserAPI/",
7387
manufacturer="Somfy",
7488
configuration_url="https://www.tahomalink.com",
89+
session=session,
7590
),
76-
"somfy_america": DefaultServer(
91+
"somfy_america": lambda session: DefaultServer(
7792
name="Somfy (North America)",
7893
endpoint="https://ha401-1.overkiz.com/enduser-mobile-web/enduserAPI/",
7994
manufacturer="Somfy",
8095
configuration_url=None,
96+
session=session,
8197
),
82-
"somfy_oceania": DefaultServer(
98+
"somfy_oceania": lambda session: DefaultServer(
8399
name="Somfy (Oceania)",
84100
endpoint="https://ha201-1.overkiz.com/enduser-mobile-web/enduserAPI/",
85101
manufacturer="Somfy",
86102
configuration_url=None,
103+
session=session,
87104
),
88-
"ubiwizz": DefaultServer(
105+
"ubiwizz": lambda session: DefaultServer(
89106
name="Ubiwizz",
90107
endpoint="https://ha129-1.overkiz.com/enduser-mobile-web/enduserAPI/",
91108
manufacturer="Decelect",
92109
configuration_url=None,
110+
session=session,
93111
),
94112
}

pyoverkiz/enums/execution.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ExecutionType(str, Enum):
1515
RAW_TRIGGER_GATEWAY = "Raw trigger (Gateway)"
1616

1717
@classmethod
18-
def _missing_(cls, value): # type: ignore
18+
def _missing_(cls, value): # type: ignore[no-untyped-def]
1919
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
2020
return cls.UNKNOWN
2121

@@ -33,7 +33,7 @@ class ExecutionState(str, Enum):
3333
QUEUED_SERVER_SIDE = "QUEUED_SERVER_SIDE"
3434

3535
@classmethod
36-
def _missing_(cls, value): # type: ignore
36+
def _missing_(cls, value): # type: ignore[no-untyped-def]
3737
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
3838
return cls.UNKNOWN
3939

@@ -56,6 +56,6 @@ class ExecutionSubType(str, Enum):
5656
TIME_TRIGGER = "TIME_TRIGGER"
5757

5858
@classmethod
59-
def _missing_(cls, value): # type: ignore
59+
def _missing_(cls, value): # type: ignore[no-untyped-def]
6060
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
6161
return cls.UNKNOWN

pyoverkiz/enums/gateway.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class GatewayType(IntEnum):
5151
TAHOMA_RAIL_DIN_S = 108
5252

5353
@classmethod
54-
def _missing_(cls, value): # type: ignore
54+
def _missing_(cls, value): # type: ignore[no-untyped-def]
5555
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
5656
return cls.UNKNOWN
5757

@@ -85,7 +85,7 @@ class GatewaySubType(IntEnum):
8585
# TAHOMA_BOX_C_IO = 12 That’s probably 17, but tahomalink.com says it’s 12
8686

8787
@classmethod
88-
def _missing_(cls, value): # type: ignore
88+
def _missing_(cls, value): # type: ignore[no-untyped-def]
8989
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
9090
return cls.UNKNOWN
9191

pyoverkiz/enums/general.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ class FailureType(IntEnum):
234234
TIME_OUT_ON_COMMAND_PROGRESS = 20003
235235

236236
@classmethod
237-
def _missing_(cls, value): # type: ignore
237+
def _missing_(cls, value): # type: ignore[no-untyped-def]
238238
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
239239
return cls.UNKNOWN
240240

@@ -416,6 +416,6 @@ class EventName(str, Enum):
416416
ZONE_UPDATED = "ZoneUpdatedEvent"
417417

418418
@classmethod
419-
def _missing_(cls, value): # type: ignore
419+
def _missing_(cls, value): # type: ignore[no-untyped-def]
420420
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
421421
return cls.UNKNOWN

pyoverkiz/enums/protocol.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ class Protocol(str, Enum):
4242
RTN = "rtn"
4343

4444
@classmethod
45-
def _missing_(cls, value): # type: ignore
45+
def _missing_(cls, value): # type: ignore[no-untyped-def]
4646
_LOGGER.warning(f"Unsupported protocol {value} has been returned for {cls}")
4747
return cls.UNKNOWN

pyoverkiz/enums/ui.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class UIClass(str, Enum):
7676
UNKNOWN = "unknown"
7777

7878
@classmethod
79-
def _missing_(cls, value): # type: ignore
79+
def _missing_(cls, value): # type: ignore[no-untyped-def]
8080
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
8181
return cls.UNKNOWN
8282

@@ -408,6 +408,6 @@ class UIWidget(str, Enum):
408408
UNKNOWN = "unknown"
409409

410410
@classmethod
411-
def _missing_(cls, value): # type: ignore
411+
def _missing_(cls, value): # type: ignore[no-untyped-def]
412412
_LOGGER.warning(f"Unsupported value {value} has been returned for {cls}")
413413
return cls.UNKNOWN

pyoverkiz/servers/atlantic_cozytouch.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ async def login(self, username: str, password: str) -> bool:
5959

6060
payload = {"jwt": jwt}
6161

62-
response = await self.post("login", data=payload)
62+
post_response = await self.post("login", data=payload)
6363

64-
if response.get("success"):
65-
return True
66-
67-
return False
64+
return "success" in post_response

pyoverkiz/servers/nexity.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,10 @@ def _get_client() -> boto3.session.Session.client:
4646
except Exception as error:
4747
raise NexityBadCredentialsException() from error
4848

49-
id_token = tokens["AuthenticationResult"]["IdToken"]
50-
5149
async with self.session.get(
5250
NEXITY_API + "/deploy/api/v1/domotic/token",
5351
headers={
54-
"Authorization": id_token,
52+
"Authorization": tokens["AuthenticationResult"]["IdToken"],
5553
},
5654
) as response:
5755
token = await response.json()
@@ -64,9 +62,6 @@ def _get_client() -> boto3.session.Session.client:
6462
user_id = username.replace("@", "_-_") # Replace @ for _-_
6563
payload = {"ssoToken": sso_token, "userId": user_id}
6664

67-
response = await self.server.post("login", data=payload)
68-
69-
if response.get("success"):
70-
return True
65+
post_response = await self.post("login", data=payload)
7166

72-
return False
67+
return "success" in post_response

pyoverkiz/servers/overkiz_server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ async def login(self, username: str, password: str) -> bool:
4545
"""Login to the server."""
4646

4747
@property
48-
def _headers(self):
48+
def _headers(self) -> dict[str, str]:
4949
return {}
5050

5151
async def get(self, path: str) -> Any:
@@ -84,6 +84,9 @@ async def delete(self, path: str) -> None:
8484
@staticmethod
8585
async def check_response(response: ClientResponse) -> None:
8686
"""Check the response returned by the OverKiz API"""
87+
88+
# pylint: disable=too-many-branches
89+
8790
if response.status in [200, 204]:
8891
return
8992

pyoverkiz/servers/somfy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class SomfyServer(OverkizServer):
2121
_expires_in: datetime.datetime | None = None
2222

2323
@property
24-
def _headers(self):
24+
def _headers(self) -> dict[str, str]:
2525
return {"Authorization": f"Bearer {self._access_token}"}
2626

2727
async def get(self, path: str) -> Any:

0 commit comments

Comments
 (0)