Skip to content

Commit

Permalink
Merge branch 'main' into reboot
Browse files Browse the repository at this point in the history
  • Loading branch information
b-rowan authored Jun 21, 2024
2 parents 66ac244 + c4f0b83 commit caa60ee
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
10 changes: 10 additions & 0 deletions custom_components/miner/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ async def _async_update_data(self):

_LOGGER.debug(f"Got data: {miner_data}")

try:
hashrate = round(float(miner_data.hashrate), 2)
except TypeError:
hashrate = None

try:
expected_hashrate = round(float(miner_data.expected_hashrate), 2)
except TypeError:
expected_hashrate = None

data = {
"hostname": miner_data.hostname,
"mac": miner_data.mac,
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 @@ -9,6 +9,6 @@
"issue_tracker": "https://github.com/Schnitzel/hass-miner/issues",
"requirements": ["pyasic==0.57.6"],
"ssdp": [],
"version": "1.1.4",
"version": "1.1.9",
"zeroconf": []
}
9 changes: 8 additions & 1 deletion custom_components/miner/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def __init__(
super().__init__(coordinator=coordinator)
self._attr_unique_id = f"{self.coordinator.data['mac']}-active"
self._attr_is_on = self.coordinator.data["is_mining"]
self.updating_switch = False

@property
def name(self) -> str | None:
Expand All @@ -88,6 +89,7 @@ async def async_turn_on(self) -> None:
raise TypeError(f"{miner}: Shutdown not supported.")
self._attr_is_on = True
await miner.resume_mining()
self.updating_switch = True
self.async_write_ha_state()

async def async_turn_off(self) -> None:
Expand All @@ -98,13 +100,18 @@ async def async_turn_off(self) -> None:
raise TypeError(f"{miner}: Shutdown not supported.")
self._attr_is_on = False
await miner.stop_mining()
self.updating_switch = True
self.async_write_ha_state()

@callback
def _handle_coordinator_update(self) -> None:
is_mining = self.coordinator.data["is_mining"]
if is_mining is not None:
self._attr_is_on = self.coordinator.data["is_mining"]
if self.updating_switch:
if is_mining == self._attr_is_on:
self.updating_switch = False
if not self.updating_switch:
self._attr_is_on = is_mining

super()._handle_coordinator_update()

Expand Down
10 changes: 5 additions & 5 deletions info.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Miner control and data is handled using [@UpstreamData](https://github.com/Upstr
[integration_blueprint]: https://github.com/custom-components/integration_blueprint
[buymecoffee]: https://www.buymeacoffee.com/ludeeus
[buymecoffeebadge]: https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow.svg?style=for-the-badge
[commits-shield]: https://img.shields.io/github/commit-activity/y/Schnitzel/miner.svg?style=for-the-badge
[commits]: https://github.com/Schnitzel/miner/commits/main
[commits-shield]: https://img.shields.io/github/commit-activity/y/Schnitzel/hass-miner.svg?style=for-the-badge
[commits]: https://github.com/Schnitzel/hass-miner/commits/main
[hacs]: https://hacs.xyz
[hacsbadge]: https://img.shields.io/badge/HACS-Custom-orange.svg?style=for-the-badge
[discord]: https://discord.gg/Qa5fW2R
Expand All @@ -55,8 +55,8 @@ Miner control and data is handled using [@UpstreamData](https://github.com/Upstr
[forum-shield]: https://img.shields.io/badge/community-forum-brightgreen.svg?style=for-the-badge
[forum]: https://community.home-assistant.io/
[license]: https://github.com/Schnitzel/miner/blob/main/LICENSE
[license-shield]: https://img.shields.io/github/license/Schnitzel/miner.svg?style=for-the-badge
[license-shield]: https://img.shields.io/github/license/Schnitzel/hass-miner.svg?style=for-the-badge
[maintenance-shield]: https://img.shields.io/badge/maintainer-%40Schnitzel-blue.svg?style=for-the-badge
[releases-shield]: https://img.shields.io/github/release/Schnitzel/miner.svg?style=for-the-badge
[releases]: https://github.com/Schnitzel/miner/releases
[releases-shield]: https://img.shields.io/github/release/Schnitzel/hass-miner.svg?style=for-the-badge
[releases]: https://github.com/Schnitzel/hass-miner/releases
[user_profile]: https://github.com/Schnitzel

0 comments on commit caa60ee

Please sign in to comment.