Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ariston/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ def __init__(self) -> None:
self.api = None
self.cloud_devices: list[dict[str, Any]] = []

async def async_connect(self, username: str, password: str, api_url: str = ARISTON_API_URL) -> bool:
async def async_connect(
self, username: str, password: str, api_url: str = ARISTON_API_URL
) -> bool:
"""Connect to the ariston cloud"""
self.api = AristonAPI(username, password, api_url)
return await self.api.async_connect()
Expand Down
54 changes: 28 additions & 26 deletions ariston/ariston_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,19 +435,20 @@ def __request(
method, path, params=params, json=body, headers=headers, timeout=30000
)
if not response.ok:
if response.status_code == 405:
if not is_retry:
if self.connect():
match response.status_code:
case 405:
if not is_retry:
if self.connect():
return self.__request(method, path, params, body, True)
raise Exception("Login failed (password changed?)")
raise Exception("Invalid token")
case 404:
return None
case _:
if not is_retry:
time.sleep(5)
return self.__request(method, path, params, body, True)
raise Exception("Login failed (password changed?)")
raise Exception("Invalid token")
if response.status_code == 404:
return None
if response.status_code == 500:
if not is_retry:
time.sleep(1)
return self.__request(method, path, params, body, True)
raise Exception(response.status_code)
raise Exception(response.status_code)

if len(response.content) > 0:
json = response.json()
Expand Down Expand Up @@ -849,23 +850,24 @@ async def __async_request(
)

if not response.ok:
if response.status == 405:
if not is_retry:
if await self.async_connect():
match response.status:
case 405:
if not is_retry:
if await self.async_connect():
return await self.__async_request(
method, path, params, body, True
)
raise Exception("Login failed (password changed?)")
raise Exception("Invalid token")
case 404:
return None
case _:
if not is_retry:
await asyncio.sleep(5)
return await self.__async_request(
method, path, params, body, True
)
raise Exception("Login failed (password changed?)")
raise Exception("Invalid token")
if response.status == 404:
return None
if response.status == 500:
if not is_retry:
await asyncio.sleep(1)
return await self.__async_request(
method, path, params, body, True
)
raise Exception(response.status)
raise Exception(response.status)

if response.content_length and response.content_length > 0:
json = await response.json()
Expand Down
2 changes: 1 addition & 1 deletion ariston/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def _set_energy_features(self):

def are_device_features_available(
self,
device_features: Optional[list[DeviceFeatures or CustomDeviceFeatures or DeviceAttribute]],
device_features: Optional[list[DeviceFeatures | CustomDeviceFeatures | DeviceAttribute]],
system_types: Optional[list[SystemType]],
whe_types: Optional[list[WheType]],
) -> bool:
Expand Down