chore: add debug logging

This commit is contained in:
Brian Berg 2020-07-12 23:25:38 +00:00
parent dc41e2e3ae
commit 42a30ce201
4 changed files with 26 additions and 8 deletions

View File

@ -84,6 +84,7 @@ async def async_setup(hass: HomeAssistant, config: Config):
# Accounts # Accounts
if balances_enabled: if balances_enabled:
_LOGGER.debug("Account balances enabled, fetching accounts...")
accounts_coordinator = AccountsDataUpdateCoordinator(hass, client) accounts_coordinator = AccountsDataUpdateCoordinator(hass, client)
await accounts_coordinator.async_refresh() await accounts_coordinator.async_refresh()
@ -95,6 +96,7 @@ async def async_setup(hass: HomeAssistant, config: Config):
# Payouts # Payouts
if payouts_enabled: if payouts_enabled:
_LOGGER.debug("Payouts enabled, fetching payouts data...")
payouts_coordinator = MiningPayoutsDataUpdateCoordinator(hass, client) payouts_coordinator = MiningPayoutsDataUpdateCoordinator(hass, client)
await payouts_coordinator.async_refresh() await payouts_coordinator.async_refresh()
@ -106,6 +108,7 @@ async def async_setup(hass: HomeAssistant, config: Config):
# Rigs # Rigs
if rigs_enabled or devices_enabled: if rigs_enabled or devices_enabled:
_LOGGER.debug("Rigs or devices enabled, fetching rigs...")
rigs_coordinator = MiningRigsDataUpdateCoordinator(hass, client) rigs_coordinator = MiningRigsDataUpdateCoordinator(hass, client)
await rigs_coordinator.async_refresh() await rigs_coordinator.async_refresh()

View File

@ -37,7 +37,6 @@ class BalanceSensor(Entity):
balance_type=BALANCE_TYPE_AVAILABLE, balance_type=BALANCE_TYPE_AVAILABLE,
): ):
"""Initialize the sensor""" """Initialize the sensor"""
_LOGGER.debug(f"Account Balance Sensor: {balance_type} {currency}")
self.coordinator = coordinator self.coordinator = coordinator
self.currency = currency self.currency = currency
self.organization_id = organization_id self.organization_id = organization_id

View File

