add light functions for btminer, and add a way to reset to admin password for btminers to allow unlocking of priviledged API.
This commit is contained in:
@@ -183,7 +183,7 @@ class BTMinerAPI(BaseMinerAPI):
|
|||||||
pwd: str = PyasicSettings().global_whatsminer_password,
|
pwd: str = PyasicSettings().global_whatsminer_password,
|
||||||
):
|
):
|
||||||
super().__init__(ip, port)
|
super().__init__(ip, port)
|
||||||
self.admin_pwd = pwd
|
self.pwd = pwd
|
||||||
self.current_token = None
|
self.current_token = None
|
||||||
|
|
||||||
async def send_command(
|
async def send_command(
|
||||||
@@ -260,7 +260,7 @@ class BTMinerAPI(BaseMinerAPI):
|
|||||||
data = await self.send_command("get_token")
|
data = await self.send_command("get_token")
|
||||||
|
|
||||||
# encrypt the admin password with the salt
|
# encrypt the admin password with the salt
|
||||||
pwd = _crypt(self.admin_pwd, "$1$" + data["Msg"]["salt"] + "$")
|
pwd = _crypt(self.pwd, "$1$" + data["Msg"]["salt"] + "$")
|
||||||
pwd = pwd.split("$")
|
pwd = pwd.split("$")
|
||||||
|
|
||||||
# take the 4th item from the pwd split
|
# take the 4th item from the pwd split
|
||||||
@@ -437,6 +437,7 @@ class BTMinerAPI(BaseMinerAPI):
|
|||||||
|
|
||||||
async def set_led(
|
async def set_led(
|
||||||
self,
|
self,
|
||||||
|
auto: bool = True,
|
||||||
color: str = "red",
|
color: str = "red",
|
||||||
period: int = 2000,
|
period: int = 2000,
|
||||||
duration: int = 1000,
|
duration: int = 1000,
|
||||||
@@ -450,6 +451,7 @@ class BTMinerAPI(BaseMinerAPI):
|
|||||||
changing the password of the miner using the Whatsminer tool.
|
changing the password of the miner using the Whatsminer tool.
|
||||||
|
|
||||||
Parameters:
|
Parameters:
|
||||||
|
auto: Whether or not to reset the LED to auto mode.
|
||||||
color: The LED color to set, either 'red' or 'green'.
|
color: The LED color to set, either 'red' or 'green'.
|
||||||
period: The flash cycle in ms.
|
period: The flash cycle in ms.
|
||||||
duration: LED on time in the cycle in ms.
|
duration: LED on time in the cycle in ms.
|
||||||
@@ -459,16 +461,19 @@ class BTMinerAPI(BaseMinerAPI):
|
|||||||
A reply informing of the status of setting the LED.
|
A reply informing of the status of setting the LED.
|
||||||
</details>
|
</details>
|
||||||
"""
|
"""
|
||||||
command = {
|
if not auto:
|
||||||
"cmd": "set_led",
|
command = {
|
||||||
"color": color,
|
"cmd": "set_led",
|
||||||
"period": period,
|
"color": color,
|
||||||
"duration": duration,
|
"period": period,
|
||||||
"start": start,
|
"duration": duration,
|
||||||
}
|
"start": start,
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
command = {"cmd": "set_led", "param": "auto"}
|
||||||
token_data = await self.get_token()
|
token_data = await self.get_token()
|
||||||
enc_command = create_privileged_cmd(token_data, command)
|
enc_command = create_privileged_cmd(token_data, command)
|
||||||
return await self.send_command(enc_command)
|
return await self.send_command(enc_command, ignore_errors=True)
|
||||||
|
|
||||||
async def set_low_power(self) -> dict:
|
async def set_low_power(self) -> dict:
|
||||||
"""Set low power mode on the miner using the API.
|
"""Set low power mode on the miner using the API.
|
||||||
@@ -542,6 +547,7 @@ class BTMinerAPI(BaseMinerAPI):
|
|||||||
|
|
||||||
A reply informing of the status of setting the password.
|
A reply informing of the status of setting the password.
|
||||||
"""
|
"""
|
||||||
|
self.pwd = old_pwd
|
||||||
# check if password length is greater than 8 bytes
|
# check if password length is greater than 8 bytes
|
||||||
if len(new_pwd.encode("utf-8")) > 8:
|
if len(new_pwd.encode("utf-8")) > 8:
|
||||||
raise APIError(
|
raise APIError(
|
||||||
@@ -551,7 +557,12 @@ class BTMinerAPI(BaseMinerAPI):
|
|||||||
command = {"cmd": "update_pwd", "old": old_pwd, "new": new_pwd}
|
command = {"cmd": "update_pwd", "old": old_pwd, "new": new_pwd}
|
||||||
token_data = await self.get_token()
|
token_data = await self.get_token()
|
||||||
enc_command = create_privileged_cmd(token_data, command)
|
enc_command = create_privileged_cmd(token_data, command)
|
||||||
return await self.send_command(enc_command)
|
try:
|
||||||
|
data = await self.send_command(enc_command)
|
||||||
|
except APIError as e:
|
||||||
|
raise e
|
||||||
|
self.pwd = new_pwd
|
||||||
|
return data
|
||||||
|
|
||||||
async def set_target_freq(self, percent: int) -> dict:
|
async def set_target_freq(self, percent: int) -> dict:
|
||||||
"""Update the target frequency.
|
"""Update the target frequency.
|
||||||
|
|||||||
@@ -72,11 +72,11 @@ class BOSMiner(BaseMiner):
|
|||||||
async def fault_light_on(self) -> bool:
|
async def fault_light_on(self) -> bool:
|
||||||
"""Sends command to turn on fault light on the miner."""
|
"""Sends command to turn on fault light on the miner."""
|
||||||
logging.debug(f"{self}: Sending fault_light on command.")
|
logging.debug(f"{self}: Sending fault_light on command.")
|
||||||
self.light = True
|
|
||||||
_ret = await self.send_ssh_command("miner fault_light on")
|
_ret = await self.send_ssh_command("miner fault_light on")
|
||||||
logging.debug(f"{self}: fault_light on command completed.")
|
logging.debug(f"{self}: fault_light on command completed.")
|
||||||
if isinstance(_ret, str):
|
if isinstance(_ret, str):
|
||||||
return True
|
self.light = True
|
||||||
|
return self.light
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def fault_light_off(self) -> bool:
|
async def fault_light_off(self) -> bool:
|
||||||
@@ -86,6 +86,7 @@ class BOSMiner(BaseMiner):
|
|||||||
_ret = await self.send_ssh_command("miner fault_light off")
|
_ret = await self.send_ssh_command("miner fault_light off")
|
||||||
logging.debug(f"{self}: fault_light off command completed.")
|
logging.debug(f"{self}: fault_light off command completed.")
|
||||||
if isinstance(_ret, str):
|
if isinstance(_ret, str):
|
||||||
|
self.light = False
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|||||||
@@ -100,15 +100,57 @@ class BTMiner(BaseMiner):
|
|||||||
|
|
||||||
return str(mac).upper()
|
return str(mac).upper()
|
||||||
|
|
||||||
|
async def _reset_api_pwd_to_admin(self, pwd: str):
|
||||||
|
try:
|
||||||
|
data = await self.api.update_pwd(pwd, "admin")
|
||||||
|
except APIError:
|
||||||
|
return False
|
||||||
|
if data:
|
||||||
|
if "Code" in data.keys():
|
||||||
|
if data["Code"] == 131:
|
||||||
|
return True
|
||||||
|
print(data)
|
||||||
|
return False
|
||||||
|
|
||||||
async def check_light(self) -> bool:
|
async def check_light(self) -> bool:
|
||||||
if not self.light:
|
data = None
|
||||||
self.light = False
|
|
||||||
|
try:
|
||||||
|
data = await self.api.get_miner_info()
|
||||||
|
except APIError:
|
||||||
|
if not self.light:
|
||||||
|
self.light = False
|
||||||
|
if data:
|
||||||
|
if "Msg" in data.keys():
|
||||||
|
if "ledstat" in data["Msg"].keys():
|
||||||
|
if not data["Msg"]["ledstat"] == "auto":
|
||||||
|
self.light = True
|
||||||
|
if data["Msg"]["ledstat"] == "auto":
|
||||||
|
self.light = False
|
||||||
return self.light
|
return self.light
|
||||||
|
|
||||||
async def fault_light_off(self) -> bool:
|
async def fault_light_off(self) -> bool:
|
||||||
|
try:
|
||||||
|
data = await self.api.set_led(auto=True)
|
||||||
|
except APIError:
|
||||||
|
return False
|
||||||
|
if data:
|
||||||
|
if "Code" in data.keys():
|
||||||
|
if data["Code"] == 131:
|
||||||
|
self.light = False
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def fault_light_on(self) -> bool:
|
async def fault_light_on(self) -> bool:
|
||||||
|
try:
|
||||||
|
data = await self.api.set_led(auto=False)
|
||||||
|
except APIError:
|
||||||
|
return False
|
||||||
|
if data:
|
||||||
|
if "Code" in data.keys():
|
||||||
|
if data["Code"] == 131:
|
||||||
|
self.light = True
|
||||||
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def get_errors(self) -> list:
|
async def get_errors(self) -> list:
|
||||||
|
|||||||
Reference in New Issue
Block a user