From b19097164b101fb0cb6a0fafaeee7b6a711ae19b Mon Sep 17 00:00:00 2001 From: Pascal Berski Date: Mon, 27 Dec 2021 01:23:34 +0100 Subject: [PATCH 1/4] added icon power --- custom_components/nicehash/const.py | 1 + 1 file changed, 1 insertion(+) diff --git a/custom_components/nicehash/const.py b/custom_components/nicehash/const.py index d3058be..fb4c2c6 100644 --- a/custom_components/nicehash/const.py +++ b/custom_components/nicehash/const.py @@ -19,6 +19,7 @@ ICON_PULSE = "mdi:pulse" ICON_THERMOMETER = "mdi:thermometer" ICON_SPEEDOMETER = "mdi:speedometer" +ICON_POWER = "mdi:power-plug" # Platforms SENSOR = "sensor" From 0846477f1fa2e23a98f27ce474eef5e8bd0799d8 Mon Sep 17 00:00:00 2001 From: Pascal Berski Date: Mon, 27 Dec 2021 01:24:31 +0100 Subject: [PATCH 2/4] added class DevicePowerSensor --- custom_components/nicehash/device_sensors.py | 46 ++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/custom_components/nicehash/device_sensors.py b/custom_components/nicehash/device_sensors.py index b40b28f..d23583a 100644 --- a/custom_components/nicehash/device_sensors.py +++ b/custom_components/nicehash/device_sensors.py @@ -17,6 +17,7 @@ ICON_PULSE, ICON_THERMOMETER, ICON_SPEEDOMETER, + ICON_POWER, NICEHASH_ATTRIBUTION, ) from .coordinators import MiningRigsDataUpdateCoordinator @@ -381,3 +382,48 @@ def device_state_attributes(self): "rig": self._rig_name, } +class DevicePowerSensor(DeviceSensor): + """ + Displays power of a mining rig device + """ + + @property + def name(self): + """Sensor name""" + return f"{self._device_name} Power" + + @property + def unique_id(self): + """Unique entity id""" + return f"{self._device_id}:power" + + @property + def state(self): + """Sensor state""" + device = self._get_device() + if device: + self._power = device.power + else: + self._power = 0 + + return self._power + + @property + def icon(self): + """Sensor icon""" + return ICON_POWER + + @property + def unit_of_measurement(self): + """Sensor unit of measurement""" + return "W" + + @property + def device_state_attributes(self): + """Sensor device state attributes""" + return { + ATTR_ATTRIBUTION: NICEHASH_ATTRIBUTION, + "power": self._power, + "rig": self._rig_name, + } + From e324a2ae18b849d9734e63b5b570ca839c47d42d Mon Sep 17 00:00:00 2001 From: Pascal Berski Date: Mon, 27 Dec 2021 01:25:55 +0100 Subject: [PATCH 3/4] added DevicePowerSensor (sensor.py / nicehash.py) --- custom_components/nicehash/nicehash.py | 1 + custom_components/nicehash/sensor.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/custom_components/nicehash/nicehash.py b/custom_components/nicehash/nicehash.py index 501a3b9..c6a6515 100644 --- a/custom_components/nicehash/nicehash.py +++ b/custom_components/nicehash/nicehash.py @@ -49,6 +49,7 @@ def __init__(self, data: dict): self.load = float(data.get("load")) self.rpm = float(data.get("revolutionsPerMinute")) self.speeds = data.get("speeds") + self.power = float(data.get("powerUsage")) class MiningRig: diff --git a/custom_components/nicehash/sensor.py b/custom_components/nicehash/sensor.py index 3ad2ad5..ca235e4 100644 --- a/custom_components/nicehash/sensor.py +++ b/custom_components/nicehash/sensor.py @@ -39,6 +39,7 @@ ) from .device_sensors import ( DeviceAlgorithmSensor, + DevicePowerSensor, DeviceSpeedSensor, DeviceStatusSensor, DeviceLoadSensor, @@ -192,5 +193,6 @@ def create_device_sensors(mining_rigs, coordinator): device_sensors.append(DeviceTemperatureSensor(coordinator, rig, device)) device_sensors.append(DeviceLoadSensor(coordinator, rig, device)) device_sensors.append(DeviceRPMSensor(coordinator, rig, device)) + device_sensors.append(DevicePowerSensor(coordinator, rig, device)) return device_sensors From 5f229e3b2983887e1f63b3ae99596d5a094351fd Mon Sep 17 00:00:00 2001 From: Pascal Berski <77379623+pascalberski@users.noreply.github.com> Date: Mon, 27 Dec 2021 11:15:49 +0100 Subject: [PATCH 4/4] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a512432..ab01f6d 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ A [Home Assistant][homeassistant] integration that creates a collection of [Nice - Temperature - Load - RPM + - Power - Most Recent Mining Payout None of the sensors are added by default. See installation instructions for available configuration options.