Skip to content

Commit 5f473e0

Browse files
committed
fix some ruff issues
1 parent fb141da commit 5f473e0

4 files changed

Lines changed: 30 additions & 28 deletions

File tree

examples/mix_v1_example_dashboard.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def safe_float(val: str | float, default: float = 0.0) -> float:
4141
)
4242

4343
# test token from official API docs https://www.showdoc.com.cn/262556420217021/1494053950115877
44-
# api_token = "6eb6f069523055a339d71e5b1f6c88cc" # gitleaks:allow
44+
# api_token = "6eb6f069523055a339d71e5b1f6c88cc" # gitleaks:allow # noqa: ERA001
4545

4646
try:
4747
# Initialize the API with token
@@ -51,7 +51,7 @@ def safe_float(val: str | float, default: float = 0.0) -> float:
5151
plants = api.plant_list()
5252
print(f"Plants: Found {plants['count']} plants") # noqa: T201
5353
plant_id = plants["plants"][0]["plant_id"]
54-
today = datetime.date.today()
54+
today = datetime.datetime.now(tz=datetime.UTC).date()
5555
devices = api.get_devices(plant_id)
5656

5757
energy_data = None
@@ -65,7 +65,7 @@ def safe_float(val: str | float, default: float = 0.0) -> float:
6565

6666
if energy_data is None:
6767
msg = "No SPH_MIX device found to get energy data from."
68-
raise Exception(msg)
68+
raise RuntimeError(msg) # noqa: TRY301
6969

7070
solar_production = f"{safe_float(energy_data.get('epvtoday')):.1f}/{safe_float(energy_data.get('epvTotal')):.1f}" # noqa: E501
7171
solar_production_pv1 = f"{safe_float(energy_data.get('epv1Today')):.1f}/{safe_float(energy_data.get('epv1Total')):.1f}" # noqa: E501

examples/noah_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def indent_print(to_output: str, indent: int) -> None:
3636
login_response = api.login(username, user_pass)
3737

3838
plant_list = api.plant_list(login_response["user"]["id"])
39-
# pp.pprint(plant_list)
39+
# pp.pprint(plant_list) # noqa: ERA001
4040

4141
print("***Totals for all plants***") # noqa: T201
4242
pp.pprint(plant_list["totalData"])
@@ -51,7 +51,7 @@ def indent_print(to_output: str, indent: int) -> None:
5151
plant_id = plant["plantId"]
5252
plant_name = plant["plantName"]
5353
plant_info = api.plant_info(plant_id)
54-
# pp.pprint(plant_info)
54+
# pp.pprint(plant_info) # noqa: ERA001
5555
print(f"***Info for Plant {plant_id} - {plant_name}***") # noqa: T201
5656
# There are more values in plant_info, but these are some of the
5757
# useful/interesting ones

examples/settings_example.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
"""Example script for reading device settings."""
23

34
import datetime
@@ -51,7 +52,7 @@
5152
# Get plant settings - This is performed for us inside
5253
# 'update_plant_settings' but you can get ALL of the settings using this
5354
current_settings = api.get_plant_settings(plant_id)
54-
# pp.pprint(current_settings)
55+
# pp.pprint(current_settings) # noqa: ERA001
5556

5657

5758
# Change the timezone of the plant
@@ -64,7 +65,7 @@
6465

6566

6667
# Set inverter time
67-
now = datetime.datetime.now()
68+
now = datetime.datetime.now(tz=datetime.UTC)
6869
dt_string = now.strftime("%Y-%m-%d %H:%M:%S")
6970
time_settings = {"param1": dt_string}
7071
print(f"Setting inverter time to: {dt_string}") # noqa: T201

examples/settings_example_AC.py

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
"""Example script for reading AC device settings."""
1+
"""
2+
Example script for reading AC device settings.
3+
4+
Sample script to set AC battery charging.
5+
6+
Takes commandline arguments for terminal SOC, start time, end time,
7+
and whether to run, with default arguments if none are given.
8+
Tested on an SPA3000.
9+
""" # noqa: N999
210

311
import json
412
import sys
513

614
import growattServer
715

8-
"""
9-
Sample script to set AC battery charging
10-
Takes commandline arguments for terminal SOC, start time, end time,
11-
and whether to run, with default arguments if none are given
12-
Tested on an SPA3000
13-
"""
14-
1516
# check for SOC percent and whether to run
16-
if len(sys.argv) != 7:
17+
if len(sys.argv) != 7: # noqa: PLR2004
1718
SOC = "40"
18-
startH = "0"
19-
startM = "40"
20-
endH = "04"
21-
endM = "30"
19+
start_h = "0"
20+
start_m = "40"
21+
end_h = "04"
22+
end_m = "30"
2223
run = "1"
2324
else:
2425
SOC = str(sys.argv[1])
25-
startH = f"{int(sys.argv[2]):02.0f}"
26-
startM = f"{int(sys.argv[3]):02.0f}"
27-
endH = f"{int(sys.argv[4]):02.0f}"
28-
endM = f"{int(sys.argv[5]):02.0f}"
26+
start_h = f"{int(sys.argv[2]):02.0f}"
27+
start_m = f"{int(sys.argv[3]):02.0f}"
28+
end_h = f"{int(sys.argv[4]):02.0f}"
29+
end_m = f"{int(sys.argv[5]):02.0f}"
2930
run = str(sys.argv[6])
3031

3132
api = growattServer.GrowattApi()
@@ -47,10 +48,10 @@
4748
schedule_settings = [
4849
"100", # Charging power %
4950
SOC, # Stop charging at SoC %
50-
startH,
51-
startM, # Schedule 1 - Start time
52-
endH,
53-
endM, # Schedule 1 - End time
51+
start_h,
52+
start_m, # Schedule 1 - Start time
53+
end_h,
54+
end_m, # Schedule 1 - End time
5455
run, # Schedule 1 - Enabled/Disabled (1 = Enabled)
5556
"00",
5657
"00", # Schedule 2 - Start time

0 commit comments

Comments
 (0)