@ -10,6 +10,7 @@ from hashlib import sha256
import hmac import hmac
import httpx import httpx
import json import json
import logging
import re import re
import sys import sys
from time import mktime from time import mktime
@ -17,6 +18,8 @@ import uuid
from .const import NICEHASH_API_URL from .const import NICEHASH_API_URL
_LOGGER = logging.getLogger(__name__)
def parse_device_name(raw_name): def parse_device_name(raw_name):
name = re.sub( name = re.sub(
@ -77,7 +80,7 @@ class Payout:
class NiceHashPublicClient: class NiceHashPublicClient:
async def get_exchange_rates(self): async def get_exchange_rates(self):
exchange_data = await self.request("GET", "/main/api/v2/exchangeRate/list") 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): async def request(self, method, path, query=None, body=None):
url = NICEHASH_API_URL + path url = NICEHASH_API_URL + path
@ -85,6 +88,8 @@ class NiceHashPublicClient:
if query is not None: if query is not None:
url += f"?{query}" url += f"?{query}"
_LOGGER.debug(url)
async with httpx.AsyncClient() as client: async with httpx.AsyncClient() as client:
if body: if body:
data = json.dumps(body) data = json.dumps(body)
@ -102,11 +107,10 @@ class NiceHashPublicClient:
class NiceHashPrivateClient: class NiceHashPrivateClient:
def __init__(self, organization_id, key, secret, verbose=False): def __init__(self, organization_id, key, secret):
self.organization_id = organization_id self.organization_id = organization_id
self.key = key self.key = key
self.secret = secret self.secret = secret
self.verbose = verbose
async def get_accounts(self): async def get_accounts(self):
return await self.request("GET", "/main/api/v2/accounting/accounts2") return await self.request("GET", "/main/api/v2/accounting/accounts2")
@ -149,10 +153,9 @@ class NiceHashPrivateClient:
url = NICEHASH_API_URL + path url = NICEHASH_API_URL + path
if query: if query:
url += "?" + query url += f"?{query}"
if self.verbose: _LOGGER.debug(url)
print(method, url)
if data: if data:
response = await client.request(method, url, data=data) response = await client.request(method, url, data=data)

View File

@ -73,6 +73,7 @@ async def async_setup_platform(
# Payout sensors # Payout sensors
if payouts_enabled: if payouts_enabled:
_LOGGER.debug("Payout sensors enabled")
payouts_coordinator = data.get("payouts_coordinator") payouts_coordinator = data.get("payouts_coordinator")
payout_sensors = create_payout_sensors(organization_id, payouts_coordinator) payout_sensors = create_payout_sensors(organization_id, payouts_coordinator)
async_add_entities(payout_sensors) async_add_entities(payout_sensors)
@ -82,17 +83,21 @@ async def async_setup_platform(
rigs_coordinator = data.get("rigs_coordinator") rigs_coordinator = data.get("rigs_coordinator")
rig_data = await client.get_mining_rigs() rig_data = await client.get_mining_rigs()
mining_rigs = rig_data.get("miningRigs") mining_rigs = rig_data.get("miningRigs")
_LOGGER.debug(f"Found {len(mining_rigs)} rigs")
if rigs_enabled: if rigs_enabled:
_LOGGER.debug("Rig sensors enabled")
rig_sensors = create_rig_sensors(mining_rigs, rigs_coordinator) rig_sensors = create_rig_sensors(mining_rigs, rigs_coordinator)
async_add_entities(rig_sensors, True) async_add_entities(rig_sensors, True)
if devices_enabled: if devices_enabled:
_LOGGER.debug("Device sensors enabled")
device_sensors = create_device_sensors(mining_rigs, rigs_coordinator) device_sensors = create_device_sensors(mining_rigs, rigs_coordinator)
async_add_entities(device_sensors, True) async_add_entities(device_sensors, True)
def create_balance_sensors(organization_id, currency, coordinator): def create_balance_sensors(organization_id, currency, coordinator):
_LOGGER.debug(f"Creating BTC account balance sensors")
balance_sensors = [ balance_sensors = [
BalanceSensor( BalanceSensor(
coordinator, coordinator,
@ -114,6 +119,7 @@ def create_balance_sensors(organization_id, currency, coordinator):
), ),
] ]
if currency == CURRENCY_USD or currency == CURRENCY_EUR: if currency == CURRENCY_USD or currency == CURRENCY_EUR:
_LOGGER.debug(f"Creating {currency} account balance sensors")
balance_sensors.append( balance_sensors.append(
BalanceSensor( BalanceSensor(
coordinator, coordinator,
@ -145,6 +151,7 @@ def create_balance_sensors(organization_id, currency, coordinator):
def create_payout_sensors(organization_id, coordinator): def create_payout_sensors(organization_id, coordinator):
_LOGGER.debug(f"Creating payout sensors")
payout_sensors = [] payout_sensors = []
payout_sensors.append(RecentMiningPayoutSensor(coordinator, organization_id)) payout_sensors.append(RecentMiningPayoutSensor(coordinator, organization_id))
@ -155,6 +162,7 @@ def create_rig_sensors(mining_rigs, coordinator):
rig_sensors = [] rig_sensors = []
for rig_data in mining_rigs: for rig_data in mining_rigs:
rig = MiningRig(rig_data) rig = MiningRig(rig_data)
_LOGGER.debug(f"Creating {rig.name} ({rig.id}) sensors")
rig_sensors.append(RigStatusSensor(coordinator, rig)) rig_sensors.append(RigStatusSensor(coordinator, rig))
rig_sensors.append(RigTemperatureSensor(coordinator, rig)) rig_sensors.append(RigTemperatureSensor(coordinator, rig))
rig_sensors.append(RigProfitabilitySensor(coordinator, rig)) rig_sensors.append(RigProfitabilitySensor(coordinator, rig))
@ -166,7 +174,12 @@ def create_device_sensors(mining_rigs, coordinator):
device_sensors = [] device_sensors = []
for rig_data in mining_rigs: for rig_data in mining_rigs:
rig = MiningRig(rig_data) 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(DeviceAlgorithmSensor(coordinator, rig, device))
device_sensors.append(DeviceSpeedSensor(coordinator, rig, device)) device_sensors.append(DeviceSpeedSensor(coordinator, rig, device))
device_sensors.append(DeviceStatusSensor(coordinator, rig, device)) device_sensors.append(DeviceStatusSensor(coordinator, rig, device))