refactor(sensors): minor simplification
This commit is contained in:
parent
eefd191e51
commit
78fc79e7a7
@ -99,27 +99,25 @@ class DeviceSensor(Entity):
|
||||
async def async_update(self):
|
||||
"""Update entity"""
|
||||
await self.coordinator.async_request_refresh()
|
||||
mining_rigs = self.coordinator.data.get("miningRigs")
|
||||
try:
|
||||
mining_rigs = self.coordinator.data.get("miningRigs")
|
||||
rig = MiningRig(mining_rigs.get(self._rig_id))
|
||||
if rig:
|
||||
device = rig.devices.get(self._device_id)
|
||||
if device:
|
||||
self._status = device.status
|
||||
self._load = device.load
|
||||
self._rpm = device.rpm
|
||||
self._temperature = device.temperature
|
||||
algorithms = device.speeds
|
||||
if len(algorithms) > 0:
|
||||
algorithm = algorithms[0]
|
||||
self._algorithm = algorithm.get("title")
|
||||
self._speed = float(algorithm.get("speed"))
|
||||
self._speed_title = algorithm.get("title")
|
||||
self._speed_unit = algorithm.get("displaySuffix")
|
||||
else:
|
||||
self._speed_title = "Unknown"
|
||||
self._speed_unit = "MH"
|
||||
self._algorithm = None
|
||||
device = rig.devices.get(self._device_id)
|
||||
self._status = device.status
|
||||
self._load = device.load
|
||||
self._rpm = device.rpm
|
||||
self._temperature = device.temperature
|
||||
algorithms = device.speeds
|
||||
if len(algorithms) > 0:
|
||||
algorithm = algorithms[0]
|
||||
self._algorithm = algorithm.get("title")
|
||||
self._speed = float(algorithm.get("speed"))
|
||||
self._speed_title = algorithm.get("title")
|
||||
self._speed_unit = algorithm.get("displaySuffix")
|
||||
else:
|
||||
self._speed_title = "Unknown"
|
||||
self._speed_unit = "MH"
|
||||
self._algorithm = None
|
||||
except Exception as e:
|
||||
_LOGGER.error(f"Unable to get mining device ({self._device_id})\n{e}")
|
||||
self._status = DEVICE_STATUS_UNKNOWN
|
||||
|
@ -61,14 +61,13 @@ class RigTemperatureSensor(Entity):
|
||||
@property
|
||||
def state(self):
|
||||
"""Sensor state"""
|
||||
mining_rigs = self.coordinator.data.get("miningRigs")
|
||||
self._highest_temp = 0
|
||||
try:
|
||||
mining_rigs = self.coordinator.data.get("miningRigs")
|
||||
rig = MiningRig(mining_rigs.get(self._rig_id))
|
||||
if rig:
|
||||
self._temps = rig.temperatures
|
||||
self._num_devices = rig.num_devices
|
||||
self._highest_temp = max(rig.temperatures)
|
||||
self._temps = rig.temperatures
|
||||
self._num_devices = rig.num_devices
|
||||
self._highest_temp = max(rig.temperatures)
|
||||
except Exception as e:
|
||||
_LOGGER.error(f"Unable to get mining rig ({self._rig_id}) temperature\n{e}")
|
||||
|
||||
@ -143,13 +142,12 @@ class RigStatusSensor(Entity):
|
||||
@property
|
||||
def state(self):
|
||||
"""Sensor state"""
|
||||
mining_rigs = self.coordinator.data.get("miningRigs")
|
||||
status = DEVICE_STATUS_UNKNOWN
|
||||
try:
|
||||
mining_rigs = self.coordinator.data.get("miningRigs")
|
||||
rig = MiningRig(mining_rigs.get(self._rig_id))
|
||||
if rig:
|
||||
status = rig.status
|
||||
self._status_time = datetime.fromtimestamp(rig.status_time / 1000.0)
|
||||
status = rig.status
|
||||
self._status_time = datetime.fromtimestamp(rig.status_time / 1000.0)
|
||||
except Exception as e:
|
||||
_LOGGER.error(f"Unable to get mining rig ({self._rig_id}) status\n{e}")
|
||||
self._status_time = None
|
||||
@ -231,12 +229,11 @@ class RigProfitabilitySensor(Entity):
|
||||
@property
|
||||
def state(self):
|
||||
"""Sensor state"""
|
||||
mining_rigs = self.coordinator.data.get("miningRigs")
|
||||
try:
|
||||
mining_rigs = self.coordinator.data.get("miningRigs")
|
||||
rig = MiningRig(mining_rigs.get(self._rig_id))
|
||||
if rig:
|
||||
self._profitability = rig.profitability
|
||||
self._unpaid_amount = rig.unpaid_amount
|
||||
self._profitability = rig.profitability
|
||||
self._unpaid_amount = rig.unpaid_amount
|
||||
except Exception as e:
|
||||
_LOGGER.error(f"Unable to get mining rig ({self._rig_id}) status\n{e}")
|
||||
self._profitability = 0
|
||||
|
Loading…
Reference in New Issue
Block a user