Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8
Clean up timeout-related, pass _request-function as an argument#637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
2014a729f321d62752d4b454cfe23701bcb9ba772bb98f66d9f2e81edf1aa98d893a1bFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -4,6 +4,7 @@ | ||||||||||||||||||
| """ | ||||||||||||||||||
| from __future__ import annotations | ||||||||||||||||||
| from collections.abc import Awaitable, Callable | ||||||||||||||||||
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Use To maintain compatibility with Python versions earlier than 3.9 and for consistency with other type hints in the code, consider importing Apply this diff to modify the import statements: -from collections.abc import Awaitable, Callable+from typing import Any, Awaitable, Callable
| ||||||||||||||||||
| import datetime as dt | ||||||||||||||||||
| from typing import Any | ||||||||||||||||||
| @@ -28,7 +29,6 @@ | ||||||||||||||||||
| ) | ||||||||||||||||||
| from plugwise.data import SmileData | ||||||||||||||||||
| from plugwise.exceptions import ConnectionFailedError, DataMissingError, PlugwiseError | ||||||||||||||||||
| from plugwise.helper import SmileComm | ||||||||||||||||||
| import aiohttp | ||||||||||||||||||
| from defusedxml import ElementTree as etree | ||||||||||||||||||
| @@ -37,7 +37,7 @@ | ||||||||||||||||||
| from munch import Munch | ||||||||||||||||||
| class SmileAPI(SmileComm, SmileData): | ||||||||||||||||||
| class SmileAPI(SmileData): | ||||||||||||||||||
| """The Plugwise SmileAPI helper class for actual Plugwise devices.""" | ||||||||||||||||||
| # pylint: disable=too-many-instance-attributes, too-many-public-methods | ||||||||||||||||||
| @@ -46,7 +46,7 @@ def __init__( | ||||||||||||||||||
| self, | ||||||||||||||||||
| host: str, | ||||||||||||||||||
| password: str, | ||||||||||||||||||
| timeout: int, | ||||||||||||||||||
| request: Callable[..., Awaitable[Any]], | ||||||||||||||||||
| websession: aiohttp.ClientSession, | ||||||||||||||||||
| _cooling_present: bool, | ||||||||||||||||||
| _elga: bool, | ||||||||||||||||||
| @@ -69,14 +69,6 @@ def __init__( | ||||||||||||||||||
| username: str = DEFAULT_USERNAME, | ||||||||||||||||||
| ) -> None: | ||||||||||||||||||
| """Set the constructor for this class.""" | ||||||||||||||||||
| super().__init__( | ||||||||||||||||||
| host, | ||||||||||||||||||
| password, | ||||||||||||||||||
| port, | ||||||||||||||||||
| timeout, | ||||||||||||||||||
| username, | ||||||||||||||||||
| websession, | ||||||||||||||||||
| ) | ||||||||||||||||||
| SmileData.__init__(self) | ||||||||||||||||||
| self._cooling_present = _cooling_present | ||||||||||||||||||
| @@ -86,9 +78,9 @@ def __init__( | ||||||||||||||||||
| self._on_off_device = _on_off_device | ||||||||||||||||||
| self._opentherm_device = _opentherm_device | ||||||||||||||||||
| self._schedule_old_states = _schedule_old_states | ||||||||||||||||||
| self._timeout = timeout | ||||||||||||||||||
| self.gateway_id = gateway_id | ||||||||||||||||||
| self.loc_data = loc_data | ||||||||||||||||||
| self.request = request | ||||||||||||||||||
| self.smile_fw_version = smile_fw_version | ||||||||||||||||||
| self.smile_hostname = smile_hostname | ||||||||||||||||||
| self.smile_hw_version = smile_hw_version | ||||||||||||||||||
| @@ -103,7 +95,7 @@ def __init__( | ||||||||||||||||||
| async def full_update_device(self) -> None: | ||||||||||||||||||
| """Perform a first fetch of all XML data, needed for initialization.""" | ||||||||||||||||||
| self._domain_objects = await self._request(DOMAIN_OBJECTS) | ||||||||||||||||||
| self._domain_objects = await self.request(DOMAIN_OBJECTS) | ||||||||||||||||||
| self._get_plugwise_notifications() | ||||||||||||||||||
| def get_all_devices(self) -> None: | ||||||||||||||||||
| @@ -461,10 +453,10 @@ async def set_temperature(self, loc_id: str, items: dict[str, float]) -> None: | ||||||||||||||||||
| await self.call_request(uri, method="put", data=data) | ||||||||||||||||||
| async def call_request(self, uri: str, **kwargs: Any) -> None: | ||||||||||||||||||
| """ConnectionFailedError wrapper for calling _request().""" | ||||||||||||||||||
| """ConnectionFailedError wrapper for calling request().""" | ||||||||||||||||||
| method: str = kwargs["method"] | ||||||||||||||||||
| data: str | None = kwargs.get("data") | ||||||||||||||||||
Comment on lines
+456
to
458
Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prevent Accessing Apply this diff to handle the missing async def call_request(self, uri: str, **kwargs: Any) -> None:
"""ConnectionFailedError wrapper for calling request()."""
- method: str = kwargs["method"]+ method: str | None = kwargs.get("method")+ if method is None:+ raise ValueError("The 'method' argument is required.")
data: str | None = kwargs.get("data")
try:
await self.request(uri, method=method, data=data)📝 Committable suggestion
Suggested change
| ||||||||||||||||||
| try: | ||||||||||||||||||
| await self._request(uri, method=method, data=data) | ||||||||||||||||||
| await self.request(uri, method=method, data=data) | ||||||||||||||||||
| except ConnectionFailedError as exc: | ||||||||||||||||||
| raise ConnectionFailedError from exc | ||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.