Skip to content

Commit

Permalink
Merge pull request #5 from pascalberski/issue4
Browse files Browse the repository at this point in the history
bug fixed: value update
  • Loading branch information
pascalberski committed Apr 2, 2022
2 parents f67cd70 + 2ddfd48 commit c5c2ddc
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
18 changes: 15 additions & 3 deletions custom_components/octune/api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
OCTune API interface
"""
import json
import logging
import httpx

Expand All @@ -19,14 +18,27 @@ async def get_devices(self):
devices = await self.get_devices_json()
workers = await self.get_workers_json()

for i in range(len(devices)):
i = 0
for device in devices:
for worker in workers:
if (worker.get("device_uuid") == devices[i].get("uuid")):
if (worker.get("device_uuid") == device.get("uuid")):
devices[i]["algorithms"] = worker.get("algorithms")
workers.remove(worker)
i += 1

return devices

async def get_device_by_id(self, id):
""" return a device by id or uuid """
device = (await self.request("GET", "/api?command={\"id\":1,\"method\":\"device.get\",\"params\":[\"" + id + "\"]}")).get("device")
workers = await self.get_workers_json()

for worker in workers:
if (worker.get("device_uuid") == device.get("uuid")):
device["algorithms"] = worker.get("algorithms")

return device

async def get_devices_json(self):
""" get devices json array """
return (await self.request("GET", "/devices_cuda")).get("devices")
Expand Down
2 changes: 1 addition & 1 deletion custom_components/octune/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
NAME = "NiceHash QuickMiner OCTune"
DOMAIN = "octune"
DOMAIN_DATA = f"{DOMAIN}_data"
VERSION = "0.0.1"
VERSION = "0.0.2"
DEFAULT_NAME = "octune"

ISSUE_URL = "https://github.com/pascalberski/ha-nhqm-octune/issues"
Expand Down
20 changes: 15 additions & 5 deletions custom_components/octune/devicesensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from homeassistant.helpers.entity import Entity

from custom_components.octune.api import OCTuneApiClient

from .const import (
ICON_HASHRATE,
)
Expand Down Expand Up @@ -66,7 +68,14 @@ async def async_update(self):

def _get_data(self):
try:
return self.coordinator.data
#_LOGGER.debug("coordinator.data: %s", self.coordinator.data)
devices = self.coordinator.data

for device in devices:
#_LOGGER.debug("comapre %s == %s = %s", device.get("uuid"), self.device.get("uuid"), (device.get("uuid") == self.device.get("uuid")))
if (device.get("uuid") == self.device.get("uuid")):
#_LOGGER.debug("device: %s", device)
return device
except Exception as exc:
_LOGGER.error("Unable to get api data\n%s", exc)
return None
Expand Down Expand Up @@ -96,7 +105,8 @@ def unique_id(self):
@property
def state(self):
"""Sensor state"""
value = float(self.device.get("gpu_temp"))
#_LOGGER.debug("data type: %s", str(type(self._get_data())))
value = float(self._get_data().get("gpu_temp"))
self.log_updates(value)
return value

Expand Down Expand Up @@ -126,7 +136,7 @@ def unique_id(self):
@property
def state(self):
"""Sensor state"""
value = float(self.device.get("__vram_temp"))
value = float(self._get_data().get("__vram_temp"))
self.log_updates(value)
return value

Expand Down Expand Up @@ -156,7 +166,7 @@ def unique_id(self):
@property
def state(self):
"""Sensor state"""
value = float(self.device.get("__hotspot_temp"))
value = float(self._get_data().get("__hotspot_temp"))
self.log_updates(value)
return value

Expand Down Expand Up @@ -190,7 +200,7 @@ def unique_id(self):
@property
def state(self):
"""Sensor state"""
value = round(float(self.device.get("algorithms")[0].get("speed"))/1000000, 2)
value = round(float(self._get_data().get("algorithms")[0].get("speed"))/1000000, 2)
self.log_updates(value)
return value

Expand Down
3 changes: 2 additions & 1 deletion custom_components/octune/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"documentation": "https://github.com/pascalberski/ha-nhqm-octune",
"issue_tracker": "https://github.com/pascalberski/ha-nhqm-octune/issues",
"dependencies": [],
"version": "0.0.1",
"version": "0.0.2",
"iot_class": "local_polling",
"codeowners": [
"@pascalberski"
],
Expand Down

0 comments on commit c5c2ddc

Please sign in to comment.