Skip to content

Commit d16ff78

Browse files
committed
linter fixes
1 parent 34c11c0 commit d16ff78

File tree

8 files changed

+140
-137
lines changed

8 files changed

+140
-137
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ max_line_length = 240
1212
ij_continuation_indent_size = 2
1313
ij_python_blank_line_at_file_end = true
1414

15-
[{*.yml_sample,*.yaml_sample,*.yml,*.yaml}]
15+
[{*.yml_sample,*.yaml_sample,*.yml,*.yaml,*.toml}]
1616
indent_size = 2

openhab/client.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def __init__(
4343
password: typing.Optional[str] = None,
4444
http_auth: typing.Optional[httpx.Auth] = None,
4545
timeout: typing.Optional[float] = None,
46-
oauth2_config: typing.Optional[typing.Dict[str, typing.Any]] = None,
46+
oauth2_config: typing.Optional[dict[str, typing.Any]] = None,
4747
) -> None:
4848
"""Class constructor.
4949
@@ -136,7 +136,7 @@ def _check_req_return(req: httpx.Response) -> None:
136136
if not 200 <= req.status_code < 300:
137137
req.raise_for_status()
138138

139-
def req_get(self, uri_path: str, params: typing.Optional[typing.Union[typing.Dict[str, typing.Any], list, tuple]] = None) -> typing.Any:
139+
def req_get(self, uri_path: str, params: typing.Optional[typing.Union[dict[str, typing.Any], list, tuple]] = None) -> typing.Any:
140140
"""Helper method for initiating a HTTP GET request.
141141
142142
Besides doing the actual request, it also checks the return value and returns the resulting decoded
@@ -155,7 +155,7 @@ def req_get(self, uri_path: str, params: typing.Optional[typing.Union[typing.Dic
155155
def req_post(
156156
self,
157157
uri_path: str,
158-
data: typing.Optional[typing.Union[str, bytes, typing.Mapping[str, typing.Any], typing.Iterable[typing.Tuple[str, typing.Optional[str]]]]] = None,
158+
data: typing.Optional[typing.Union[str, bytes, typing.Mapping[str, typing.Any], typing.Iterable[tuple[str, typing.Optional[str]]]]] = None,
159159
) -> None:
160160
"""Helper method for initiating a HTTP POST request.
161161
@@ -207,7 +207,7 @@ def req_put(
207207
self._check_req_return(r)
208208

209209
# fetch all items
210-
def fetch_all_items(self) -> typing.Dict[str, openhab.items.Item]:
210+
def fetch_all_items(self) -> dict[str, openhab.items.Item]:
211211
"""Returns all items defined in openHAB.
212212
213213
Returns:
@@ -317,7 +317,7 @@ def logout(self) -> bool:
317317

318318
return res.status_code == 200
319319

320-
def _oauth2_token_updater(self, token: typing.Dict[str, typing.Any], refresh_token: typing.Any = None, access_token: typing.Any = None) -> None:
320+
def _oauth2_token_updater(self, token: dict[str, typing.Any], refresh_token: typing.Any = None, access_token: typing.Any = None) -> None:
321321
if self.oauth2_config is None:
322322
raise ValueError('OAuth2 configuration is not set; invalid action!')
323323

@@ -329,15 +329,15 @@ def _oauth2_token_updater(self, token: typing.Dict[str, typing.Any], refresh_tok
329329
def create_or_update_item(
330330
self,
331331
name: str,
332-
_type: typing.Union[str, typing.Type[openhab.items.Item]],
332+
_type: typing.Union[str, type[openhab.items.Item]],
333333
quantity_type: typing.Optional[str] = None,
334334
label: typing.Optional[str] = None,
335335
category: typing.Optional[str] = None,
336-
tags: typing.Optional[typing.List[str]] = None,
337-
group_names: typing.Optional[typing.List[str]] = None,
338-
group_type: typing.Optional[typing.Union[str, typing.Type[openhab.items.Item]]] = None,
336+
tags: typing.Optional[list[str]] = None,
337+
group_names: typing.Optional[list[str]] = None,
338+
group_type: typing.Optional[typing.Union[str, type[openhab.items.Item]]] = None,
339339
function_name: typing.Optional[str] = None,
340-
function_params: typing.Optional[typing.List[str]] = None,
340+
function_params: typing.Optional[list[str]] = None,
341341
) -> None:
342342
"""Creates a new item in openHAB if there is no item with name 'name' yet.
343343
@@ -359,7 +359,7 @@ def create_or_update_item(
359359
Can be one of ['EQUALITY', 'AND', 'OR', 'NAND', 'NOR', 'AVG', 'SUM', 'MAX', 'MIN', 'COUNT', 'LATEST', 'EARLIEST']
360360
function_params: Optional list of function params (no documentation found), depending on function name.
361361
"""
362-
paramdict: typing.Dict[str, typing.Union[str, typing.List[str], typing.Dict[str, typing.Union[str, typing.List[str]]]]] = {}
362+
paramdict: dict[str, typing.Union[str, list[str], dict[str, typing.Union[str, list[str]]]]] = {}
363363

364364
if isinstance(_type, type):
365365
if issubclass(_type, openhab.items.Item):
@@ -425,7 +425,7 @@ def get_item_persistence(
425425
page: int = 0,
426426
page_length: int = 0,
427427
boundary: bool = False,
428-
) -> typing.Iterator[typing.Dict[str, typing.Union[str, int]]]:
428+
) -> typing.Iterator[dict[str, typing.Union[str, int]]]:
429429
"""Method for fetching persistence data for a given item.
430430
431431
Args:
@@ -443,7 +443,7 @@ def get_item_persistence(
443443
"state": "23"
444444
}
445445
"""
446-
params: typing.Dict[str, typing.Any] = {
446+
params: dict[str, typing.Any] = {
447447
'boundary': str(boundary).lower(),
448448
'page': page,
449449
'pagelength': page_length,

openhab/command_types.py

+9-11
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CommandType(metaclass=abc.ABCMeta):
3434
"""Base command type class."""
3535

3636
TYPENAME = ''
37-
SUPPORTED_TYPENAMES: typing.List[str] = []
37+
SUPPORTED_TYPENAMES: list[str] = []
3838
UNDEF = 'UNDEF'
3939
NULL = 'NULL'
4040
UNDEFINED_STATES = [UNDEF, NULL]
@@ -48,8 +48,8 @@ def is_undefined(cls, value: typing.Any) -> bool:
4848
def get_type_for(
4949
cls,
5050
typename: str,
51-
parent_cls: typing.Optional[typing.Type['CommandType']] = None,
52-
) -> typing.Union[typing.Type['CommandType'], None]:
51+
parent_cls: typing.Optional[type['CommandType']] = None,
52+
) -> typing.Union[type['CommandType'], None]:
5353
"""Get a class type for a given typename."""
5454
if parent_cls is None:
5555
parent_cls = CommandType
@@ -230,7 +230,7 @@ class ColorType(CommandType):
230230
SUPPORTED_TYPENAMES = [TYPENAME]
231231

232232
@classmethod
233-
def parse(cls, value: str) -> typing.Optional[typing.Tuple[float, float, float]]:
233+
def parse(cls, value: str) -> typing.Optional[tuple[float, float, float]]:
234234
"""Parse a given value."""
235235
if value in ColorType.UNDEFINED_STATES:
236236
return None
@@ -251,7 +251,7 @@ def parse(cls, value: str) -> typing.Optional[typing.Tuple[float, float, float]]
251251
return h, s, b
252252

253253
@classmethod
254-
def validate(cls, value: typing.Union[str, typing.Tuple[float, float, float]]) -> None:
254+
def validate(cls, value: typing.Union[str, tuple[float, float, float]]) -> None:
255255
"""Value validation method.
256256
257257
Valid values are in format H,S,B.
@@ -283,7 +283,7 @@ class DecimalType(CommandType):
283283
SUPPORTED_TYPENAMES = [TYPENAME, 'Quantity']
284284

285285
@classmethod
286-
def parse(cls, value: str) -> typing.Union[None, typing.Tuple[typing.Union[int, float], str]]:
286+
def parse(cls, value: str) -> typing.Union[None, tuple[typing.Union[int, float], str]]:
287287
"""Parse a given value."""
288288
if value in DecimalType.UNDEFINED_STATES:
289289
return None
@@ -306,7 +306,7 @@ def parse(cls, value: str) -> typing.Union[None, typing.Tuple[typing.Union[int,
306306
raise ValueError
307307

308308
@classmethod
309-
def validate(cls, value: typing.Union[float, typing.Tuple[float, str], str]) -> None:
309+
def validate(cls, value: typing.Union[float, tuple[float, str], str]) -> None:
310310
"""Value validation method.
311311
312312
Valid values are any of data_type:
@@ -611,7 +611,7 @@ class PointType(CommandType):
611611
SUPPORTED_TYPENAMES = [TYPENAME]
612612

613613
@classmethod
614-
def parse(cls, value: str) -> typing.Optional[typing.Tuple[float, float, float]]:
614+
def parse(cls, value: str) -> typing.Optional[tuple[float, float, float]]:
615615
"""Parse a given value."""
616616
if value in PercentType.UNDEFINED_STATES:
617617
return None
@@ -630,9 +630,7 @@ def parse(cls, value: str) -> typing.Optional[typing.Tuple[float, float, float]]
630630
return latitude, longitude, altitude
631631

632632
@classmethod
633-
def validate(
634-
cls, value: typing.Optional[typing.Union[str, typing.Tuple[typing.Union[float, int], typing.Union[float, int], typing.Union[float, int]]]]
635-
) -> None:
633+
def validate(cls, value: typing.Optional[typing.Union[str, tuple[typing.Union[float, int], typing.Union[float, int], typing.Union[float, int]]]]) -> None:
636634
"""Value validation method.
637635
638636
A valid PointType is a tuple of three decimal values representing:

openhab/config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Oauth2User(pydantic.BaseModel):
5252
"""Nested user structure within an oauth2 token."""
5353

5454
name: str
55-
roles: typing.List[str]
55+
roles: list[str]
5656

5757

5858
class Oauth2Token(pydantic.BaseModel):
@@ -62,7 +62,7 @@ class Oauth2Token(pydantic.BaseModel):
6262
expires_in: int
6363
expires_at: float = time.time() - 10
6464
refresh_token: str
65-
scope: typing.Union[str, typing.List[str]] = 'admin'
65+
scope: typing.Union[str, list[str]] = 'admin'
6666
token_type: str
6767
user: Oauth2User
6868

openhab/items.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@
3434
class Item:
3535
"""Base item class."""
3636

37-
types: typing.Sequence[typing.Type[openhab.command_types.CommandType]] = []
38-
state_types: typing.Sequence[typing.Type[openhab.command_types.CommandType]] = []
39-
command_event_types: typing.Sequence[typing.Type[openhab.command_types.CommandType]] = []
40-
state_event_types: typing.Sequence[typing.Type[openhab.command_types.CommandType]] = []
41-
state_changed_event_types: typing.Sequence[typing.Type[openhab.command_types.CommandType]] = []
37+
types: typing.Sequence[type[openhab.command_types.CommandType]] = []
38+
state_types: typing.Sequence[type[openhab.command_types.CommandType]] = []
39+
command_event_types: typing.Sequence[type[openhab.command_types.CommandType]] = []
40+
state_event_types: typing.Sequence[type[openhab.command_types.CommandType]] = []
41+
state_changed_event_types: typing.Sequence[type[openhab.command_types.CommandType]] = []
4242

4343
TYPENAME = 'unknown'
4444

@@ -144,7 +144,7 @@ def unit_of_measure(self) -> str:
144144
return self._unitOfMeasure
145145

146146
@property
147-
def members(self) -> typing.Dict[str, typing.Any]:
147+
def members(self) -> dict[str, typing.Any]:
148148
"""If item is a type of Group, it will return all member items for this group.
149149
150150
For none group item empty dictionary will be returned.
@@ -155,7 +155,7 @@ def members(self) -> typing.Dict[str, typing.Any]:
155155
"""
156156
return self._members
157157

158-
def _validate_value(self, value: typing.Union[str, typing.Type[openhab.command_types.CommandType]]) -> None:
158+
def _validate_value(self, value: typing.Union[str, type[openhab.command_types.CommandType]]) -> None:
159159
"""Private method for verifying the new value before modifying the state of the item."""
160160
if self.type_ == 'String':
161161
if not isinstance(value, (str, bytes)):
@@ -176,7 +176,7 @@ def _validate_value(self, value: typing.Union[str, typing.Type[openhab.command_t
176176
else:
177177
raise ValueError
178178

179-
def _parse_rest(self, value: str) -> typing.Tuple[str, str]:
179+
def _parse_rest(self, value: str) -> tuple[str, str]:
180180
"""Parse a REST result into a native object."""
181181
return value, ''
182182

@@ -289,7 +289,7 @@ def persistence(
289289
page: int = 0,
290290
page_length: int = 0,
291291
boundary: bool = False,
292-
) -> typing.Iterator[typing.Dict[str, typing.Union[str, int]]]:
292+
) -> typing.Iterator[dict[str, typing.Union[str, int]]]:
293293
"""Method for fetching persistence data for a given item.
294294
295295
Args:
@@ -321,8 +321,8 @@ class GroupItem(Item):
321321
"""String item type."""
322322

323323
TYPENAME = 'Group'
324-
types: typing.List[typing.Type[openhab.command_types.CommandType]] = []
325-
state_types: typing.List[typing.Type[openhab.command_types.CommandType]] = []
324+
types: list[type[openhab.command_types.CommandType]] = []
325+
state_types: list[type[openhab.command_types.CommandType]] = []
326326

327327

328328
class StringItem(Item):
@@ -382,7 +382,7 @@ def __ne__(self, other: object) -> bool:
382382

383383
return not self.__eq__(other)
384384

385-
def _parse_rest(self, value: str) -> typing.Tuple[datetime.datetime, str]: # type: ignore[override]
385+
def _parse_rest(self, value: str) -> tuple[datetime.datetime, str]: # type: ignore[override]
386386
"""Parse a REST result into a native object.
387387
388388
Args:
@@ -470,7 +470,7 @@ class NumberItem(Item):
470470
types = [openhab.command_types.DecimalType]
471471
state_types = types
472472

473-
def _parse_rest(self, value: str) -> typing.Tuple[typing.Union[float, None], str]: # type: ignore[override]
473+
def _parse_rest(self, value: str) -> tuple[typing.Union[float, None], str]: # type: ignore[override]
474474
"""Parse a REST result into a native object.
475475
476476
Args:
@@ -499,7 +499,7 @@ def _parse_rest(self, value: str) -> typing.Tuple[typing.Union[float, None], str
499499

500500
raise ValueError(f'{self.__class__}: unable to parse value "{value}"')
501501

502-
def _rest_format(self, value: typing.Union[float, typing.Tuple[float, str], str]) -> typing.Union[str, bytes]:
502+
def _rest_format(self, value: typing.Union[float, tuple[float, str], str]) -> typing.Union[str, bytes]:
503503
"""Format a value before submitting to openHAB.
504504
505505
Args:
@@ -545,7 +545,7 @@ class DimmerItem(Item):
545545
types = [openhab.command_types.OnOffType, openhab.command_types.PercentType, openhab.command_types.IncreaseDecreaseType]
546546
state_types = [openhab.command_types.PercentType]
547547

548-
def _parse_rest(self, value: str) -> typing.Tuple[float, str]: # type: ignore[override]
548+
def _parse_rest(self, value: str) -> tuple[float, str]: # type: ignore[override]
549549
"""Parse a REST result into a native object.
550550
551551
Args:
@@ -595,7 +595,7 @@ class ColorItem(DimmerItem):
595595
types = [openhab.command_types.OnOffType, openhab.command_types.PercentType, openhab.command_types.IncreaseDecreaseType, openhab.command_types.ColorType]
596596
state_types = [openhab.command_types.ColorType]
597597

598-
def _parse_rest(self, value: str) -> typing.Tuple[typing.Optional[typing.Tuple[float, float, float]], str]: # type: ignore[override]
598+
def _parse_rest(self, value: str) -> tuple[typing.Optional[tuple[float, float, float]], str]: # type: ignore[override]
599599
"""Parse a REST result into a native object.
600600
601601
Args:
@@ -608,7 +608,7 @@ def _parse_rest(self, value: str) -> typing.Tuple[typing.Optional[typing.Tuple[f
608608
result = openhab.command_types.ColorType.parse(value)
609609
return result, ''
610610

611-
def _rest_format(self, value: typing.Union[typing.Tuple[int, int, float], str, int]) -> str:
611+
def _rest_format(self, value: typing.Union[tuple[int, int, float], str, int]) -> str:
612612
"""Format a value before submitting to openHAB.
613613
614614
Args:
@@ -634,7 +634,7 @@ class RollershutterItem(Item):
634634
types = [openhab.command_types.UpDownType, openhab.command_types.PercentType, openhab.command_types.StopMoveType]
635635
state_types = [openhab.command_types.PercentType]
636636

637-
def _parse_rest(self, value: str) -> typing.Tuple[int, str]: # type: ignore[override]
637+
def _parse_rest(self, value: str) -> tuple[int, str]: # type: ignore[override]
638638
"""Parse a REST result into a native object.
639639
640640
Args:
@@ -680,7 +680,7 @@ class LocationItem(Item):
680680
types = [openhab.command_types.PointType]
681681
state_types = [openhab.command_types.PointType]
682682

683-
def _parse_rest(self, value: str) -> typing.Tuple[typing.Optional[typing.Tuple[float, float, float]], str]: # type: ignore[override]
683+
def _parse_rest(self, value: str) -> tuple[typing.Optional[tuple[float, float, float]], str]: # type: ignore[override]
684684
"""Parse a REST result into a native object.
685685
686686
Args:
@@ -692,7 +692,7 @@ def _parse_rest(self, value: str) -> typing.Tuple[typing.Optional[typing.Tuple[f
692692
"""
693693
return openhab.command_types.PointType.parse(value), ''
694694

695-
def _rest_format(self, value: typing.Union[typing.Tuple[float, float, float], str]) -> str:
695+
def _rest_format(self, value: typing.Union[tuple[float, float, float], str]) -> str:
696696
"""Format a value before submitting to openHAB.
697697
698698
Args:

openhab/rules.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ def __init__(self, openhab_conn: 'openhab.client.OpenHAB') -> None:
4141
self.openhab = openhab_conn
4242
self.logger = logging.getLogger(__name__)
4343

44-
def get(self) -> typing.List[typing.Dict[str, typing.Any]]:
44+
def get(self) -> list[dict[str, typing.Any]]:
4545
"""Get all rules."""
4646
return self.openhab.req_get('/rules')

0 commit comments

Comments
 (0)