Skip to content

Commit 2c9f4ac

Browse files
committed
formatting for older files
1 parent f214c76 commit 2c9f4ac

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

growattServer/base_api.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,40 @@
1515
BATT_MODE_GRID_FIRST = 2
1616

1717

18-
def hash_password(password):
19-
"""
20-
Normal MD5, except add c if a byte of the digest is less than 10.
21-
"""
22-
password_md5 = hashlib.md5(password.encode("utf-8")).hexdigest()
18+
def hash_password(password: str) -> str:
19+
"""Hash password using modified MD5 (adds 'c' if byte < 10)."""
20+
password_md5 = hashlib.md5(password.encode("utf-8")).hexdigest() # noqa: S324
2321
for i in range(0, len(password_md5), 2):
2422
if password_md5[i] == "0":
2523
password_md5 = password_md5[0:i] + "c" + password_md5[i + 1 :]
2624
return password_md5
2725

2826

2927
class Timespan(IntEnum):
28+
"""Time period enumeration for API queries."""
29+
3030
hour = 0
3131
day = 1
3232
month = 2
3333

3434

3535
class GrowattApi:
36+
"""Base API client for Growatt server communication."""
37+
3638
server_url = "https://openapi.growatt.com/"
3739
agent_identifier = "Dalvik/2.1.0 (Linux; U; Android 12; https://github.com/indykoning/PyPi_GrowattServer)"
3840

39-
def __init__(self, add_random_user_id=False, agent_identifier=None):
41+
def __init__(
42+
self, *, add_random_user_id: bool = False, agent_identifier: str | None = None
43+
) -> None:
44+
"""
45+
Initialize the Growatt API client.
46+
47+
Args:
48+
add_random_user_id: Whether to add a random 5-digit ID to the user agent.
49+
agent_identifier: Custom user agent string (overrides default if provided).
50+
51+
"""
4052
if agent_identifier != None:
4153
self.agent_identifier = agent_identifier
4254

0 commit comments

Comments
 (0)