refactor(sensors): update params/types
- remove device number from rig status sensor
This commit is contained in:
parent
24488a8eb7
commit
5c99904287
@ -19,6 +19,7 @@ from .const import (
|
|||||||
ICON_CURRENCY_USD,
|
ICON_CURRENCY_USD,
|
||||||
NICEHASH_ATTRIBUTION,
|
NICEHASH_ATTRIBUTION,
|
||||||
)
|
)
|
||||||
|
from .data_coordinators import AccountsDataUpdateCoordinator
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -30,9 +31,9 @@ class BalanceSensor(Entity):
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
coordinator,
|
coordinator: AccountsDataUpdateCoordinator,
|
||||||
organization_id,
|
organization_id: str,
|
||||||
currency,
|
currency: str,
|
||||||
balance_type=BALANCE_TYPE_AVAILABLE,
|
balance_type=BALANCE_TYPE_AVAILABLE,
|
||||||
):
|
):
|
||||||
"""Initialize the sensor"""
|
"""Initialize the sensor"""
|
||||||
|
@ -19,6 +19,7 @@ from .const import (
|
|||||||
ICON_SPEEDOMETER,
|
ICON_SPEEDOMETER,
|
||||||
NICEHASH_ATTRIBUTION,
|
NICEHASH_ATTRIBUTION,
|
||||||
)
|
)
|
||||||
|
from .data_coordinators import MiningRigsDataUpdateCoordinator
|
||||||
from .nicehash import MiningRig, MiningRigDevice
|
from .nicehash import MiningRig, MiningRigDevice
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -29,13 +30,18 @@ class DeviceSensor(Entity):
|
|||||||
Mining rig device sensor
|
Mining rig device sensor
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, coordinator, rig, device):
|
def __init__(
|
||||||
|
self,
|
||||||
|
coordinator: MiningRigsDataUpdateCoordinator,
|
||||||
|
rig_data: dict,
|
||||||
|
device_data: dict,
|
||||||
|
):
|
||||||
"""Initialize the sensor"""
|
"""Initialize the sensor"""
|
||||||
self.coordinator = coordinator
|
self.coordinator = coordinator
|
||||||
self._rig_id = rig.get("rigId")
|
self._rig_id = rig_data.get("rigId")
|
||||||
self._rig_name = rig.get("name")
|
self._rig_name = rig_data.get("name")
|
||||||
self._device_name = device.get("name")
|
self._device_name = device_data.get("name")
|
||||||
self._device_id = device.get("id")
|
self._device_id = device_data.get("id")
|
||||||
self._status = DEVICE_STATUS_UNKNOWN
|
self._status = DEVICE_STATUS_UNKNOWN
|
||||||
self._load = 0
|
self._load = 0
|
||||||
self._rpm = 0
|
self._rpm = 0
|
||||||
|
@ -16,6 +16,7 @@ from .const import (
|
|||||||
ICON_THERMOMETER,
|
ICON_THERMOMETER,
|
||||||
NICEHASH_ATTRIBUTION,
|
NICEHASH_ATTRIBUTION,
|
||||||
)
|
)
|
||||||
|
from .data_coordinators import MiningRigsDataUpdateCoordinator
|
||||||
from .nicehash import MiningRig
|
from .nicehash import MiningRig
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -26,11 +27,11 @@ class RigTemperatureSensor(Entity):
|
|||||||
Displays highest temperature of active mining rig devices
|
Displays highest temperature of active mining rig devices
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, coordinator, rig):
|
def __init__(self, coordinator: MiningRigsDataUpdateCoordinator, rig_data: dict):
|
||||||
"""Initialize the sensor"""
|
"""Initialize the sensor"""
|
||||||
self.coordinator = coordinator
|
self.coordinator = coordinator
|
||||||
self._rig_id = rig["rigId"]
|
self._rig_id = rig_data["rigId"]
|
||||||
self._rig_name = rig["name"]
|
self._rig_name = rig_data["name"]
|
||||||
self._temps = []
|
self._temps = []
|
||||||
self._num_devices = 0
|
self._num_devices = 0
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
@ -110,15 +111,13 @@ class RigStatusSensor(Entity):
|
|||||||
Displays status of a mining rig
|
Displays status of a mining rig
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, coordinator, rig):
|
def __init__(self, coordinator: MiningRigsDataUpdateCoordinator, rig_data: dict):
|
||||||
"""Initialize the sensor"""
|
"""Initialize the sensor"""
|
||||||
self.coordinator = coordinator
|
self.coordinator = coordinator
|
||||||
self._rig_id = rig["rigId"]
|
self._rig_id = rig_data["rigId"]
|
||||||
self._rig_name = rig["name"]
|
self._rig_name = rig_data["name"]
|
||||||
self._status = DEVICE_STATUS_UNKNOWN
|
self._status = DEVICE_STATUS_UNKNOWN
|
||||||
self._status_time = None
|
self._status_time = None
|
||||||
self._num_devices = 0
|
|
||||||
self._unit_of_measurement = "\u200b"
|
|
||||||
_LOGGER.debug(f"Mining Rig Status Sensor: {self._rig_name} ({self._rig_id})")
|
_LOGGER.debug(f"Mining Rig Status Sensor: {self._rig_name} ({self._rig_id})")
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -150,7 +149,6 @@ class RigStatusSensor(Entity):
|
|||||||
rig = MiningRig(mining_rigs.get(self._rig_id))
|
rig = MiningRig(mining_rigs.get(self._rig_id))
|
||||||
if rig:
|
if rig:
|
||||||
status = rig.status
|
status = rig.status
|
||||||
self._num_devices = rig.num_devices
|
|
||||||
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:
|
||||||
_LOGGER.error(f"Unable to get mining rig ({self._rig_id}) status\n{e}")
|
_LOGGER.error(f"Unable to get mining rig ({self._rig_id}) status\n{e}")
|
||||||
@ -168,7 +166,7 @@ class RigStatusSensor(Entity):
|
|||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Sensor unit of measurement"""
|
"""Sensor unit of measurement"""
|
||||||
return self._unit_of_measurement
|
return "\u200b"
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_state_attributes(self):
|
def device_state_attributes(self):
|
||||||
@ -181,7 +179,6 @@ class RigStatusSensor(Entity):
|
|||||||
ATTR_ATTRIBUTION: NICEHASH_ATTRIBUTION,
|
ATTR_ATTRIBUTION: NICEHASH_ATTRIBUTION,
|
||||||
"status": self._status,
|
"status": self._status,
|
||||||
"status_time": status_time,
|
"status_time": status_time,
|
||||||
"total_devices": self._num_devices,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async def async_added_to_hass(self):
|
async def async_added_to_hass(self):
|
||||||
@ -200,11 +197,11 @@ class RigProfitabilitySensor(Entity):
|
|||||||
Displays profitability of a mining rig
|
Displays profitability of a mining rig
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, coordinator, rig):
|
def __init__(self, coordinator: MiningRigsDataUpdateCoordinator, rig_data: dict):
|
||||||
"""Initialize the sensor"""
|
"""Initialize the sensor"""
|
||||||
self.coordinator = coordinator
|
self.coordinator = coordinator
|
||||||
self._rig_id = rig["rigId"]
|
self._rig_id = rig_data["rigId"]
|
||||||
self._rig_name = rig["name"]
|
self._rig_name = rig_data["name"]
|
||||||
self._profitability = 0
|
self._profitability = 0
|
||||||
self._unpaid_amount = 0
|
self._unpaid_amount = 0
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
|
Loading…
Reference in New Issue
Block a user