chore: add debug logging
This commit is contained in:
parent
dc41e2e3ae
commit
42a30ce201
@ -84,6 +84,7 @@ async def async_setup(hass: HomeAssistant, config: Config):
|
||||
|
||||
# Accounts
|
||||
if balances_enabled:
|
||||
_LOGGER.debug("Account balances enabled, fetching accounts...")
|
||||
accounts_coordinator = AccountsDataUpdateCoordinator(hass, client)
|
||||
await accounts_coordinator.async_refresh()
|
||||
|
||||
@ -95,6 +96,7 @@ async def async_setup(hass: HomeAssistant, config: Config):
|
||||
|
||||
# Payouts
|
||||
if payouts_enabled:
|
||||
_LOGGER.debug("Payouts enabled, fetching payouts data...")
|
||||
payouts_coordinator = MiningPayoutsDataUpdateCoordinator(hass, client)
|
||||
await payouts_coordinator.async_refresh()
|
||||
|
||||
@ -106,6 +108,7 @@ async def async_setup(hass: HomeAssistant, config: Config):
|
||||
|
||||
# Rigs
|
||||
if rigs_enabled or devices_enabled:
|
||||
_LOGGER.debug("Rigs or devices enabled, fetching rigs...")
|
||||
rigs_coordinator = MiningRigsDataUpdateCoordinator(hass, client)
|
||||
await rigs_coordinator.async_refresh()
|
||||
|
||||
|
@ -37,7 +37,6 @@ class BalanceSensor(Entity):
|
||||
balance_type=BALANCE_TYPE_AVAILABLE,
|
||||
):
|
||||
"""Initialize the sensor"""
|
||||
_LOGGER.debug(f"Account Balance Sensor: {balance_type} {currency}")
|
||||
self.coordinator = coordinator
|
||||
self.currency = currency
|
||||
self.organization_id = organization_id
|
||||
|
@ -10,6 +10,7 @@ from hashlib import sha256
|
||||
import hmac
|
||||
import httpx
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
import sys
|
||||
from time import mktime
|
||||
@ -17,6 +18,8 @@ import uuid
|
||||
|
||||
from .const import NICEHASH_API_URL
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def parse_device_name(raw_name):
|
||||
name = re.sub(
|
||||
@ -77,7 +80,7 @@ class Payout:
|
||||
class NiceHashPublicClient:
|
||||
async def get_exchange_rates(self):
|
||||
exchange_data = await self.request("GET", "/main/api/v2/exchangeRate/list")
|
||||
return exchange_data["list"]
|
||||
return exchange_data.get("list")
|
||||
|
||||
async def request(self, method, path, query=None, body=None):
|
||||
url = NICEHASH_API_URL + path
|
||||
@ -85,6 +88,8 @@ class NiceHashPublicClient:
|
||||
if query is not None:
|
||||
url += f"?{query}"
|
||||
|
||||
_LOGGER.debug(url)
|
||||
|
||||
async with httpx.AsyncClient() as client:
|
||||
if body:
|
||||
data = json.dumps(body)
|
||||
@ -102,11 +107,10 @@ class NiceHashPublicClient:
|
||||
|
||||
|
||||
class NiceHashPrivateClient:
|
||||
def __init__(self, organization_id, key, secret, verbose=False):
|
||||
def __init__(self, organization_id, key, secret):
|
||||
self.organization_id = organization_id
|
||||
self.key = key
|
||||
self.secret = secret
|
||||
self.verbose = verbose
|
||||
|
||||
async def get_accounts(self):
|
||||
return await self.request("GET", "/main/api/v2/accounting/accounts2")
|
||||
@ -149,10 +153,9 @@ class NiceHashPrivateClient:
|
||||
|
||||
url = NICEHASH_API_URL + path
|
||||
if query:
|
||||
url += "?" + query
|
||||
url += f"?{query}"
|
||||
|
||||
if self.verbose:
|
||||
print(method, url)
|
||||
_LOGGER.debug(url)
|
||||
|
||||
if data:
|
||||
response = await client.request(method, url, data=data)
|
||||
|
@ -73,6 +73,7 @@ async def async_setup_platform(
|
||||
|
||||
# Payout sensors
|
||||
if payouts_enabled:
|
||||
_LOGGER.debug("Payout sensors enabled")
|
||||
payouts_coordinator = data.get("payouts_coordinator")
|
||||
payout_sensors = create_payout_sensors(organization_id, payouts_coordinator)
|
||||
async_add_entities(payout_sensors)
|
||||
@ -82,17 +83,21 @@ async def async_setup_platform(
|
||||
rigs_coordinator = data.get("rigs_coordinator")
|
||||
rig_data = await client.get_mining_rigs()
|
||||
mining_rigs = rig_data.get("miningRigs")
|
||||
_LOGGER.debug(f"Found {len(mining_rigs)} rigs")
|
||||
|
||||
if rigs_enabled:
|
||||
_LOGGER.debug("Rig sensors enabled")
|
||||
rig_sensors = create_rig_sensors(mining_rigs, rigs_coordinator)
|
||||
async_add_entities(rig_sensors, True)
|
||||
|
||||
if devices_enabled:
|
||||
_LOGGER.debug("Device sensors enabled")
|
||||
device_sensors = create_device_sensors(mining_rigs, rigs_coordinator)
|
||||
async_add_entities(device_sensors, True)
|
||||
|
||||
|
||||
def create_balance_sensors(organization_id, currency, coordinator):
|
||||
_LOGGER.debug(f"Creating BTC account balance sensors")
|
||||
balance_sensors = [
|
||||
BalanceSensor(
|
||||
coordinator,
|
||||
@ -114,6 +119,7 @@ def create_balance_sensors(organization_id, currency, coordinator):
|
||||
),
|
||||
]
|
||||
if currency == CURRENCY_USD or currency == CURRENCY_EUR:
|
||||
_LOGGER.debug(f"Creating {currency} account balance sensors")
|
||||
balance_sensors.append(
|
||||
BalanceSensor(
|
||||
coordinator,
|
||||
@ -145,6 +151,7 @@ def create_balance_sensors(organization_id, currency, coordinator):
|
||||
|
||||
|
||||
def create_payout_sensors(organization_id, coordinator):
|
||||
_LOGGER.debug(f"Creating payout sensors")
|
||||
payout_sensors = []
|
||||
payout_sensors.append(RecentMiningPayoutSensor(coordinator, organization_id))
|
||||
|
||||
@ -155,6 +162,7 @@ def create_rig_sensors(mining_rigs, coordinator):
|
||||
rig_sensors = []
|
||||
for rig_data in mining_rigs:
|
||||
rig = MiningRig(rig_data)
|
||||
_LOGGER.debug(f"Creating {rig.name} ({rig.id}) sensors")
|
||||
rig_sensors.append(RigStatusSensor(coordinator, rig))
|
||||
rig_sensors.append(RigTemperatureSensor(coordinator, rig))
|
||||
rig_sensors.append(RigProfitabilitySensor(coordinator, rig))
|
||||
@ -166,7 +174,12 @@ def create_device_sensors(mining_rigs, coordinator):
|
||||
device_sensors = []
|
||||
for rig_data in mining_rigs:
|
||||
rig = MiningRig(rig_data)
|
||||
for device in rig.devices.values():
|
||||
devices = rig.devices.values()
|
||||
_LOGGER.debug(
|
||||
f"Found {len(devices)} device sensor(s) for {rig.name} ({rig.id})"
|
||||
)
|
||||
for device in devices:
|
||||
_LOGGER.debug(f"Creating {device.name} ({device.id}) sensors")
|
||||
device_sensors.append(DeviceAlgorithmSensor(coordinator, rig, device))
|
||||
device_sensors.append(DeviceSpeedSensor(coordinator, rig, device))
|
||||
device_sensors.append(DeviceStatusSensor(coordinator, rig, device))
|
||||
|
Loading…
Reference in New Issue
Block a user