Skip to content

Commit

Permalink
Update requirements, and add available property to all entities.
Browse files Browse the repository at this point in the history
  • Loading branch information
b-rowan committed Jan 23, 2024
1 parent 90785ad commit 0a0f232
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
8 changes: 7 additions & 1 deletion custom_components/miner/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import pyasic
from homeassistant.components.number import NumberEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.core import callback
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
Expand Down Expand Up @@ -132,3 +133,8 @@ def _handle_coordinator_update(self) -> None:
]

super()._handle_coordinator_update()

@property
def available(self) -> bool:
"""Return if entity is available or not."""
return self.coordinator.available
15 changes: 15 additions & 0 deletions custom_components/miner/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ def native_value(self) -> StateType:
"""Return the state of the sensor."""
return self._sensor_data

@property
def available(self) -> bool:
"""Return if entity is available or not."""
return self.coordinator.available


class MinerBoardSensor(CoordinatorEntity[MinerCoordinator], SensorEntity):
"""Defines a Miner Board Sensor."""
Expand Down Expand Up @@ -249,6 +254,11 @@ def native_value(self) -> StateType:
"""Return the state of the sensor."""
return self._sensor_data

@property
def available(self) -> bool:
"""Return if entity is available or not."""
return self.coordinator.available


class MinerFanSensor(CoordinatorEntity[MinerCoordinator], SensorEntity):
"""Defines a Miner Fan Sensor."""
Expand Down Expand Up @@ -301,3 +311,8 @@ def device_info(self) -> entity.DeviceInfo:
def native_value(self) -> StateType:
"""Return the state of the sensor."""
return self._sensor_data

@property
def available(self) -> bool:
"""Return if entity is available or not."""
return self.coordinator.available
8 changes: 7 additions & 1 deletion custom_components/miner/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from homeassistant.components.sensor import SensorEntityDescription
from homeassistant.components.switch import SwitchEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant, callback
from homeassistant.core import callback
from homeassistant.core import HomeAssistant
from homeassistant.helpers import entity
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.update_coordinator import CoordinatorEntity
Expand Down Expand Up @@ -106,3 +107,8 @@ def _handle_coordinator_update(self) -> None:
self._attr_is_on = self.coordinator.data["is_mining"]

super()._handle_coordinator_update()

@property
def available(self) -> bool:
"""Return if entity is available or not."""
return self.coordinator.available
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ homeassistant>=2024.1.0
pip>=21.0,<23.2
ruff==0.0.267
pyasic==0.48.5
setuptools==69.0.3
pre-commit

0 comments on commit 0a0f232

Please sign in to comment.