feature: add is_mining for btminer, and fix some minor bugs.
This commit is contained in:
@@ -73,6 +73,11 @@ class BaseMinerAPI:
|
|||||||
# send the command
|
# send the command
|
||||||
data = await self._send_bytes(json.dumps(cmd).encode("utf-8"))
|
data = await self._send_bytes(json.dumps(cmd).encode("utf-8"))
|
||||||
|
|
||||||
|
if data == b"Socket connect failed: Connection refused\n":
|
||||||
|
if not ignore_errors:
|
||||||
|
raise APIError(data.decode("utf-8"))
|
||||||
|
return {}
|
||||||
|
|
||||||
data = self._load_api_data(data)
|
data = self._load_api_data(data)
|
||||||
|
|
||||||
# check for if the user wants to allow errors to return
|
# check for if the user wants to allow errors to return
|
||||||
|
|||||||
@@ -616,3 +616,22 @@ class BTMiner(BaseMiner):
|
|||||||
|
|
||||||
async def set_hostname(self, hostname: str):
|
async def set_hostname(self, hostname: str):
|
||||||
await self.api.set_hostname(hostname)
|
await self.api.set_hostname(hostname)
|
||||||
|
|
||||||
|
async def is_mining(self, api_status: dict = None) -> Optional[bool]:
|
||||||
|
if not api_status:
|
||||||
|
try:
|
||||||
|
api_status = await self.api.status()
|
||||||
|
except APIError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
if api_status:
|
||||||
|
try:
|
||||||
|
if api_status["Msg"].get("btmineroff"):
|
||||||
|
try:
|
||||||
|
await self.api.devdetails()
|
||||||
|
except APIError:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
return True if api_status["Msg"]["mineroff"] == "false" else False
|
||||||
|
except LookupError:
|
||||||
|
pass
|
||||||
|
|||||||
@@ -346,7 +346,7 @@ class BaseMiner(ABC):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
async def is_mining(self, *args, **kwargs) -> Optional[bool]:
|
async def is_mining(self, *args, **kwargs) -> Optional[bool]:
|
||||||
"""Check whether the miner is mining
|
"""Check whether the miner is mining.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
A boolean value representing if the miner is mining.
|
A boolean value representing if the miner is mining.
|
||||||
|
|||||||
@@ -453,7 +453,6 @@ class MinerFactory:
|
|||||||
text, resp = await concurrent_get_first_result(
|
text, resp = await concurrent_get_first_result(
|
||||||
tasks, lambda x: x[0] is not None
|
tasks, lambda x: x[0] is not None
|
||||||
)
|
)
|
||||||
|
|
||||||
if text is not None:
|
if text is not None:
|
||||||
return self._parse_web_type(text, resp)
|
return self._parse_web_type(text, resp)
|
||||||
|
|
||||||
@@ -462,7 +461,7 @@ class MinerFactory:
|
|||||||
session: aiohttp.ClientSession, url: str
|
session: aiohttp.ClientSession, url: str
|
||||||
) -> Tuple[Optional[str], Optional[aiohttp.ClientResponse]]:
|
) -> Tuple[Optional[str], Optional[aiohttp.ClientResponse]]:
|
||||||
try:
|
try:
|
||||||
resp = await session.get(url)
|
resp = await session.get(url, allow_redirects=False)
|
||||||
return await resp.text(), resp
|
return await resp.text(), resp
|
||||||
except (aiohttp.ClientError, asyncio.TimeoutError):
|
except (aiohttp.ClientError, asyncio.TimeoutError):
|
||||||
pass
|
pass
|
||||||
@@ -620,6 +619,8 @@ class MinerFactory:
|
|||||||
return
|
return
|
||||||
except (ConnectionError, OSError):
|
except (ConnectionError, OSError):
|
||||||
return
|
return
|
||||||
|
if data == b"Socket connect failed: Connection refused\n":
|
||||||
|
return
|
||||||
|
|
||||||
data = await self._fix_api_data(data)
|
data = await self._fix_api_data(data)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user