diff --git a/custom_components/nicehash/const.py b/custom_components/nicehash/const.py index c64d29c..d3058be 100644 --- a/custom_components/nicehash/const.py +++ b/custom_components/nicehash/const.py @@ -77,3 +77,5 @@ DEVICE_LOAD = "device-load" DEVICE_RPM = "device-rpm" # Payout types PAYOUT_USER = "USER" +# Magic numbers +MAX_TWO_BYTES = 65536 diff --git a/custom_components/nicehash/nicehash.py b/custom_components/nicehash/nicehash.py index 7bf1e49..501a3b9 100644 --- a/custom_components/nicehash/nicehash.py +++ b/custom_components/nicehash/nicehash.py @@ -16,7 +16,7 @@ import sys from time import mktime import uuid -from .const import NICEHASH_API_URL +from .const import MAX_TWO_BYTES, NICEHASH_API_URL _LOGGER = logging.getLogger(__name__) @@ -45,7 +45,7 @@ class MiningRigDevice: self.id = data.get("id") self.name = parse_device_name(data.get("name")) self.status = data.get("status").get("description") - self.temperature = int(data.get("temperature")) + self.temperature = int(data.get("temperature")) % MAX_TWO_BYTES self.load = float(data.get("load")) self.rpm = float(data.get("revolutionsPerMinute")) self.speeds = data.get("speeds") @@ -60,11 +60,15 @@ class MiningRig: self.profitability = data.get("profitability") self.unpaid_amount = data.get("unpaidAmount") devices = data.get("devices") - self.num_devices = len(devices) - self.devices = dict() - for device_data in devices: - device = MiningRigDevice(device_data) - self.devices[f"{device.id}"] = device + if devices is not None: + self.num_devices = len(devices) + self.devices = dict() + for device_data in devices: + device = MiningRigDevice(device_data) + self.devices[f"{device.id}"] = device + else: + self.num_devices = 0 + self.devices = dict() def get_algorithms(self): algorithms = dict() diff --git a/custom_components/nicehash/rig_sensors.py b/custom_components/nicehash/rig_sensors.py index a32b613..0c9b196 100644 --- a/custom_components/nicehash/rig_sensors.py +++ b/custom_components/nicehash/rig_sensors.py @@ -104,7 +104,8 @@ class RigHighTemperatureSensor(RigSensor): for device in rig.devices.values(): if device.temperature > -1: self._temps.append(device.temperature) - self._highest_temp = max(self._temps) + if len(self._temps) > 0: + self._highest_temp = max(self._temps) return self._highest_temp @@ -160,7 +161,8 @@ class RigLowTemperatureSensor(RigSensor): for device in rig.devices.values(): if device.temperature > -1: self._temps.append(device.temperature) - self._lowest_temp = min(self._temps) + if len(self._temps) > 0: + self._lowest_temp = min(self._temps) return self._lowest_temp @@ -365,8 +367,6 @@ class RigSpeedSensor(RigSensor): self._algorithm = algo.name self._speed = algo.speed self._unit = algo.unit - print(self._algorithm) - print(self._speed) return self._speed diff --git a/custom_components/nicehash/sensor.py b/custom_components/nicehash/sensor.py index d15e184..3ad2ad5 100644 --- a/custom_components/nicehash/sensor.py +++ b/custom_components/nicehash/sensor.py @@ -161,7 +161,7 @@ def create_payout_sensors(organization_id, coordinator): return payout_sensors -def create_rig_sensors(mining_rigs, coordinator, algorithms=[]): +def create_rig_sensors(mining_rigs, coordinator): rig_sensors = [] for rig_data in mining_rigs: rig = MiningRig(rig_data)