Skip to content

Commit 20c98ca

Browse files
author
enes.oerdek
committed
feat: introduce new sensors (statistics)
1 parent 9ea491f commit 20c98ca

File tree

3 files changed

+251
-21
lines changed

3 files changed

+251
-21
lines changed

custom_components/helium_solana/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ async def async_setup_entry(
4747
hass.data[DOMAIN][entry.entry_id] = hass_data
4848
#_LOGGER.exception(entry)
4949
# Forward the setup to the sensor platform.
50-
hass.async_create_task(
51-
hass.config_entries.async_forward_entry_setup(entry, "sensor")
52-
)
50+
await hass.config_entries.async_forward_entry_setups(entry, ["sensor"])
5351
return True
5452

5553
async def async_unload_entry(

custom_components/helium_solana/sensor.py

Lines changed: 246 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
Entity,
1818
DeviceInfo
1919
)
20-
20+
from homeassistant.core import HomeAssistant
2121
from homeassistant.helpers.typing import (
2222
ConfigType,
23-
DiscoveryInfoType,
24-
HomeAssistantType,
23+
DiscoveryInfoType
2524
)
2625

2726
from homeassistant.helpers.device_registry import DeviceEntryType
@@ -89,7 +88,7 @@ async def async_setup_entry(
8988
async_add_entities(sensors, update_before_add=True)
9089

9190
async def async_setup_platform(
92-
hass: HomeAssistantType,
91+
hass: HomeAssistant,
9392
config: ConfigType,
9493
async_add_entities: Callable,
9594
discovery_info: Optional[DiscoveryInfoType] = None,
@@ -115,18 +114,250 @@ async def get_sensors(integration, wallet, prices):
115114
sensors.append(PriceSensor(price))
116115

117116
if integration == 'general_stats':
118-
sensors.append(HeliumStats(api_backend, 'IOT', 'total_hotspots', 'Total Hotspots', ['stats', 'iot', 'total_hotspots'], 'mdi:router-wireless', 'Hotspots'))
119-
sensors.append(HeliumStats(api_backend, 'IOT', 'active_hotspots', 'Active Hotspots', ['stats', 'iot', 'active_hotspots'], 'mdi:router-wireless', 'Hotspots'))
120-
sensors.append(HeliumStats(api_backend, 'IOT', 'total_cities', 'Total Cities', ['stats', 'iot', 'total_cities'],'mdi:city', 'Cities'))
121-
sensors.append(HeliumStats(api_backend, 'IOT', 'total_countries', 'Total Countries', ['stats', 'iot', 'total_countries'], 'mdi:earth', 'Countries'))
122-
sensors.append(HeliumStats(api_backend, 'IOT', 'daily_average_rewards', 'Daily Average Rewards', ['stats', 'iot', 'daily_average_rewards'], 'mdi:hand-coin-outline', 'IOT', 'float'))
123-
124-
sensors.append(HeliumStats(api_backend, 'MOBILE', 'total_hotspots', 'Total Hotspots', ['stats', 'mobile', 'total_hotspots'],'mdi:router-wireless', 'Hotspots'))
125-
sensors.append(HeliumStats(api_backend, 'MOBILE', 'active_hotspots', 'Active Hotspots', ['stats', 'mobile', 'active_hotspots'],'mdi:router-wireless', 'Hotspots'))
126-
sensors.append(HeliumStats(api_backend, 'MOBILE', 'total_cities', 'Total Cities', ['stats', 'mobile', 'total_cities'], 'mdi:city', 'Cities'))
127-
sensors.append(HeliumStats(api_backend, 'MOBILE', 'total_countries', 'Total Countries', ['stats', 'mobile', 'total_countries'], 'mdi:earth', 'Countries'))
128-
sensors.append(HeliumStats(api_backend, 'MOBILE', 'daily_average_rewards', 'Daily Average Rewards', ['stats', 'mobile', 'daily_average_rewards'], 'mdi:hand-coin-outline', 'MOBILE' ,'float'))
117+
sensors.append(
118+
HeliumStats(
119+
api_backend,
120+
"heliumstats",
121+
"IOT",
122+
"total_hotspots",
123+
"Total Hotspots",
124+
["stats", "iot", "total_hotspots"],
125+
"mdi:router-wireless",
126+
"Hotspots",
127+
)
128+
)
129+
sensors.append(
130+
HeliumStats(
131+
api_backend,
132+
"heliumstats",
133+
"IOT",
134+
"active_hotspots",
135+
"Active Hotspots",
136+
["stats", "iot", "active_hotspots"],
137+
"mdi:router-wireless",
138+
"Hotspots",
139+
)
140+
)
141+
sensors.append(
142+
HeliumStats(
143+
api_backend,
144+
"heliumstats",
145+
"IOT",
146+
"total_cities",
147+
"Total Cities",
148+
["stats", "iot", "total_cities"],
149+
"mdi:city",
150+
"Cities",
151+
)
152+
)
153+
sensors.append(
154+
HeliumStats(
155+
api_backend,
156+
"heliumstats",
157+
"IOT",
158+
"total_countries",
159+
"Total Countries",
160+
["stats", "iot", "total_countries"],
161+
"mdi:earth",
162+
"Countries",
163+
)
164+
)
165+
sensors.append(
166+
HeliumStats(
167+
api_backend,
168+
"heliumstats",
169+
"IOT",
170+
"daily_average_rewards",
171+
"Daily Average Rewards",
172+
["stats", "iot", "daily_average_rewards"],
173+
"mdi:hand-coin-outline",
174+
"IOT",
175+
"float",
176+
)
177+
)
178+
179+
sensors.append(
180+
HeliumStats(
181+
api_backend,
182+
"heliumstats",
183+
"MOBILE",
184+
"total_hotspots",
185+
"Total Hotspots",
186+
["stats", "mobile", "total_hotspots"],
187+
"mdi:router-wireless",
188+
"Hotspots",
189+
)
190+
)
191+
sensors.append(
192+
HeliumStats(
193+
api_backend,
194+
"heliumstats",
195+
"MOBILE",
196+
"active_hotspots",
197+
"Active Hotspots",
198+
["stats", "mobile", "active_hotspots"],
199+
"mdi:router-wireless",
200+
"Hotspots",
201+
)
202+
)
203+
sensors.append(
204+
HeliumStats(
205+
api_backend,
206+
"heliumstats",
207+
"MOBILE",
208+
"total_cities",
209+
"Total Cities",
210+
["stats", "mobile", "total_cities"],
211+
"mdi:city",
212+
"Cities",
213+
)
214+
)
215+
sensors.append(
216+
HeliumStats(
217+
api_backend,
218+
"heliumstats",
219+
"MOBILE",
220+
"total_countries",
221+
"Total Countries",
222+
["stats", "mobile", "total_countries"],
223+
"mdi:earth",
224+
"Countries",
225+
)
226+
)
227+
sensors.append(
228+
HeliumStats(
229+
api_backend,
230+
"heliumstats",
231+
"MOBILE",
232+
"daily_average_rewards",
233+
"Daily Average Rewards",
234+
["stats", "mobile", "daily_average_rewards"],
235+
"mdi:hand-coin-outline",
236+
"MOBILE",
237+
"float",
238+
)
239+
)
240+
241+
sensors.append(
242+
HeliumStats(
243+
api_backend,
244+
"epochinfo",
245+
"HNT",
246+
"epoch",
247+
"Epoch",
248+
["epoch"],
249+
"mdi:hand-coin-outline",
250+
"Epoch",
251+
"int",
252+
)
253+
)
254+
sensors.append(
255+
HeliumStats(
256+
api_backend,
257+
"epochinfo",
258+
"IOT",
259+
"dc_burned",
260+
"DC burned",
261+
["iot_dc_burned"],
262+
"mdi:hand-coin-outline",
263+
"IOT",
264+
"int",
265+
)
266+
)
267+
sensors.append(
268+
HeliumStats(
269+
api_backend,
270+
"epochinfo",
271+
"IOT",
272+
"delegation_rewards",
273+
"Delegation Rewards",
274+
["iot_delegation_rewards_issued"],
275+
"mdi:hand-coin-outline",
276+
"IOT",
277+
"int",
278+
)
279+
)
280+
sensors.append(
281+
HeliumStats(
282+
api_backend,
283+
"epochinfo",
284+
"IOT",
285+
"utility_score",
286+
"Utility Score",
287+
["iot_utility_score"],
288+
"mdi:hand-coin-outline",
289+
"Score",
290+
"int",
291+
)
292+
)
293+
sensors.append(
294+
HeliumStats(
295+
api_backend,
296+
"epochinfo",
297+
"IOT",
298+
"vehnt",
299+
"VeHNT",
300+
["iot_vehnt_at_epoch_start"],
301+
"mdi:hand-coin-outline",
302+
"VeHNT",
303+
"float",
304+
)
305+
)
129306

307+
sensors.append(
308+
HeliumStats(
309+
api_backend,
310+
"epochinfo",
311+
"MOBILE",
312+
"dc_burned",
313+
"DC burned",
314+
["mobile_dc_burned"],
315+
"mdi:hand-coin-outline",
316+
"MOBILE",
317+
"int",
318+
)
319+
)
320+
sensors.append(
321+
HeliumStats(
322+
api_backend,
323+
"epochinfo",
324+
"MOBILE",
325+
"delegation_rewards",
326+
"Delegation Rewards",
327+
["mobile_delegation_rewards_issued"],
328+
"mdi:hand-coin-outline",
329+
"MOBILE",
330+
"int",
331+
)
332+
)
333+
sensors.append(
334+
HeliumStats(
335+
api_backend,
336+
"epochinfo",
337+
"MOBILE",
338+
"utility_score",
339+
"Utility Score",
340+
["mobile_utility_score"],
341+
"mdi:hand-coin-outline",
342+
"Score",
343+
"int",
344+
)
345+
)
346+
sensors.append(
347+
HeliumStats(
348+
api_backend,
349+
"epochinfo",
350+
"MOBILE",
351+
"vehnt",
352+
"VeHNT",
353+
["mobile_vehnt_at_epoch_start"],
354+
"mdi:hand-coin-outline",
355+
"VeHNT",
356+
"float",
357+
)
358+
)
359+
360+
130361
if integration == 'wallet':
131362

132363
#if integration == 'wallet_balance':

custom_components/helium_solana/sensors/HeliumStats.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515

1616
class HeliumStats(Entity):
1717
"""Helium Stats"""
18-
def __init__(self, api, token, key, name, path, icon, uom, type='int'):
18+
def __init__(self, api, api_entity, token, key, name, path, icon, uom, type='int'):
1919
super().__init__()
2020
self.api = api
21+
self.api_entity = api_entity
2122
self.token = token
2223
self.key = key
2324
self.path = path
@@ -75,7 +76,7 @@ async def async_update(self):
7576
try:
7677

7778

78-
response = await self.api.get_data('heliumstats')
79+
response = await self.api.get_data(self.api_entity)
7980

8081
if response.status_code != 200:
8182
return
@@ -95,4 +96,4 @@ async def async_update(self):
9596

9697
except (requests.exceptions.RequestException):
9798
self._available = False
98-
_LOGGER.exception("Error retrieving helium stats from hotspotty")
99+
_LOGGER.exception("Error retrieving helium stats from backend")

0 commit comments

Comments
 (0)