diff --git a/README.md b/README.md index a512432..11fb748 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ A [Home Assistant][homeassistant] integration that creates a collection of [Nice - Algorithm - Speed - Temperature + - HotSpot Temperature - Load - RPM - Most Recent Mining Payout diff --git a/custom_components/nicehash/device_sensors.py b/custom_components/nicehash/device_sensors.py index b40b28f..3bde909 100644 --- a/custom_components/nicehash/device_sensors.py +++ b/custom_components/nicehash/device_sensors.py @@ -287,6 +287,54 @@ def device_state_attributes(self): "rig": self._rig_name, } +class DeviceHotspotTemperatureSensor(DeviceSensor): + """ + Displays hotspot temperature of a mining rig device + """ + + _temperature = 0 + + @property + def name(self): + """Sensor name""" + return f"{self._device_name} hotspot Temperature" + + @property + def unique_id(self): + """Unique entity id""" + return f"{self._device_id}:hotspot_temperature" + + @property + def state(self): + """Sensor state""" + device = self._get_device() + if device: + self._hotspot_temperature = device.hotspot_temperature + else: + self._hotspot_temperature = 0 + + return self._hotspot_temperature + + @property + def icon(self): + """Sensor icon""" + return ICON_THERMOMETER + + @property + def unit_of_measurement(self): + """Sensor unit of measurement""" + # Not Celsius because then HA might convert to Fahrenheit + return "C" + + @property + def device_state_attributes(self): + """Sensor device state attributes""" + return { + ATTR_ATTRIBUTION: NICEHASH_ATTRIBUTION, + "hotspot_temperature": self._hotspot_temperature, + "rig": self._rig_name, + } + class DeviceLoadSensor(DeviceSensor): """ diff --git a/custom_components/nicehash/nicehash.py b/custom_components/nicehash/nicehash.py index 501a3b9..79e0394 100644 --- a/custom_components/nicehash/nicehash.py +++ b/custom_components/nicehash/nicehash.py @@ -46,6 +46,7 @@ def __init__(self, data: dict): self.name = parse_device_name(data.get("name")) self.status = data.get("status").get("description") self.temperature = int(data.get("temperature")) % MAX_TWO_BYTES + self.hotspot_temperature = round(int(data.get("temperature")) / MAX_TWO_BYTES) self.load = float(data.get("load")) self.rpm = float(data.get("revolutionsPerMinute")) self.speeds = data.get("speeds") diff --git a/custom_components/nicehash/sensor.py b/custom_components/nicehash/sensor.py index 3ad2ad5..7cd036c 100644 --- a/custom_components/nicehash/sensor.py +++ b/custom_components/nicehash/sensor.py @@ -44,6 +44,7 @@ DeviceLoadSensor, DeviceRPMSensor, DeviceTemperatureSensor, + DeviceHotspotTemperatureSensor ) _LOGGER = logging.getLogger(__name__) @@ -190,6 +191,7 @@ def create_device_sensors(mining_rigs, coordinator): device_sensors.append(DeviceSpeedSensor(coordinator, rig, device)) device_sensors.append(DeviceStatusSensor(coordinator, rig, device)) device_sensors.append(DeviceTemperatureSensor(coordinator, rig, device)) + device_sensors.append(DeviceHotspotTemperatureSensor(coordinator, rig, device)) device_sensors.append(DeviceLoadSensor(coordinator, rig, device)) device_sensors.append(DeviceRPMSensor(coordinator, rig, device))