set vnish power limit

This commit is contained in:
Wilfred Allyn
2024-11-30 07:39:00 -05:00
committed by Brett Rowan
parent 4b16ea2ca2
commit a3087e1a96
2 changed files with 26 additions and 0 deletions

View File

@@ -14,6 +14,7 @@
# limitations under the License. - # limitations under the License. -
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import logging
from typing import Optional from typing import Optional
from pyasic import MinerConfig from pyasic import MinerConfig
@@ -272,3 +273,19 @@ class VNish(VNishFirmware, BMMiner):
return self.config return self.config
self.config = MinerConfig.from_vnish(web_settings, web_presets) self.config = MinerConfig.from_vnish(web_settings, web_presets)
return self.config return self.config
async def set_power_limit(self, wattage: int) -> bool:
# Can only set power limit to tuned preset
try:
await self.web.set_power_limit(wattage)
updated_settings = await self.web.settings()
except APIError:
raise
except Exception as e:
logging.warning(f"{self} - Failed to set power limit: {e}")
return False
if int(updated_settings["miner"]["overclock"]["preset"]) == wattage:
return True
else:
return False

View File

@@ -138,6 +138,15 @@ class VNishWebAPI(BaseWebAPI):
async def settings(self) -> dict: async def settings(self) -> dict:
return await self.send_command("settings") return await self.send_command("settings")
async def set_power_limit(self, wattage: int) -> bool:
# Can only set power limit to tuned preset
settings = await self.settings()
settings["miner"]["overclock"]["preset"] = str(wattage)
new_settings = {"miner": {"overclock": settings["miner"]["overclock"]}}
# response will always be {"restart_required":false,"reboot_required":false} even if unsuccessful
return await self.send_command("settings", privileged=True, **new_settings)
async def autotune_presets(self) -> dict: async def autotune_presets(self) -> dict:
return await self.send_command("autotune/presets") return await self.send_command("autotune/presets")