Skip to content

Commit

Permalink
Merge pull request #208 from UpstreamData/main
Browse files Browse the repository at this point in the history
Remove NumberEntity deprecated functionality
  • Loading branch information
Schnitzel authored Nov 13, 2023
2 parents d1fe269 + b3b2869 commit b42370a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Control your Bitcoin miner from Home Assistant.

## Installation

Use HACS, add the custom repo https://github.com/UpstreamData/hass-miner to it
Use HACS, add the custom repo https://github.com/Schnitzel/hass-miner to it

Installation and usage:

Expand Down
3 changes: 2 additions & 1 deletion custom_components/miner/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ async def validate_input(data: dict[str, str]) -> dict[str, str]:
miner.pwd = miner_password
await miner.get_data()

except Exception: # pylint: disable=broad-except
except Exception as e: # pylint: disable=broad-except
_LOGGER.error(f"Miner setup error: {e}")
return {
"base": "Unable to authenticate with Miner, is Username & Password correct?"
}
Expand Down
2 changes: 1 addition & 1 deletion custom_components/miner/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async def _async_update_data(self):
"miner_sensors": {
"hashrate": miner_data.hashrate,
"ideal_hashrate": miner_data.nominal_hashrate,
"temperature": int(miner_data.temperature_avg),
"temperature": miner_data.temperature_avg,
"power_limit": miner_data.wattage_limit,
"miner_consumption": miner_data.wattage,
},
Expand Down
2 changes: 1 addition & 1 deletion custom_components/miner/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"homekit": {},
"iot_class": "local_polling",
"issue_tracker": "https://github.com/Schnitzel/hass-miner/issues",
"requirements": ["pyasic==0.36.9"],
"requirements": ["pyasic==0.40.0"],
"ssdp": [],
"version": "0.7.0",
"zeroconf": []
Expand Down
47 changes: 31 additions & 16 deletions custom_components/miner/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,13 @@ def _create_entity(key: str):
# coordinator.async_add_listener(new_data_received)


# TODO: This needs an update. Lots of weird lint errors here.
class MinerPowerLimitNumber(CoordinatorEntity[MinerCoordinator], NumberEntity):
"""Defines a Miner Number to set the Power Limit of the Miner."""

def __init__(
self,
coordinator: MinerCoordinator,
) -> None:
"""Initialize the sensor."""
def __init__(self, coordinator: MinerCoordinator):
"""Initialize the PowerLimit entity."""
super().__init__(coordinator=coordinator)
self._attr_unique_id = f"{self.coordinator.data['mac']}-power_limit"

self._attr_value = self.coordinator.data["miner_sensors"]["power_limit"]

self._attr_min_value = 100
self._attr_max_value = 5000
self._attr_step = 100
self._attr_native_value = self.coordinator.data["miner_sensors"]["power_limit"]

@property
def name(self) -> str | None:
Expand All @@ -89,7 +79,32 @@ def device_info(self) -> entity.DeviceInfo:
name=f"{self.coordinator.entry.title}",
)

async def async_set_value(self, value):
@property
def unique_id(self) -> str | None:
"""Return device UUID."""
return f"{self.coordinator.data['mac']}-power_limit"

@property
def native_min_value(self) -> float | None:
"""Return device minimum value."""
return 100

@property
def native_max_value(self) -> float | None:
"""Return device maximum value."""
return 5000

@property
def native_step(self) -> float | None:
"""Return device increment step."""
return 100

@property
def native_unit_of_measurement(self):
"""Return device unit of measurement."""
return "W"

async def async_set_native_value(self, value):
"""Update the current value."""

miner = self.coordinator.miner
Expand All @@ -107,11 +122,11 @@ async def async_set_value(self, value):
if not result:
raise pyasic.APIError("Failed to set wattage.")

self._attr_value = value
self._attr_native_value = value
self.async_write_ha_state()

@callback
def _handle_coordinator_update(self) -> None:
self._attr_value = self.coordinator.data["miner_sensors"]["power_limit"]
self._attr_native_value = self.coordinator.data["miner_sensors"]["power_limit"]

super()._handle_coordinator_update()
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
minerinterface==0.5.3
colorlog==6.7.0
homeassistant==2023.7.1
homeassistant
pip>=21.0,<23.2
ruff==0.0.267
pyasic==0.36.9
pyasic
pre-commit

0 comments on commit b42370a

Please sign in to comment.