feature: implement GPRC set commands properly.

This commit is contained in:
Upstream Data
2023-11-18 22:45:09 -07:00
parent d79509bda7
commit 6449f10615

View File

@@ -15,11 +15,11 @@
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
import json import json
from datetime import datetime, timedelta from datetime import datetime, timedelta
from enum import Enum
from typing import List, Union from typing import List, Union
import grpc_requests import grpc_requests
import httpx import httpx
from google.protobuf.message import Message
from grpc import RpcError from grpc import RpcError
from pyasic import APIError, settings from pyasic import APIError, settings
@@ -28,10 +28,31 @@ from pyasic.web.bosminer.proto import (
get_auth_service_descriptors, get_auth_service_descriptors,
get_service_descriptors, get_service_descriptors,
) )
from pyasic.web.bosminer.proto.bos.v1.actions import SaveAction from pyasic.web.bosminer.proto.bos.v1.actions_pb2 import (
from pyasic.web.bosminer.proto.bos.v1.performance import ( SetLocateDeviceStatusRequest, # noqa: this will be defined
ManualPerformanceMode, )
PerformanceMode, from pyasic.web.bosminer.proto.bos.v1.authentication_pb2 import (
SetPasswordRequest, # noqa: this will be defined
)
from pyasic.web.bosminer.proto.bos.v1.common_pb2 import (
SaveAction, # noqa: this will be defined
)
from pyasic.web.bosminer.proto.bos.v1.cooling_pb2 import (
SetImmersionModeRequest, # noqa: this will be defined
)
from pyasic.web.bosminer.proto.bos.v1.miner_pb2 import (
EnableHashboardsRequest, # noqa: this will be defined
DisableHashboardsRequest, # noqa: this will be defined
)
from pyasic.web.bosminer.proto.bos.v1.performance_pb2 import (
SetDefaultPowerTargetRequest, # noqa: this will be defined
IncrementPowerTargetRequest, # noqa: this will be defined
DecrementPowerTargetRequest, # noqa: this will be defined
SetPowerTargetRequest, # noqa: this will be defined
SetDefaultHashrateTargetRequest, # noqa: this will be defined
SetHashrateTargetRequest, # noqa: this will be defined
IncrementHashrateTargetRequest, # noqa: this will be defined
DecrementHashrateTargetRequest, # noqa: this will be defined
) )
@@ -265,7 +286,11 @@ class BOSMinerGRPCAPI:
pass pass
async def send_command( async def send_command(
self, command: str, ignore_errors: bool = False, auth: bool = True, **parameters self,
command: str,
message: Message = None,
ignore_errors: bool = False,
auth: bool = True,
) -> dict: ) -> dict:
service, method = command.split("/") service, method = command.split("/")
metadata = [] metadata = []
@@ -279,7 +304,7 @@ class BOSMinerGRPCAPI:
return await client.request( return await client.request(
service, service,
method, method,
request=parameters, request=message,
metadata=metadata, metadata=metadata,
) )
except RpcError as e: except RpcError as e:
@@ -339,8 +364,10 @@ class BOSMinerGRPCAPI:
return await self.send_command("braiins.bos.v1.ActionsService/Reboot") return await self.send_command("braiins.bos.v1.ActionsService/Reboot")
async def set_locate_device_status(self, enable: bool): async def set_locate_device_status(self, enable: bool):
message = SetLocateDeviceStatusRequest()
message.enable = enable
return await self.send_command( return await self.send_command(
"braiins.bos.v1.ActionsService/SetLocateDeviceStatus", enable=enable "braiins.bos.v1.ActionsService/SetLocateDeviceStatus", message=message
) )
async def get_locate_device_status(self): async def get_locate_device_status(self):
@@ -349,23 +376,26 @@ class BOSMinerGRPCAPI:
) )
async def set_password(self, password: str = None): async def set_password(self, password: str = None):
kwargs = {} message = SetPasswordRequest()
if password: if password:
kwargs["password"] = password message.password = password
return await self.send_command( return await self.send_command(
"braiins.bos.v1.AuthenticationService/SetPassword", **kwargs "braiins.bos.v1.AuthenticationService/SetPassword", message=message
) )
async def get_cooling_state(self): async def get_cooling_state(self):
return await self.send_command("braiins.bos.v1.CoolingService/GetCoolingState") return await self.send_command("braiins.bos.v1.CoolingService/GetCoolingState")
async def set_immersion_mode( async def set_immersion_mode(
self, enable: bool, save_action: SaveAction = SaveAction.SAVE_AND_APPLY self,
enable: bool,
save_action: SaveAction = SaveAction.SAVE_ACTION_SAVE_AND_APPLY,
): ):
message = SetImmersionModeRequest()
message.enable = enable
message.save_action = save_action
return await self.send_command( return await self.send_command(
"braiins.bos.v1.CoolingService/SetImmersionMode", "braiins.bos.v1.CoolingService/SetImmersionMode", message=message
save_action=save_action,
enable_immersion_mode=enable,
) )
async def get_tuner_state(self): async def get_tuner_state(self):
@@ -379,101 +409,114 @@ class BOSMinerGRPCAPI:
) )
async def set_default_power_target( async def set_default_power_target(
self, save_action: SaveAction = SaveAction.SAVE_AND_APPLY self, save_action: SaveAction = SaveAction.SAVE_ACTION_SAVE_AND_APPLY
): ):
message = SetDefaultPowerTargetRequest()
message.save_action = save_action
return await self.send_command( return await self.send_command(
"braiins.bos.v1.PerformanceService/SetDefaultPowerTarget", "braiins.bos.v1.PerformanceService/SetDefaultPowerTarget", message=message
save_action=save_action,
) )
async def set_power_target( async def set_power_target(
self, power_target: int, save_action: SaveAction = SaveAction.SAVE_AND_APPLY self,
power_target: int,
save_action: SaveAction = SaveAction.SAVE_ACTION_SAVE_AND_APPLY,
): ):
message = SetPowerTargetRequest()
message.power_target.watt = power_target
message.save_action = save_action
return await self.send_command( return await self.send_command(
"braiins.bos.v1.PerformanceService/SetPowerTarget", "braiins.bos.v1.PerformanceService/SetPowerTarget", message=message
save_action=save_action,
power_target=power_target,
) )
async def increment_power_target( async def increment_power_target(
self, self,
power_target_increment: int, power_target_increment: int,
save_action: SaveAction = SaveAction.SAVE_AND_APPLY, save_action: SaveAction = SaveAction.SAVE_ACTION_SAVE_AND_APPLY,
): ):
message = IncrementPowerTargetRequest()
message.power_target_increment.watt = power_target_increment
message.save_action = save_action
return await self.send_command( return await self.send_command(
"braiins.bos.v1.PerformanceService/IncrementPowerTarget", "braiins.bos.v1.PerformanceService/IncrementPowerTarget", message=message
save_action=save_action,
power_target_increment=power_target_increment,
) )
async def decrement_power_target( async def decrement_power_target(
self, self,
power_target_decrement: int, power_target_decrement: int,
save_action: SaveAction = SaveAction.SAVE_AND_APPLY, save_action: SaveAction = SaveAction.SAVE_ACTION_SAVE_AND_APPLY,
): ):
message = DecrementPowerTargetRequest()
message.power_target_decrement.watt = power_target_decrement
message.save_action = save_action
return await self.send_command( return await self.send_command(
"braiins.bos.v1.PerformanceService/DecrementPowerTarget", "braiins.bos.v1.PerformanceService/DecrementPowerTarget",
save_action=save_action, message=message,
power_target_decrement=power_target_decrement,
) )
async def set_default_hashrate_target( async def set_default_hashrate_target(
self, save_action: SaveAction = SaveAction.SAVE_AND_APPLY self, save_action: SaveAction = SaveAction.SAVE_ACTION_SAVE_AND_APPLY
): ):
message = SetDefaultHashrateTargetRequest()
message.save_action = save_action
return await self.send_command( return await self.send_command(
"braiins.bos.v1.PerformanceService/SetDefaultHashrateTarget", "braiins.bos.v1.PerformanceService/SetDefaultHashrateTarget",
save_action=save_action, message=message
) )
async def set_hashrate_target( async def set_hashrate_target(
self, hashrate_target: int, save_action: SaveAction = SaveAction.SAVE_AND_APPLY self,
hashrate_target: int,
save_action: SaveAction = SaveAction.SAVE_ACTION_SAVE_AND_APPLY,
): ):
message = SetHashrateTargetRequest()
message.hashrate_target.terahash_per_second = hashrate_target
message.save_action = save_action
return await self.send_command( return await self.send_command(
"braiins.bos.v1.PerformanceService/SetHashrateTarget", "braiins.bos.v1.PerformanceService/SetHashrateTarget",
save_action=save_action, message=message
hashrate_target=hashrate_target,
) )
async def increment_hashrate_target( async def increment_hashrate_target(
self, self,
hashrate_target_increment: int, hashrate_target_increment: int,
save_action: SaveAction = SaveAction.SAVE_AND_APPLY, save_action: SaveAction = SaveAction.SAVE_ACTION_SAVE_AND_APPLY,
): ):
message = IncrementHashrateTargetRequest()
message.hashrate_target_increment.terahash_per_second = hashrate_target_increment
message.save_action = save_action
return await self.send_command( return await self.send_command(
"braiins.bos.v1.PerformanceService/IncrementHashrateTarget", "braiins.bos.v1.PerformanceService/IncrementHashrateTarget",
save_action=save_action, message=message,
hashrate_target_increment=hashrate_target_increment,
) )
async def decrement_hashrate_target( async def decrement_hashrate_target(
self, self,
hashrate_target_decrement: int, hashrate_target_decrement: int,
save_action: SaveAction = SaveAction.SAVE_AND_APPLY, save_action: SaveAction = SaveAction.SAVE_ACTION_SAVE_AND_APPLY,
): ):
message = DecrementHashrateTargetRequest()
message.hashrate_target_decrement.terahash_per_second = hashrate_target_decrement
message.save_action = save_action
return await self.send_command( return await self.send_command(
"braiins.bos.v1.PerformanceService/DecrementHashrateTarget", "braiins.bos.v1.PerformanceService/DecrementHashrateTarget",
save_action=save_action, message=message,
hashrate_target_decrement=hashrate_target_decrement,
) )
async def set_dps(self): async def set_dps(self):
raise NotImplementedError raise NotImplementedError
return await self.send_command("braiins.bos.v1.PerformanceService/SetDPS") return await self.send_command("braiins.bos.v1.PerformanceService/SetDPS")
async def set_performance_mode( async def set_performance_mode(self):
self, raise NotImplementedError
power_target: int = None,
hashrate_target: float = None,
manual_config: ManualPerformanceMode = None,
):
config = PerformanceMode.create(
power_target=power_target,
hashrate_target=hashrate_target,
manual_configuration=manual_config,
)
return await self.send_command( return await self.send_command(
"braiins.bos.v1.PerformanceService/SetPerformanceMode", **config "braiins.bos.v1.PerformanceService/SetPerformanceMode"
) )
async def get_active_performance_mode(self): async def get_active_performance_mode(self):
@@ -527,21 +570,27 @@ class BOSMinerGRPCAPI:
async def enable_hashboards( async def enable_hashboards(
self, self,
hashboard_ids: List[str], hashboard_ids: List[str],
save_action: SaveAction = SaveAction.SAVE_AND_APPLY, save_action: SaveAction = SaveAction.SAVE_ACTION_SAVE_AND_APPLY,
): ):
message = EnableHashboardsRequest()
message.hashboard_ids[:] = hashboard_ids
message.save_action = save_action
return await self.send_command( return await self.send_command(
"braiins.bos.v1.MinerService/EnableHashboards", "braiins.bos.v1.MinerService/EnableHashboards",
hashboard_ids=hashboard_ids, message = message
save_action=save_action,
) )
async def disable_hashboards( async def disable_hashboards(
self, self,
hashboard_ids: List[str], hashboard_ids: List[str],
save_action: SaveAction = SaveAction.SAVE_AND_APPLY, save_action: SaveAction = SaveAction.SAVE_ACTION_SAVE_AND_APPLY,
): ):
message = DisableHashboardsRequest()
message.hashboard_ids[:] = hashboard_ids
message.save_action = save_action
return await self.send_command( return await self.send_command(
"braiins.bos.v1.MinerService/DisableHashboards", "braiins.bos.v1.MinerService/DisableHashboards",
hashboard_ids=hashboard_ids, message=message
save_action=save_action,
) )