Skip to content

Commit 335b783

Browse files
committed
fix linter issues
1 parent 6b2e634 commit 335b783

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

openhab/client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def req_post(self,
184184
def req_put(self,
185185
uri_path: str,
186186
data: typing.Optional[dict] = None,
187-
json: typing.Optional[dict] = None,
187+
json_data: typing.Optional[dict] = None,
188188
headers: typing.Optional[dict] = None
189189
) -> None:
190190
"""Helper method for initiating a HTTP PUT request.
@@ -195,7 +195,7 @@ def req_put(self,
195195
Args:
196196
uri_path (str): The path to be used in the PUT request.
197197
data (dict, optional): A optional dict with data to be submitted as part of the PUT request.
198-
json: Data to be submitted as json.
198+
json_data: Data to be submitted as json.
199199
headers: Specify optional custom headers.
200200
201201
Returns:
@@ -204,7 +204,7 @@ def req_put(self,
204204
if headers is None:
205205
headers = {'Content-Type': 'text/plain'}
206206

207-
r = self.session.put(self.url_rest + uri_path, data=data, json=json, headers=headers, timeout=self.timeout)
207+
r = self.session.put(self.url_rest + uri_path, data=data, json=json_data, headers=headers, timeout=self.timeout)
208208
self._check_req_return(r)
209209

210210
# fetch all items
@@ -300,7 +300,7 @@ def get_item_raw(self, name: str) -> typing.Any:
300300
Returns:
301301
dict: A JSON decoded dict.
302302
"""
303-
return self.req_get('/items/{}'.format(name))
303+
return self.req_get(f'/items/{name}')
304304

305305
def logout(self) -> bool:
306306
"""OAuth2 session logout method.
@@ -378,7 +378,7 @@ def create_or_update_item(self,
378378
Can be one of ['EQUALITY', 'AND', 'OR', 'NAND', 'NOR', 'AVG', 'SUM', 'MAX', 'MIN', 'COUNT', 'LATEST', 'EARLIEST']
379379
function_params: Optional list of function params (no documentation found), depending on function name.
380380
"""
381-
paramdict: typing.Dict[str, typing.Union[str, typing.List[str], typing.Dict[str, typing.Union[str, typing.List]]]] = {}
381+
paramdict: typing.Dict[str, typing.Union[str, typing.List[str], typing.Dict[str, typing.Union[str, typing.List[str]]]]] = {}
382382

383383
if isinstance(_type, type):
384384
if issubclass(_type, openhab.items.Item):
@@ -427,14 +427,14 @@ def create_or_update_item(self,
427427
if function_name == 'COUNT' and (not function_params or len(function_params) != 1):
428428
raise ValueError(f'Group function "{function_name}" requires one arguments')
429429

430-
paramdict['function'] = {'name': function_name}
431-
432430
if function_params:
433-
paramdict['function']['params'] = function_params
431+
paramdict['function'] = {'name': function_name, 'params': function_params}
432+
else:
433+
paramdict['function'] = {'name': function_name}
434434

435435
self.logger.debug('About to create item with PUT request:\n%s', str(paramdict))
436436

437-
self.req_put(f'/items/{name}', json=paramdict, headers={'Content-Type': 'application/json'})
437+
self.req_put(f'/items/{name}', json_data=paramdict, headers={'Content-Type': 'application/json'})
438438

439439

440440
# noinspection PyPep8Naming

openhab/command_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def validate(cls, value: typing.Union[str, typing.Tuple[int, int, float]]) -> No
253253
strvalue = str(value)
254254
if isinstance(value, tuple):
255255
if len(value) == 3:
256-
strvalue = "{},{},{}".format(value[0], value[1], value[2])
256+
strvalue = f'{value[0]},{value[1]},{value[2]}'
257257
super().validate(strvalue)
258258
ColorType.parse(strvalue)
259259

openhab/items.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def _validate_value(self, value: typing.Union[str, typing.Type[openhab.command_t
169169
validation = True
170170

171171
if not validation:
172-
raise ValueError('Invalid value "{}"'.format(value))
172+
raise ValueError(f'Invalid value "{value}"')
173173
else:
174174
raise ValueError()
175175

@@ -282,8 +282,8 @@ class GroupItem(Item):
282282
"""String item type."""
283283

284284
TYPENAME = 'Group'
285-
types = []
286-
state_types = []
285+
types: typing.List[typing.Type[openhab.command_types.CommandType]] = []
286+
state_types: typing.List[typing.Type[openhab.command_types.CommandType]] = []
287287

288288

289289
class StringItem(Item):
@@ -456,9 +456,9 @@ def _parse_rest(self, value: str) -> typing.Tuple[typing.Union[float, None], str
456456
return float(value), ''
457457

458458
except (ArithmeticError, ValueError) as exc:
459-
self.logger.error('error in parsing new value "{}" for "{}"'.format(value, self.name), exc)
459+
self.logger.error('Error in parsing new value "%s" for "%s" - "%s"', value, self.name, exc)
460460

461-
raise ValueError('{}: unable to parse value "{}"'.format(self.__class__, value))
461+
raise ValueError(f'{self.__class__}: unable to parse value "{value}"')
462462

463463
def _rest_format(self, value: float) -> str: # type: ignore[override]
464464
"""Format a value before submitting to openHAB.
@@ -484,7 +484,7 @@ def command(self, *args: typing.Any, **kwargs: typing.Any) -> None:
484484
485485
Note: Commands are not accepted for items of type contact.
486486
"""
487-
raise ValueError('This item ({}) only supports updates, not commands!'.format(self.__class__))
487+
raise ValueError(f'This item ({self.__class__}) only supports updates, not commands!')
488488

489489
def open(self) -> None:
490490
"""Set the state of the contact item to OPEN."""

0 commit comments

Comments
 (0)