Skip to content

Commit fb141da

Browse files
committed
Fix ruff issues
1 parent dfccc0f commit fb141da

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

examples/mix_example.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import getpass
2727
import json
2828
import pprint
29+
from pathlib import Path
2930

3031
from . import growattServer
3132

@@ -97,15 +98,15 @@ def indent_print(to_output: str, indent: int) -> None:
9798
pp.pprint(mix_info)
9899

99100
print("Saving inverter data to old_inverter_data.json") # noqa: T201
100-
with open("old_inverter_data.json", "w") as f:
101+
with Path("old_inverter_data.json").open("w") as f:
101102
json.dump(mix_info, f, indent=4, sort_keys=True)
102103

103104
mix_totals = api.mix_totals(device_sn, plant_id)
104105
print("Saving energy data to old_energy_data.json") # noqa: T201
105-
with open("old_energy_data.json", "w") as f:
106+
with Path("old_energy_data.json").open("w") as f:
106107
json.dump(mix_totals, f, indent=4, sort_keys=True)
107108

108-
# pp.pprint(mix_totals)
109+
# pp.pprint(mix_totals) # noqa: ERA001
109110
indent_print("*TOTAL VALUES*", 4)
110111
indent_print("==Today Totals==", 4)
111112
indent_print(f"Battery Charge (kwh): {mix_info['eBatChargeToday']}", 6)
@@ -124,9 +125,9 @@ def indent_print(to_output: str, indent: int) -> None:
124125
mix_detail = api.mix_detail(device_sn, plant_id)
125126

126127
print("Saving energy data to old_detail_data.json") # noqa: T201
127-
with open("old_detail_data.json", "w") as f:
128+
with Path("old_detail_data.json").open("w") as f:
128129
json.dump(mix_detail, f, indent=4, sort_keys=True)
129-
# pp.pprint(mix_detail)
130+
# pp.pprint(mix_detail) # noqa: ERA001
130131

131132
# Some of the 'totals' values that are returned by this function do not align # noqa: E501
132133
# to what we would expect, however the graph data always seems to be accurate.
@@ -136,37 +137,37 @@ def indent_print(to_output: str, indent: int) -> None:
136137
# and 'import from grid' (etouser) which seem to be calculated from one-another
137138
# It would appear that 'etouser' is calculated on the backend incorrectly # noqa: E501
138139
# for systems that use AC battery charged (e.g. during cheap nighttime rates)
139-
pacToGridToday = 0.0
140-
pacToUserToday = 0.0
141-
pdischargeToday = 0.0
142-
ppvToday = 0.0
143-
sysOutToday = 0.0
144-
145-
chartData = mix_detail["chartData"]
146-
for data_points in chartData.values():
140+
pac_to_grid_today = 0.0
141+
pac_to_user_today = 0.0
142+
pdischarge_today = 0.0
143+
ppv_today = 0.0
144+
sys_out_today = 0.0
145+
146+
chart_data = mix_detail["chartData"]
147+
for data_points in chart_data.values():
147148
# For each time entry convert it's wattage into kWh, this assumes # noqa: E501
148149
# that the wattage value is the same for the whole 5 minute window # noqa: E501
149150
# (it's the only assumption we can make)
150151
# We Multiply the wattage by 5/60 (the number of minutes of the time # noqa: E501
151152
# window divided by the number of minutes in an hour) to give us the # noqa: E501
152153
# equivalent kWh reading for that 5 minute window
153-
pacToGridToday += float(data_points["pacToGrid"]) * (5 / 60)
154-
pacToUserToday += float(data_points["pacToUser"]) * (5 / 60)
155-
pdischargeToday += float(data_points["pdischarge"]) * (5 / 60)
156-
ppvToday += float(data_points["ppv"]) * (5 / 60)
157-
sysOutToday += float(data_points["sysOut"]) * (5 / 60)
158-
159-
mix_detail["calculatedPacToGridTodayKwh"] = round(pacToGridToday, 2)
160-
mix_detail["calculatedPacToUserTodayKwh"] = round(pacToUserToday, 2)
161-
mix_detail["calculatedPdischargeTodayKwh"] = round(pdischargeToday, 2)
162-
mix_detail["calculatedPpvTodayKwh"] = round(ppvToday, 2)
163-
mix_detail["calculatedSysOutTodayKwh"] = round(sysOutToday, 2)
154+
pac_to_grid_today += float(data_points["pacToGrid"]) * (5 / 60)
155+
pac_to_user_today += float(data_points["pacToUser"]) * (5 / 60)
156+
pdischarge_today += float(data_points["pdischarge"]) * (5 / 60)
157+
ppv_today += float(data_points["ppv"]) * (5 / 60)
158+
sys_out_today += float(data_points["sysOut"]) * (5 / 60)
159+
160+
mix_detail["calculatedPacToGridTodayKwh"] = round(pac_to_grid_today, 2)
161+
mix_detail["calculatedPacToUserTodayKwh"] = round(pac_to_user_today, 2)
162+
mix_detail["calculatedPdischargeTodayKwh"] = round(pdischarge_today, 2)
163+
mix_detail["calculatedPpvTodayKwh"] = round(ppv_today, 2)
164+
mix_detail["calculatedSysOutTodayKwh"] = round(sys_out_today, 2)
164165

165166
# Option to print mix_detail again now we've made the additions
166-
# pp.pprint(mix_detail)
167+
# pp.pprint(mix_detail) # noqa: ERA001
167168

168169
dashboard_data = api.dashboard_data(plant_id)
169-
# pp.pprint(dashboard_data)
170+
# pp.pprint(dashboard_data) # noqa: ERA001
170171

171172
indent_print("*TODAY TOTALS BREAKDOWN*", 4)
172173
indent_print(
@@ -267,7 +268,7 @@ def indent_print(to_output: str, indent: int) -> None:
267268
# This call gets all of the instantaneous values from the system
268269
# e.g. current load, generation etc.
269270
mix_status = api.mix_system_status(device_sn, plant_id)
270-
# pp.pprint(mix_status)
271+
# pp.pprint(mix_status) # noqa: ERA001
271272
# NOTE - There are some other values available in mix_status,
272273
# however these are the most useful ones
273274
indent_print("*CURRENT VALUES*", 4)

0 commit comments

Comments
 (0)