Skip to content

Commit 3a2f0f0

Browse files
committed
fixed incongruity with bools between websocket and rest apis
1 parent 17e90d1 commit 3a2f0f0

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

appdaemon/utils.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@
3333
from pytz import BaseTzInfo
3434

3535
from appdaemon.parse import parse_datetime
36-
from appdaemon.version import __version__ # noqa: F401
37-
from appdaemon.version import __version_comments__ # noqa: F401
36+
from appdaemon.version import (
37+
__version__, # noqa: F401
38+
__version_comments__, # noqa: F401
39+
)
3840

3941
from . import exceptions as ade
4042
from .parse import parse_timedelta
@@ -1082,12 +1084,14 @@ def clean_kwargs(**kwargs: Any) -> Generator[tuple[str, Any]]:
10821084
- Mapping values (like dicts) are converted to dicts of cleaned key-value pairs
10831085
"""
10841086

1085-
def _clean_value(val: bool | datetime | Any) -> str:
1087+
def _clean_value(val: bool | datetime | Any) -> str | int | float | bool:
10861088
match val:
1089+
case bool():
1090+
return val
1091+
case str() | int() | float() | bool():
1092+
return val
10871093
case datetime():
10881094
return val.isoformat()
1089-
case bool():
1090-
return str(val).lower()
10911095
case _:
10921096
return str(val)
10931097

@@ -1097,7 +1101,7 @@ def _clean_value(val: bool | datetime | Any) -> str:
10971101
continue
10981102
case str():
10991103
# This case needs to be before the Iterable case because strings are iterable
1100-
yield key, _clean_value(val)
1104+
yield key, val
11011105
case Mapping():
11021106
# This case needs to be before the Iterable case because Mappings like dicts are iterable
11031107
yield key, dict(clean_kwargs(**val))
@@ -1111,9 +1115,13 @@ def clean_http_kwargs(**kwargs: Any) -> Generator[tuple[str, Any]]:
11111115
"""Recursively cleans the kwarg dict to prepare it for use in HTTP requests."""
11121116
for key, val in clean_kwargs(**kwargs):
11131117
match val:
1114-
case "false" | None:
1115-
# Filter out values that are False or None
1118+
case None:
1119+
continue # filter None values
1120+
case False | "false":
1121+
# Filter out values that are False
11161122
continue
1123+
case True:
1124+
yield key, "true"
11171125
case _:
11181126
yield key, val
11191127

0 commit comments

Comments
 (0)