Skip to content

Commit cf5a21f

Browse files
authored
Add additional typing (#438)
1 parent 39e9513 commit cf5a21f

20 files changed

Lines changed: 182 additions & 124 deletions

pyisy/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
limitations under the License.
2222
"""
2323

24+
from __future__ import annotations
25+
2426
from importlib.metadata import PackageNotFoundError, version
2527

2628
from .exceptions import (

pyisy/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using this module.
99
"""
1010

11+
from __future__ import annotations
12+
1113
import argparse
1214
import asyncio
1315
import logging

pyisy/configuration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""ISY Configuration Lookup."""
22

3+
from __future__ import annotations
4+
35
from xml.dom import minidom
46

57
from .constants import (

pyisy/connection.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Connection to the ISY."""
22

3+
from __future__ import annotations
4+
35
import asyncio
46
import ssl
57
from urllib.parse import quote, urlencode
@@ -57,15 +59,15 @@ class Connection:
5759

5860
def __init__(
5961
self,
60-
address,
61-
port,
62-
username,
63-
password,
64-
use_https=False,
65-
tls_ver=1.1,
66-
webroot="",
67-
websession=None,
68-
):
62+
address: str,
63+
port: int,
64+
username: str,
65+
password: str,
66+
use_https: bool = False,
67+
tls_ver: float = 1.1,
68+
webroot: str = "",
69+
websession: aiohttp.ClientSession | None = None,
70+
) -> None:
6971
"""Initialize the Connection object."""
7072
if len(_LOGGER.handlers) == 0:
7173
enable_logging(add_null_handler=True)
@@ -90,27 +92,27 @@ def __init__(
9092
self.req_session = websession
9193
self.sslcontext = get_sslcontext(use_https, tls_ver)
9294

93-
async def test_connection(self):
95+
async def test_connection(self) -> str | None:
9496
"""Test the connection and get the config for the ISY."""
9597
config = await self.get_config(retries=None)
9698
if not config:
9799
_LOGGER.error("Could not connect to the ISY with the parameters provided.")
98100
raise ISYConnectionError
99101
return config
100102

101-
def increase_available_connections(self):
103+
def increase_available_connections(self) -> None:
102104
"""Increase the number of allowed connections for newer hardware."""
103105
_LOGGER.debug("Increasing available simultaneous connections")
104106
self.semaphore = asyncio.Semaphore(
105107
MAX_HTTPS_CONNECTIONS_IOX if self.use_https else MAX_HTTP_CONNECTIONS_IOX
106108
)
107109

108-
async def close(self):
110+
async def close(self) -> None:
109111
"""Cleanup connections and prepare for exit."""
110112
await self.req_session.close()
111113

112114
@property
113-
def connection_info(self):
115+
def connection_info(self) -> dict[str, str | int | bytes | None]:
114116
"""Return the connection info required to connect to the ISY."""
115117
connection_info = {}
116118
connection_info["auth"] = self._auth.encode()
@@ -124,12 +126,12 @@ def connection_info(self):
124126
return connection_info
125127

126128
@property
127-
def url(self):
129+
def url(self) -> str:
128130
"""Return the full connection url."""
129131
return self._url
130132

131133
# COMMON UTILITIES
132-
def compile_url(self, path: list[str], query: str | None = None):
134+
def compile_url(self, path: list[str], query: str | None = None) -> str:
133135
"""Compile the URL to fetch from the ISY."""
134136
url = self.url
135137
if path is not None:

pyisy/constants.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Constants for the PyISY Module."""
22

3+
from __future__ import annotations
4+
35
import datetime
46

57
UPDATE_INTERVAL = 0.5

pyisy/events/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
"""ISY Event Stream Subclasses."""
2+
3+
from __future__ import annotations

pyisy/events/eventreader.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""ISY TCP Socket Event Reader."""
22

3+
from __future__ import annotations
4+
35
import errno
46
import select
57
import ssl

pyisy/events/strings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Strings for Event Stream Requests."""
22

3+
from __future__ import annotations
4+
35
# Subscribe Message
46
SUB_MSG = {
57
"head": """POST /services HTTP/1.1

pyisy/events/tcpsocket.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""ISY Event Stream."""
22

3+
from __future__ import annotations
4+
35
import asyncio
46
import logging
57
import socket

pyisy/exceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Exceptions used by the PyISY module."""
22

3+
from __future__ import annotations
4+
35
from xml.parsers.expat import ExpatError
46

57
XML_ERRORS = (AttributeError, KeyError, ValueError, TypeError, IndexError, ExpatError)

0 commit comments

Comments
 (0)