forked from tolwi/hassio-ecoflow-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.init.py
56 lines (48 loc) · 1.56 KB
/
debug.init.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import asyncio
import logging
import os
from types import MappingProxyType
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from custom_components.ecoflow_cloud.devices.powerkit import PowerKit
from custom_components.ecoflow_cloud.entities import BaseSensorEntity
from custom_components.ecoflow_cloud import EcoflowAuthentication, EcoflowMQTTClient
logging.basicConfig(level=logging.INFO)
_LOGGER = logging.getLogger(__name__)
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
async def main():
data = MappingProxyType(
{
"type": "powerkit",
"device_id": os.environ['ecoflowSn']
}
)
config = ConfigEntry(
version='1.0.0',
minor_version='1',
domain='homeassistant.local',
title='debugEcoflow',
data=data,
source='',
options= MappingProxyType(
{
"refresh_period_sec": 1
})
)
auth = EcoflowAuthentication(os.environ['ecoflowUserName'], os.environ['ecoflowPassword'])
auth.authorize()
home = HomeAssistant('./')
client = EcoflowMQTTClient(home, config, auth)
powerkit = PowerKit()
sensors = powerkit.sensors(client)
client.data.params_observable().subscribe(lambda v: updateSensors(v))
def updateSensors(data: dict[str, any]):
for v in sensors:
v.hass = home
v._updated(data)
_LOGGER.info(v.name)
_LOGGER.info(v._attr_native_value)
while True:
await asyncio.sleep(1)
asyncio.run(main())