2828
2929from .utility import http_client
3030
31- from .api .heliumstats import HeliumStatsAPI
3231from .api .backend import BackendAPI
3332from .sensors .WalletBalance import WalletBalance
3433from .sensors .HotspotReward import HotspotReward
4039
4140from .const import (
4241 DOMAIN ,
42+ CONF_VERSION ,
43+ CONF_INTEGRATION ,
4344 CONF_WALLET ,
4445 CONF_WALLETS ,
4546 CONF_HOTSPOTS ,
6465 }
6566)
6667
67- heliumStatsAPI = HeliumStatsAPI (HOTSPOTTY_STATS , HOTSPOTTY_TOKEN )
6868api_backend = BackendAPI ()
6969
7070async def async_setup_entry (
@@ -73,9 +73,19 @@ async def async_setup_entry(
7373 async_add_entities
7474):
7575 config = hass .data [DOMAIN ][config_entry .entry_id ]
76- wallets = config .get (CONF_WALLETS )
77- sensors = await get_sensors (wallets , None )
78-
76+ integration = config .get (CONF_INTEGRATION )
77+ wallet = config .get (CONF_WALLET )
78+ sensors = await get_sensors (integration , wallet , None )
79+
80+ #version = config.get(CONF_VERSION)
81+ #if version == 2:
82+ # integration = config.get(CONF_INTEGRATION)
83+ # wallet = config.get(CONF_WALLET)
84+ # sensors = await get_sensors(integration, wallet, None)
85+ #elif version is None:
86+ # wallets = config.get(CONF_WALLETS)
87+ #print(wallets)
88+ # sensors = await get_sensors_legacy(wallets, None)
7989 async_add_entities (sensors , update_before_add = True )
8090
8191async def async_setup_platform (
@@ -87,44 +97,44 @@ async def async_setup_platform(
8797 """Set up the sensor platform."""
8898 wallets = config .get (CONF_WALLETS )
8999 prices = config .get (CONF_PRICES )
90- sensors = await get_sensors (wallets , prices )
100+ sensors = await get_sensors_legacy (wallets , prices )
91101
92102 async_add_entities (sensors , update_before_add = True )
93103
94- async def get_sensors (wallets , prices ):
104+ async def get_sensors (integration , wallet , prices ):
95105 sensors = []
96- sensors .append (PriceSensor (http_client , ADDRESS_IOT , 'IOT' , 'helium-iot' ))
97- sensors .append (PriceSensor (http_client , ADDRESS_MOBILE , 'MOBILE' , 'helium-mobile' ))
98- sensors .append (PriceSensor (http_client , ADDRESS_HNT , 'HNT' ,'helium' ))
99- sensors .append (PriceSensor (http_client , ADDRESS_SOLANA , 'SOLANA' , 'wrapped-solana' ))
100-
101-
102- if prices :
103- for price in prices :
104- sensors .append (PriceSensor (price ))
105-
106- sensors .append (HeliumStats (api_backend , 'IOT' , 'total_hotspots' , 'Total Hotspots' , ['stats' , 'iot' , 'total_hotspots' ], 'mdi:router-wireless' , 'Hotspots' ))
107- sensors .append (HeliumStats (api_backend , 'IOT' , 'active_hotspots' , 'Active Hotspots' , ['stats' , 'iot' , 'active_hotspots' ], 'mdi:router-wireless' , 'Hotspots' ))
108- sensors .append (HeliumStats (api_backend , 'IOT' , 'total_cities' , 'Total Cities' , ['stats' , 'iot' , 'total_cities' ],'mdi:city' , 'Cities' ))
109- sensors .append (HeliumStats (api_backend , 'IOT' , 'total_countries' , 'Total Countries' , ['stats' , 'iot' , 'total_countries' ], 'mdi:earth' , 'Countries' ))
110- sensors .append (HeliumStats (api_backend , 'IOT' , 'daily_average_rewards' , 'Daily Average Rewards' , ['stats' , 'iot' , 'daily_average_rewards' ], 'mdi:hand-coin-outline' , 'IOT' , 'float' ))
111106
112- sensors .append (HeliumStats (api_backend , 'MOBILE' , 'total_hotspots' , 'Total Hotspots' , ['stats' , 'mobile' , 'total_hotspots' ],'mdi:router-wireless' , 'Hotspots' ))
113- sensors .append (HeliumStats (api_backend , 'MOBILE' , 'active_hotspots' , 'Active Hotspots' , ['stats' , 'mobile' , 'active_hotspots' ],'mdi:router-wireless' , 'Hotspots' ))
114- sensors .append (HeliumStats (api_backend , 'MOBILE' , 'total_cities' , 'Total Cities' , ['stats' , 'mobile' , 'total_cities' ], 'mdi:city' , 'Cities' ))
115- sensors .append (HeliumStats (api_backend , 'MOBILE' , 'total_countries' , 'Total Countries' , ['stats' , 'mobile' , 'total_countries' ], 'mdi:earth' , 'Countries' ))
116- sensors .append (HeliumStats (api_backend , 'MOBILE' , 'daily_average_rewards' , 'Daily Average Rewards' , ['stats' , 'mobile' , 'daily_average_rewards' ], 'mdi:hand-coin-outline' , 'MOBILE' ,'float' ))
117-
118- for wallet in wallets :
119- len_wallet = len (wallet )
120- if len_wallet < 32 or len_wallet > 44 :
121- continue
122-
107+ if integration == 'general_token_price' :
108+ sensors .append (PriceSensor (http_client , ADDRESS_IOT , 'IOT' , 'helium-iot' ))
109+ sensors .append (PriceSensor (http_client , ADDRESS_MOBILE , 'MOBILE' , 'helium-mobile' ))
110+ sensors .append (PriceSensor (http_client , ADDRESS_HNT , 'HNT' ,'helium' ))
111+ sensors .append (PriceSensor (http_client , ADDRESS_SOLANA , 'SOLANA' , 'wrapped-solana' ))
112+
113+ if prices :
114+ for price in prices :
115+ sensors .append (PriceSensor (price ))
116+
117+ 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' ))
129+
130+ if integration == 'wallet' :
131+ #if integration == 'wallet_balance':
123132 sensors .append (WalletBalance (api_backend , wallet , 'hnt' , ['balance' , 'hnt' ], 'HNT' ,'mdi:wallet' ))
124133 sensors .append (WalletBalance (api_backend , wallet , 'iot' , ['balance' , 'iot' ], 'IOT' ,'mdi:wallet' ))
125134 sensors .append (WalletBalance (api_backend , wallet , 'sol' , ['balance' , 'solana' ], 'SOL' ,'mdi:wallet' ))
126135 sensors .append (WalletBalance (api_backend , wallet , 'mobile' , ['balance' , 'mobile' ], 'MOBILE' ,'mdi:wallet' ))
127136
137+ #if integration == 'wallet_hotspots':
128138 response = await api_backend .get_data ('hotspot-rewards2/' + str (wallet ))
129139 if response .status_code == 200 :
130140 rewards = response .json ()
@@ -142,6 +152,7 @@ async def get_sensors(wallets, prices):
142152 sensors .append (HotspotReward (api_backend , wallet , wallet , ['rewards_aggregated' , token , 'unclaimed_rewards' ], 'Unclaimed Rewards' , token , 'mdi:hand-coin-outline' ))
143153 sensors .append (HotspotReward (api_backend , wallet , wallet , ['rewards_aggregated' , token , 'total_rewards' ], 'Total Rewards' , token , 'mdi:hand-coin-outline' ))
144154
155+ #if integration == 'wallet_staking':
145156 response = await api_backend .get_data ('staking-rewards/' + str (wallet ))
146157 if response .status_code == 200 :
147158 rewards = response .json ()
@@ -153,11 +164,22 @@ async def get_sensors(wallets, prices):
153164 sensors .append (StakingRewardsToken (api_backend , wallet , token , 'mdi:hand-coin-outline' ))
154165 #pass
155166
167+ return sensors
156168
157- #_LOGGER.info(rewards)
169+ async def get_sensors_legacy (wallets , prices ):
170+ sensors = []
171+ sensors += await get_sensors ('general_token_price' , None , prices )
172+ sensors += await get_sensors ('general_stats' , None , None )
158173
159174
160- #sensors.append(HotspotReward(backendAPI, wallet, 'iot', ['rewards', ADDRESS_IOT], 'IOT', 'mdi:hand-coin-outline'))
161- #sensors.append(HotspotReward(backendAPI, wallet, 'mobile', ['rewards', ADDRESS_MOBILE], 'MOBILE', 'mdi:hand-coin-outline'))
175+ for wallet in wallets :
176+ len_wallet = len (wallet )
177+ if len_wallet < 32 or len_wallet > 44 :
178+ continue
179+
180+ sensors += await get_sensors ('wallet' , wallet , None )
181+ #sensors += await get_sensors('wallet_balance', wallet, None)
182+ #sensors += await get_sensors('wallet_hotspots', wallet, None)
183+ #sensors += await get_sensors('wallet_staking', wallet, None)
162184
163185 return sensors
0 commit comments