Add support for the grpc set_performance_mode command.
This commit is contained in:
@@ -13,9 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and -
|
# See the License for the specific language governing permissions and -
|
||||||
# limitations under the License. -
|
# limitations under the License. -
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
import asyncio
|
|
||||||
import json
|
import json
|
||||||
import warnings
|
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
@@ -30,13 +28,11 @@ 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.performance import (
|
||||||
class SaveAction(Enum):
|
ManualPerformanceMode,
|
||||||
UNSPECIFIED = "SaveAction.SAVE_ACTION_UNSPECIFIED"
|
PerformanceMode,
|
||||||
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"
|
|
||||||
|
|
||||||
|
|
||||||
class BOSMinerWebAPI(BaseWebAPI):
|
class BOSMinerWebAPI(BaseWebAPI):
|
||||||
@@ -464,10 +460,20 @@ class BOSMinerGRPCAPI:
|
|||||||
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(self):
|
async def set_performance_mode(
|
||||||
raise NotImplementedError
|
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(
|
return await self.send_command(
|
||||||
"braiins.bos.v1.PerformanceService/SetPerformanceMode"
|
"braiins.bos.v1.PerformanceService/SetPerformanceMode", **config
|
||||||
)
|
)
|
||||||
|
|
||||||
async def get_active_performance_mode(self):
|
async def get_active_performance_mode(self):
|
||||||
|
|||||||
@@ -13,6 +13,8 @@
|
|||||||
# See the License for the specific language governing permissions and -
|
# See the License for the specific language governing permissions and -
|
||||||
# limitations under the License. -
|
# limitations under the License. -
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
from .bos import version_pb2
|
from .bos import version_pb2
|
||||||
from .bos.v1 import (
|
from .bos.v1 import (
|
||||||
actions_pb2,
|
actions_pb2,
|
||||||
|
|||||||
15
pyasic/web/bosminer/proto/bos/__init__.py
Normal file
15
pyasic/web/bosminer/proto/bos/__init__.py
Normal 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. -
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
15
pyasic/web/bosminer/proto/bos/v1/__init__.py
Normal file
15
pyasic/web/bosminer/proto/bos/v1/__init__.py
Normal 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. -
|
||||||
|
# ------------------------------------------------------------------------------
|
||||||
23
pyasic/web/bosminer/proto/bos/v1/actions.py
Normal file
23
pyasic/web/bosminer/proto/bos/v1/actions.py
Normal 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"
|
||||||
110
pyasic/web/bosminer/proto/bos/v1/performance.py
Normal file
110
pyasic/web/bosminer/proto/bos/v1/performance.py
Normal 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)
|
||||||
Reference in New Issue
Block a user