refactor(sensors): minor simplification

This commit is contained in:
Brian Berg 2020-07-11 18:41:22 +00:00
parent eefd191e51
commit 78fc79e7a7
2 changed files with 27 additions and 32 deletions

View File

@ -99,12 +99,10 @@ class DeviceSensor(Entity):
async def async_update(self): async def async_update(self):
"""Update entity""" """Update entity"""
await self.coordinator.async_request_refresh() await self.coordinator.async_request_refresh()
mining_rigs = self.coordinator.data.get("miningRigs")
try: try:
mining_rigs = self.coordinator.data.get("miningRigs")
rig = MiningRig(mining_rigs.get(self._rig_id)) rig = MiningRig(mining_rigs.get(self._rig_id))
if rig:
device = rig.devices.get(self._device_id) device = rig.devices.get(self._device_id)
if device:
self._status = device.status self._status = device.status
self._load = device.load self._load = device.load
self._rpm = device.rpm self._rpm = device.rpm

View File

@ -61,11 +61,10 @@ class RigTemperatureSensor(Entity):
@property @property
def state(self): def state(self):
"""Sensor state""" """Sensor state"""
mining_rigs = self.coordinator.data.get("miningRigs")
self._highest_temp = 0 self._highest_temp = 0
try: try:
mining_rigs = self.coordinator.data.get("miningRigs")
rig = MiningRig(mining_rigs.get(self._rig_id)) rig = MiningRig(mining_rigs.get(self._rig_id))
if rig:
self._temps = rig.temperatures self._temps = rig.temperatures
self._num_devices = rig.num_devices self._num_devices = rig.num_devices
self._highest_temp = max(rig.temperatures) self._highest_temp = max(rig.temperatures)
@ -143,11 +142,10 @@ class RigStatusSensor(Entity):
@property @property
def state(self): def state(self):
"""Sensor state""" """Sensor state"""
mining_rigs = self.coordinator.data.get("miningRigs")
status = DEVICE_STATUS_UNKNOWN status = DEVICE_STATUS_UNKNOWN
try: try:
mining_rigs = self.coordinator.data.get("miningRigs")
rig = MiningRig(mining_rigs.get(self._rig_id)) rig = MiningRig(mining_rigs.get(self._rig_id))
if rig:
status = rig.status status = rig.status
self._status_time = datetime.fromtimestamp(rig.status_time / 1000.0) self._status_time = datetime.fromtimestamp(rig.status_time / 1000.0)
except Exception as e: except Exception as e:
@ -231,10 +229,9 @@ class RigProfitabilitySensor(Entity):
@property @property
def state(self): def state(self):
"""Sensor state""" """Sensor state"""
mining_rigs = self.coordinator.data.get("miningRigs")
try: try:
mining_rigs = self.coordinator.data.get("miningRigs")
rig = MiningRig(mining_rigs.get(self._rig_id)) rig = MiningRig(mining_rigs.get(self._rig_id))
if rig:
self._profitability = rig.profitability self._profitability = rig.profitability
self._unpaid_amount = rig.unpaid_amount self._unpaid_amount = rig.unpaid_amount
except Exception as e: except Exception as e: