34 lines
976 B
Python
34 lines
976 B
Python
import asyncio
|
|
|
|
from InverterData import InverterData
|
|
|
|
|
|
class Inverter:
|
|
def __init__(self, queue: asyncio.Queue, cloud_connection, inverter_id):
|
|
self._queue = queue
|
|
self.inverter_id = inverter_id
|
|
self.cloud_connection = cloud_connection
|
|
self.gather_data = False
|
|
|
|
async def start(self):
|
|
self.gather_data = True
|
|
await self.gather()
|
|
|
|
async def gather(self):
|
|
while self.gather_data:
|
|
realtime_data: dict = self.cloud_connection.get_realtime_data(self.inverter_id)
|
|
rt_data = InverterData(
|
|
self.inverter_id,
|
|
realtime_data
|
|
)
|
|
statistic: dict = self.cloud_connection.get_statistic_data(self.inverter_id)
|
|
st_data = InverterData(
|
|
self.inverter_id,
|
|
statistic
|
|
)
|
|
await self._queue.put(rt_data)
|
|
await self._queue.put(st_data)
|
|
await asyncio.sleep(60)
|
|
|
|
|