File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515BATT_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
2927class Timespan (IntEnum ):
28+ """Time period enumeration for API queries."""
29+
3030 hour = 0
3131 day = 1
3232 month = 2
3333
3434
3535class 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
You can’t perform that action at this time.
0 commit comments