From 9672dd6873c43d5fdbc4cb63d2d1784a770575e3 Mon Sep 17 00:00:00 2001 From: UpstreamData Date: Wed, 2 Nov 2022 10:32:33 -0600 Subject: [PATCH] bug: fix warnings when new whatsminer API commands don't exist. --- pyasic/API/__init__.py | 10 +++++----- pyasic/API/bmminer.py | 4 ++-- pyasic/API/btminer.py | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/pyasic/API/__init__.py b/pyasic/API/__init__.py index e8878833..10abbae6 100644 --- a/pyasic/API/__init__.py +++ b/pyasic/API/__init__.py @@ -82,7 +82,7 @@ If you are sure you want to use this command please use API.send_command("{comma # make sure we can actually run each command, otherwise they will fail commands = self._check_commands(*commands) # standard multicommand format is "command1+command2" - # doesnt work for S19 which uses the backup _x19_multicommand + # doesn't work for S19 which uses the backup _x19_multicommand command = "+".join(commands) try: data = await self.send_command(command) @@ -129,15 +129,15 @@ If you are sure you want to use this command please use API.send_command("{comma command: Union[str, bytes], parameters: Union[str, int, bool] = None, ignore_errors: bool = False, - x19_command: bool = False, + allow_warning: bool = True, ) -> dict: """Send an API command to the miner and return the result. Parameters: command: The command to sent to the miner. parameters: Any additional parameters to be sent with the command. - ignore_errors: Whether or not to raise APIError when the command returns an error. - x19_command: Whether this is a command for an x19 that may be an issue (such as a "+" delimited multicommand) + ignore_errors: Whether to raise APIError when the command returns an error. + allow_warning: Whether to warn if the command fails. Returns: The return data from the API command parsed from JSON into a dict. @@ -157,7 +157,7 @@ If you are sure you want to use this command please use API.send_command("{comma # validate the command succeeded validation = self._validate_command_output(data) if not validation[0]: - if not x19_command: + if allow_warning: logging.warning( f"{self.ip}: API Command Error: {command}: {validation[1]}" ) diff --git a/pyasic/API/bmminer.py b/pyasic/API/bmminer.py index 0221af5d..c18b8072 100644 --- a/pyasic/API/bmminer.py +++ b/pyasic/API/bmminer.py @@ -48,7 +48,7 @@ class BMMinerAPI(BaseMinerAPI): # doesnt work for S19 which uses the backup _x19_multicommand command = "+".join(commands) try: - data = await self.send_command(command, x19_command=ignore_x19_error) + data = await self.send_command(command, allow_warning=ignore_x19_error) except APIError: logging.debug(f"{self.ip}: Handling X19 multicommand.") data = await self._x19_multicommand(*command.split("+")) @@ -62,7 +62,7 @@ class BMMinerAPI(BaseMinerAPI): # send all commands individually for cmd in commands: data[cmd] = [] - data[cmd].append(await self.send_command(cmd, x19_command=True)) + data[cmd].append(await self.send_command(cmd, allow_warning=True)) except APIError as e: raise APIError(e) except Exception as e: diff --git a/pyasic/API/btminer.py b/pyasic/API/btminer.py index f8ce32c8..49ed1bbd 100644 --- a/pyasic/API/btminer.py +++ b/pyasic/API/btminer.py @@ -767,7 +767,7 @@ class BTMinerAPI(BaseMinerAPI): General miner info. """ - return await self.send_command("get_miner_info") + return await self.send_command("get_miner_info", allow_warning=False) async def get_error_code(self) -> dict: """Get a list of error codes from the miner. @@ -781,4 +781,4 @@ class BTMinerAPI(BaseMinerAPI): A list of error codes on the miner. """ - return await self.send_command("get_error_code") + return await self.send_command("get_error_code", allow_warning=False)