Add support for the grpc set_performance_mode command.

This commit is contained in:
UpstreamData
2023-11-07 08:54:06 -07:00
parent 717b9421dd
commit 36e76c6f41
6 changed files with 183 additions and 12 deletions

View File

@@ -13,9 +13,7 @@
# See the License for the specific language governing permissions and -
# limitations under the License. -
# ------------------------------------------------------------------------------
import asyncio
import json
import warnings
from datetime import datetime, timedelta
from enum import Enum
from typing import List, Union
@@ -30,13 +28,11 @@ from pyasic.web.bosminer.proto import (
get_auth_service_descriptors,
get_service_descriptors,
)
class SaveAction(Enum):
UNSPECIFIED = "SaveAction.SAVE_ACTION_UNSPECIFIED"
SAVE = "SaveAction.SAVE_ACTION_SAVE"
SAVE_AND_APPLY = "SaveAction.SAVE_ACTION_SAVE_AND_APPLY"
SAVE_AND_FORCE_APPLY = "SaveAction.SAVE_ACTION_SAVE_AND_FORCE_APPLY"
from pyasic.web.bosminer.proto.bos.v1.actions import SaveAction
from pyasic.web.bosminer.proto.bos.v1.performance import (
ManualPerformanceMode,
PerformanceMode,
)
class BOSMinerWebAPI(BaseWebAPI):
@@ -464,10 +460,20 @@ class BOSMinerGRPCAPI:
raise NotImplementedError
return await self.send_command("braiins.bos.v1.PerformanceService/SetDPS")
async def set_performance_mode(self):
raise NotImplementedError
async def set_performance_mode(
self,
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(
"braiins.bos.v1.PerformanceService/SetPerformanceMode"
"braiins.bos.v1.PerformanceService/SetPerformanceMode", **config
)
async def get_active_performance_mode(self):

View File

@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and -
# limitations under the License. -
# ------------------------------------------------------------------------------
from __future__ import annotations
from .bos import version_pb2
from .bos.v1 import (
actions_pb2,

View File

@@ -0,0 +1,15 @@
# ------------------------------------------------------------------------------
# Copyright 2022 Upstream Data Inc -
# -
# Licensed under the Apache License, Version 2.0 (the "License"); -
# you may not use this file except in compliance with the License. -
# You may obtain a copy of the License at -
# -
# http://www.apache.org/licenses/LICENSE-2.0 -
# -
# Unless required by applicable law or agreed to in writing, software -
# distributed under the License is distributed on an "AS IS" BASIS, -
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -
# See the License for the specific language governing permissions and -
# limitations under the License. -
# ------------------------------------------------------------------------------

View File

@@ -0,0 +1,15 @@
# ------------------------------------------------------------------------------
# Copyright 2022 Upstream Data Inc -
# -
# Licensed under the Apache License, Version 2.0 (the "License"); -
# you may not use this file except in compliance with the License. -
# You may obtain a copy of the License at -
# -
# http://www.apache.org/licenses/LICENSE-2.0 -
# -
# Unless required by applicable law or agreed to in writing, software -
# distributed under the License is distributed on an "AS IS" BASIS, -
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -
# See the License for the specific language governing permissions and -
# limitations under the License. -
# ------------------------------------------------------------------------------

View File

@@ -0,0 +1,23 @@
# ------------------------------------------------------------------------------
# Copyright 2022 Upstream Data Inc -
# -
# Licensed under the Apache License, Version 2.0 (the "License"); -
# you may not use this file except in compliance with the License. -
# You may obtain a copy of the License at -
# -
# http://www.apache.org/licenses/LICENSE-2.0 -
# -
# Unless required by applicable law or agreed to in writing, software -
# distributed under the License is distributed on an "AS IS" BASIS, -
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -
# See the License for the specific language governing permissions and -
# limitations under the License. -
# ------------------------------------------------------------------------------
from enum import Enum
class SaveAction(Enum):
UNSPECIFIED = "SaveAction.SAVE_ACTION_UNSPECIFIED"
SAVE = "SaveAction.SAVE_ACTION_SAVE"
SAVE_AND_APPLY = "SaveAction.SAVE_ACTION_SAVE_AND_APPLY"
SAVE_AND_FORCE_APPLY = "SaveAction.SAVE_ACTION_SAVE_AND_FORCE_APPLY"

View File

@@ -0,0 +1,110 @@
# ------------------------------------------------------------------------------
# Copyright 2022 Upstream Data Inc -
# -
# Licensed under the Apache License, Version 2.0 (the "License"); -
# you may not use this file except in compliance with the License. -
# You may obtain a copy of the License at -
# -
# http://www.apache.org/licenses/LICENSE-2.0 -
# -
# Unless required by applicable law or agreed to in writing, software -
# distributed under the License is distributed on an "AS IS" BASIS, -
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -
# See the License for the specific language governing permissions and -
# limitations under the License. -
# ------------------------------------------------------------------------------
from dataclasses import asdict, dataclass
from typing import Union
@dataclass
class Frequency:
hertz: float
@dataclass
class Voltage:
volt: float
@dataclass
class Power:
watt: int
@dataclass
class TeraHashrate:
terahash_per_second: float
@dataclass
class HashboardPerformanceSettings:
id: str
frequency: Frequency
voltage: Voltage
@dataclass
class ManualPerformanceMode:
global_frequency: Frequency
global_voltage: Voltage
hashboards: list[HashboardPerformanceSettings]
@dataclass
class PowerTargetMode:
power_target: Power
@dataclass
class HashrateTargetMode:
hashrate_target: TeraHashrate
@dataclass
class TunerPerformanceMode:
target: Union[PowerTargetMode, HashrateTargetMode]
@dataclass
class PerformanceMode:
mode: Union[ManualPerformanceMode, TunerPerformanceMode]
@classmethod
def create(
cls,
power_target: int = None,
hashrate_target: float = None,
manual_configuration: ManualPerformanceMode = None,
):
provided_args = [power_target, hashrate_target, manual_configuration]
if sum(arg is not None for arg in provided_args) > 1:
raise ValueError(
"More than one keyword argument provided. Please use only power target, hashrate target, or manual config."
)
elif sum(arg is not None for arg in provided_args) < 1:
raise ValueError(
"Please pass one of power target, hashrate target, or manual config."
)
if power_target is not None:
return cls(
mode=TunerPerformanceMode(
target=PowerTargetMode(power_target=Power(watt=power_target))
)
)
elif hashrate_target is not None:
return cls(
mode=TunerPerformanceMode(
target=HashrateTargetMode(
hashrate_target=TeraHashrate(
terahash_per_second=hashrate_target
)
)
)
)
elif manual_configuration is not None:
return cls(mode=manual_configuration)
def as_dict(self):
return asdict(self)