Skip to content

Commit 37c5edc

Browse files
committed
add a new sensor for online score average
1 parent 9532ae0 commit 37c5edc

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A custom homeassistant integration ```storj_node_statistics``` to read statistics from a storj storage node using json data provided by the node.
44

5-
This integration is unofficial and not related to the official storj company at all.
5+
This integration is unofficial and not related to the official storj company at all.
66

77
## Example card
88

@@ -13,7 +13,7 @@ This is somewhat the view I'm using, the graphs should get more interesting over
1313
## Setup
1414
### HACS (recommended)
1515

16-
Click the button below to install via HACS.
16+
Click the button below to install via HACS.
1717

1818
[![Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.](https://my.home-assistant.io/badges/hacs_repository.svg)](https://my.home-assistant.io/redirect/hacs_repository/?owner=ledimestari&repository=homeassistant-storj-integration&category=integration)
1919

@@ -52,12 +52,13 @@ Provided sensors:
5252
- Estimated earning this month
5353
- Held back this month
5454
- Gross total this month
55+
- Average online score of all satellites
5556

5657
each sensor uses the first six characters of the Node ID as a prefix to the key value, e.g. ```sensor.abc123_disk_use_percentage```.
5758

5859
Potential features missing for now:
5960

60-
- Suspension, Audit and Online scores for each satellite
61+
- Suspension, Audit and Online scores for each satellite separate
6162
- Total payout history
6263
- Disk space overused
6364
- Time since last contact

custom_components/storj_node_statistics/sensor.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@
117117
native_unit_of_measurement="$",
118118
icon="mdi:currency-usd",
119119
),
120+
SensorEntityDescription(
121+
key="storj_satellite_avg_online",
122+
name="Average Online score of all satellites",
123+
native_unit_of_measurement="%",
124+
icon="mdi:percent",
125+
),
120126
)
121127

122128

@@ -268,4 +274,14 @@ def native_value(self) -> str | None:
268274
if self.entity_description.key == "storj_current_month_pay_total":
269275
pay_total = payout + held
270276
return round(float(pay_total / 100), 2)
277+
# ---
278+
if self.entity_description.key == "storj_satellite_avg_online":
279+
avg_online_score = 0.0
280+
audits = self.coordinator.data["satellites"].get("audits", [])
281+
avg_online_score = (
282+
sum(a["onlineScore"] for a in audits) / len(audits) * 100
283+
if audits
284+
else 0
285+
)
286+
return round(float(avg_online_score), 2)
271287
return None

0 commit comments

Comments
 (0)