Skip to content

Commit

Permalink
fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
msp1974 committed Dec 19, 2023
1 parent 3216736 commit 2a1eb25
Showing 1 changed file with 35 additions and 21 deletions.
56 changes: 35 additions & 21 deletions aioWiserHeatAPI/rest_controller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
"""Module to manage rest commands of Wiser hub"""
import asyncio
import enum
import json
Expand Down Expand Up @@ -25,6 +26,8 @@

@dataclass
class WiserAPIParams:
"""Class to hold default values"""

passive_mode_increment = 0.5
stored_manual_target_temperature_alt_source = "current"

Expand All @@ -42,6 +45,8 @@ def __init__(self):

# Enums
class WiserRestActionEnum(enum.Enum):
"""Enumeration of http methods"""

GET = "get"
POST = "post"
PATCH = "patch"
Expand Down Expand Up @@ -122,16 +127,19 @@ async def _do_hub_action(

except asyncio.TimeoutError as ex:
raise WiserHubConnectionError(
f"Connection timeout trying to communicate with Wiser Hub {self._wiser_connection_info.host} for url {url}"
)
f"Connection timeout trying to communicate with Wiser Hub "
f"{self._wiser_connection_info.host} for url {url}"
) from ex
except aiohttp.ClientResponseError as ex:
raise WiserHubConnectionError(
f"Response error trying to communicate with Wiser Hub {self._wiser_connection_info.host} for url {url}. Error is {ex}"
)
f"Response error trying to communicate with Wiser Hub "
f"{self._wiser_connection_info.host} for url {url}. Error is {ex}"
) from ex
except aiohttp.ClientConnectorError as ex:
raise WiserHubConnectionError(
f"Connection error trying to communicate with Wiser Hub {self._wiser_connection_info.host} for url {url}. Error is {ex}"
)
f"Connection error trying to communicate with Wiser Hub "
f"{self._wiser_connection_info.host} for url {url}. Error is {ex}"
) from ex

def _process_nok_response(
self,
Expand All @@ -142,19 +150,24 @@ def _process_nok_response(
):
if response.status == 401:
raise WiserHubAuthenticationError(
f"Error authenticating to Wiser Hub {self._wiser_connection_info.host}. Check your secret key"
f"Error authenticating to Wiser Hub "
f"{self._wiser_connection_info.host}. Check your secret key"
)
elif response.status == 404 and raise_for_endpoint_error:
raise WiserHubRESTError(
f"Rest endpoint not found on Wiser Hub {self._wiser_connection_info.host} for url {url}"
f"Rest endpoint not found on Wiser Hub "
f"{self._wiser_connection_info.host} for url {url}"
)
elif response.status == 408:
raise WiserHubConnectionError(
f"Connection timed out trying to communicate with Wiser Hub {self._wiser_connection_info.host} for url {url}"
f"Connection timed out trying to communicate with Wiser Hub "
f"{self._wiser_connection_info.host} for url {url}"
)
elif raise_for_endpoint_error:
raise WiserHubRESTError(
f"Unknown error communicating with Wiser Hub {self._wiser_connection_info.host} for url {url} with data {data}. Error code is: {response.status}"
f"Unknown error communicating with Wiser Hub "
f"{self._wiser_connection_info.host} for url {url} with data {data}. "
f"Error code is: {response.status}"
)

async def _get_hub_data(
Expand All @@ -176,9 +189,10 @@ async def _get_extra_config_data(self):
self._extra_config_file, self._hub_name.lower()
)
await self._extra_config.async_load_config()
except WiserExtraConfigError as ex:
except WiserExtraConfigError:
_LOGGER.error(
"Your config file is corrupted and needs to be fixed to maintain all the functionality of this integration."
"Your config file is corrupted and needs to be fixed "
"to maintain all the functionality of this integration."
)
self._extra_config = None

Expand All @@ -196,9 +210,7 @@ async def _send_command(
"""
url = WISERHUBDOMAIN + url
_LOGGER.debug(
"Sending command to url: {} with parameters {}".format(
url, command_data
)
"Sending command to url: %s with parameters %s", url, command_data
)

return await self._do_hub_action(method, url, command_data)
Expand All @@ -214,17 +226,19 @@ async def _do_schedule_action(
"""
url = WISERHUBSCHEDULES + url
_LOGGER.debug(
"Actioning schedule to url: {} with action {} and data {}".format(
url, action.value, schedule_data
)
"Actioning schedule to url: %s with action %s and data %s",
url,
action.value,
schedule_data,
)

return await self._do_hub_action(action, url, schedule_data)

async def _send_schedule_command(
self,
action: str,
schedule_data: dict,
id: int = 0,
schedule_id: int = 0,
schedule_type: str = None,
) -> bool:
"""
Expand All @@ -236,7 +250,7 @@ async def _send_schedule_command(
if action == "UPDATE":
result = await self._do_schedule_action(
WiserRestActionEnum.PATCH,
"{}/{}".format(schedule_type, id),
f"{schedule_type}/{schedule_id}",
schedule_data,
)

Expand All @@ -257,7 +271,7 @@ async def _send_schedule_command(
elif action == "DELETE":
result = await self._do_schedule_action(
WiserRestActionEnum.DELETE,
"{}/{}".format(schedule_type, id),
f"{schedule_type}/{schedule_id}",
schedule_data,
)
return result

0 comments on commit 2a1eb25

Please sign in to comment.