added class DevicePowerSensor

This commit is contained in:
Pascal Berski 2021-12-27 01:24:31 +01:00 committed by Roxedus
parent 829d1cd3f7
commit 53f35f04ea
No known key found for this signature in database
GPG Key ID: EBC13557C4D91D7B

View File

@ -17,6 +17,7 @@ from .const import (
ICON_PULSE,
ICON_THERMOMETER,
ICON_SPEEDOMETER,
ICON_POWER,
NICEHASH_ATTRIBUTION,
)
from .coordinators import MiningRigsDataUpdateCoordinator
@ -381,3 +382,48 @@ class DeviceRPMSensor(DeviceSensor):
"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,
}