Skip to content

Commit fe7417d

Browse files
Fox workaround for fd power max (#2907)
* Fox workaround for fd power max * Revert gecloud change
1 parent a127315 commit fe7417d

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

apps/predbat/fox.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -747,8 +747,14 @@ async def get_scheduler(self, deviceSN):
747747
result = await self.request_get(GET_SCHEDULER, datain={"deviceSN": deviceSN}, post=True)
748748
if result:
749749
self.fdpwr_max[deviceSN] = result.get("properties", {}).get("fdpwr", {}).get("range", {}).get("max", 8000)
750+
# XXX: Fox seems to be have an issue with FD Power max value, no maximum is listed but the default fdPwr listed in disabled groups seems to be the max so find that
751+
for group in result.get("groups", []):
752+
if group.get("enable", 1) == 0:
753+
self.fdpwr_max[deviceSN] = group.get("fdPwr", self.fdpwr_max[deviceSN])
754+
break
755+
750756
self.fdsoc_min[deviceSN] = result.get("properties", {}).get("fdsoc", {}).get("range", {}).get("min", 10)
751-
self.log("Fox: Fetched schedule got {}".format(result))
757+
self.log("Fox: Fetched schedule got {} fdPwr max {} fdSoc min {}".format(result, self.fdpwr_max[deviceSN], self.fdsoc_min[deviceSN]))
752758
self.device_scheduler[deviceSN] = result
753759
return result
754760
return {}
@@ -853,21 +859,21 @@ async def request_get_func(self, path, post=False, datain=None):
853859
self.failures_total += 1
854860
if errno in [40400, 41200, 41201, 41202, 41203, 41935, 44098]:
855861
# Rate limiting so wait up to 31 seconds
856-
self.log("Info: Fox: Rate limiting or comms issue detected, waiting...")
862+
self.log(f"Info: Fox: Rate limiting or comms issue detected {msg}:{errno}, waiting...")
857863
await asyncio.sleep(random.random() * 30 + 1)
858864
return None, True
859865
elif errno in [40402]:
860866
# Out of API calls for today
861-
self.log("Warn: Fox: Has run out of API calls for today, sleeping...")
867+
self.log(f"Warn: Fox: Has run out of API calls for today {msg}:{errno}, sleeping...")
862868
await asyncio.sleep(5 * 60)
863869
return None, False
864870
elif errno in [44096]:
865871
# Unsupported function code
866-
self.log("Warn: Fox: Unsupported function code {} from {}".format(errno, url))
872+
self.log(f"Warn: Fox: Unsupported function code {msg}:{errno} from {url}")
867873
return None, False
868874
elif errno in [40257]:
869875
# Invalid parameter
870-
self.log("Warn: Fox: Invalid parameter {} from {} message {}".format(errno, url, msg))
876+
self.log(f"Warn: Fox: Invalid parameter {msg}:{errno} from {url}")
871877
return None, False
872878
else:
873879
self.log("Warn: Fox: Error {} from {} message {}".format(errno, url, msg))
@@ -1283,12 +1289,16 @@ async def test_fox_api(api_key):
12831289

12841290
# Create FoxAPI instance with a lambda that returns the API key
12851291
fox_api = FoxAPI(api_key, False, mock_base)
1286-
# device_List = await fox_api.get_device_list()
1287-
# print(f"Device List: {device_List}")
1292+
device_List = await fox_api.get_device_list()
1293+
print(f"Device List: {device_List}")
12881294
# await fox_api.start()
1289-
# res = await fox_api.get_device_settings(sn)
1290-
# res = await fox_api.get_battery_charging_time(sn)
1291-
# res = await fox_api.get_scheduler(sn)
1295+
res = await fox_api.get_device_settings(sn)
1296+
print(res)
1297+
res = await fox_api.get_battery_charging_time(sn)
1298+
print(res)
1299+
res = await fox_api.get_scheduler(sn)
1300+
print(res)
1301+
return 1
12921302
# res = await fox_api.compute_schedule(sn)
12931303
# res = await fox_api.publish_data()
12941304
# res = await fox_api.set_device_setting(sn, "dummy", 42)
@@ -1301,13 +1311,13 @@ async def test_fox_api(api_key):
13011311
new_slot = {}
13021312
new_slot["enable"] = 1
13031313
new_slot["workMode"] = "ForceDischarge"
1304-
new_slot["startHour"] = 23
1314+
new_slot["startHour"] = 11
13051315
new_slot["startMinute"] = 30
1306-
new_slot["endHour"] = 23
1307-
new_slot["endMinute"] = 59
1308-
new_slot["fdSoc"] = 10
1309-
new_slot["fdPwr"] = 10500
1310-
new_slot["minSocOnGrid"] = 10
1316+
new_slot["endHour"] = 12
1317+
new_slot["endMinute"] = 00
1318+
new_slot["fdSoc"] = 20
1319+
new_slot["fdPwr"] = 4000
1320+
new_slot["minSocOnGrid"] = 20
13111321
new_slot2 = {}
13121322
new_slot2["enable"] = 1
13131323
new_slot2["workMode"] = "ForceCharge"
@@ -1319,10 +1329,9 @@ async def test_fox_api(api_key):
13191329
new_slot2["fdPwr"] = 8000
13201330
new_slot2["minSocOnGrid"] = 100
13211331

1322-
new_schedule = fox_api.validate_schedule([new_slot2, new_slot])
1332+
new_schedule = fox_api.validate_schedule([new_slot])
13231333
print("Validated schedule")
13241334
print(new_schedule)
1325-
return 0
13261335

13271336
print("Sending: {}".format(new_schedule))
13281337
res = await fox_api.set_scheduler(sn, new_schedule)

apps/predbat/gecloud.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,8 +1262,6 @@ async def async_get_devices(self):
12621262
result["gateway"] = serial
12631263
elif batteries:
12641264
result["battery"].append(serial)
1265-
elif battery:
1266-
result["battery"].append(serial)
12671265
else:
12681266
self.log("Warn: GECloud: Device without serial found: {}".format(device))
12691267
return result

apps/predbat/predbat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import requests
2626
import asyncio
2727

28-
THIS_VERSION = "v8.27.17"
28+
THIS_VERSION = "v8.27.18"
2929

3030
# fmt: off
3131
PREDBAT_FILES = ["predbat.py", "config.py", "prediction.py", "gecloud.py","utils.py", "inverter.py", "ha.py", "download.py", "unit_test.py", "web.py", "web_helper.py", "predheat.py", "futurerate.py", "octopus.py", "solcast.py","execute.py", "plan.py", "fetch.py", "output.py", "userinterface.py", "energydataservice.py", "alertfeed.py", "compare.py", "db_manager.py", "db_engine.py", "plugin_system.py", "ohme.py", "components.py", "fox.py", "carbon.py", "web_mcp.py"]

0 commit comments

Comments
 (0)