Skip to content

Commit

Permalink
Convert StrEnum and IntEnum in proxy (#1177)
Browse files Browse the repository at this point in the history
  • Loading branch information
SukramJ authored Aug 30, 2023
1 parent 637916a commit f246f7e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Version 2023.8.15 (2023-08-30)

- Reduce visibility of local constants
- Convert StrEnum and IntEnum in proxy

# Version 2023.8.13 (2023-08-28)

Expand Down
17 changes: 17 additions & 0 deletions hahomematic/xml_rpc_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import asyncio
from collections.abc import Callable
from concurrent.futures import ThreadPoolExecutor
from enum import IntEnum, StrEnum
import errno
import logging
from ssl import SSLError
Expand Down Expand Up @@ -85,6 +86,7 @@ async def __async_request(self, *args, **kwargs): # type: ignore[no-untyped-def
] in _VALID_XMLRPC_COMMANDS_ON_NO_CONNECTION or not self._connection_state.has_issue( # noqa: E501
issuer=self
):
args = _cleanup_args(*args)
_LOGGER.debug("__ASYNC_REQUEST: %s", args)
result = await self._async_add_proxy_executor_job(
# pylint: disable=protected-access
Expand Down Expand Up @@ -129,3 +131,18 @@ def stop(self) -> None:
"""Stop depending services."""
if self._proxy_executor:
self._proxy_executor.shutdown()


def _cleanup_args(*args: Any) -> Any:
"""Cleanup the type of args."""
if len(args[1]) == 0:
return args
new_args: list[Any] = []
for arg in args[1]:
if isinstance(arg, StrEnum):
new_args.append(str(arg))
elif isinstance(arg, IntEnum):
new_args.append(int(arg))
else:
new_args.append(arg)
return (args[0], tuple(new_args))

0 comments on commit f246f7e

Please sign in to comment.