Skip to content

Commit 563a092

Browse files
committed
Fix cli async calls
1 parent e4a1c84 commit 563a092

File tree

3 files changed

+8
-14
lines changed

3 files changed

+8
-14
lines changed

karcher/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async def login(ctx: click.Context, username: str, password: str):
114114

115115
kh = await KarcherHome.create(country=ctx.obj.country)
116116

117-
ctx.obj.print(kh.login(username, password))
117+
ctx.obj.print(await kh.login(username, password))
118118

119119
await kh.close()
120120

karcher/karcher.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# SPDX-License-Identifier: MIT
44
# -----------------------------------------------------------
55

6-
import asyncio
76
import collections
87
import json
98
import threading
@@ -73,11 +72,6 @@ def __init__(self):
7372
self._http = None
7473
self._http_external = False
7574

76-
def __del__(self):
77-
"""Destructor"""
78-
79-
asyncio.run(self.close())
80-
8175
async def close(self):
8276
"""Close underlying connections"""
8377

@@ -114,22 +108,22 @@ async def _request(self, method: str, url: str, **kwargs) -> aiohttp.ClientRespo
114108
data = ''
115109
if method == 'GET':
116110
params = kwargs.get('params') or {}
117-
if type(params) == str:
111+
if isinstance(params, str):
118112
params = urllib.parse.parse_qs(params)
119113
buf = urllib.parse.urlencode(params)
120114
data = buf
121115
kwargs['params'] = buf
122116
elif method == 'POST' or method == 'PUT':
123117
v = params = kwargs.get('json') or {}
124-
if type(v) == dict:
118+
if isinstance(v, dict):
125119
v = collections.OrderedDict(v.items())
126120
for key, val in v.items():
127121
data += key
128122
if val is None:
129123
data += 'null'
130-
elif type(val) == str:
124+
elif isinstance(val, str):
131125
data += val
132-
elif type(val) == dict:
126+
elif isinstance(val, dict):
133127
data += json.dumps(val, separators=(',', ':'))
134128
else:
135129
data += str(val)
@@ -174,7 +168,7 @@ async def _process_response(self, resp: aiohttp.ClientResponse, prop=None) -> An
174168
return None
175169
# Handle special response types
176170
result = data['result']
177-
if type(result) == str:
171+
if isinstance(result, str):
178172
raise KarcherHomeException(-2, 'Invalid response: ' + result)
179173
if prop is not None:
180174
return json.loads(decrypt(result[prop]))

karcher/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,12 @@ def snake_case(value: str) -> str:
102102

103103

104104
def snake_case_fields(data: str) -> str:
105-
if type(data) is dict:
105+
if isinstance(data, dict):
106106
n = {}
107107
for k, v in data.items():
108108
n[snake_case(k)] = snake_case_fields(v)
109109
return n
110-
elif type(data) is list:
110+
elif isinstance(data, list):
111111
n = []
112112
for v in data:
113113
n.append(snake_case_fields(v))

0 commit comments

Comments
 (0)