1
1
import asyncio
2
+ import json
2
3
import logging
3
4
import os
4
5
import sys
@@ -48,27 +49,26 @@ async def initialize(self):
48
49
self ._api = RestAPIv2 (hass , self ._config_manager )
49
50
await self ._api .initialize ()
50
51
51
- if self ._api .is_online :
52
-
53
- await self ._api .update ([PRODUCT_MAIN_ENDPOINT ])
52
+ await self ._api .update ([PRODUCT_MAIN_ENDPOINT ])
54
53
55
- main_device = self ._api .data .get (PRINTER_MAIN_DEVICE )
56
- model = main_device .get (MODEL_PROPERTY )
57
- title = f"{ model } ({ self ._api .config_data .hostname } )"
54
+ main_device = self ._api .data .get (PRINTER_MAIN_DEVICE )
55
+ model = main_device .get (MODEL_PROPERTY )
56
+ title = f"{ model } ({ self ._api .config_data .hostname } )"
58
57
59
- print ( title )
58
+ _LOGGER . info ( f"Title: { title } " )
60
59
61
- for i in range ( 0 , 1 ):
62
- # self._api.config_data.update({
63
- # key: os.environ.get(key) if i % 2 == 0 or key != "host" else "127.0.0.1"
64
- # for key in self._api.config_data.to_dict()
65
- # })
60
+ def _modify_connection ( self , index : int ):
61
+ self ._api .config_data .update ({
62
+ key : os .environ .get (key ) if index % 2 == 0 or key != "host" else "127.0.0.1"
63
+ for key in self ._api .config_data .to_dict ()
64
+ })
66
65
66
+ async def update (self , times : int ):
67
+ if self ._api .is_online :
68
+ for i in range (0 , times ):
67
69
await self ._api .update ()
68
70
69
- # print(json.dumps(self._api.data_config, indent=4))
70
- # print(json.dumps(self._api.data, indent=4))
71
- # print(json.dumps(self._api.data[PRINTER_MAIN_DEVICE], indent=4))
71
+ _LOGGER .debug (json .dumps (self ._api .data [PRINTER_MAIN_DEVICE ], indent = 4 ))
72
72
73
73
await asyncio .sleep (10 )
74
74
@@ -83,6 +83,7 @@ async def initialize(self):
83
83
84
84
try :
85
85
loop .run_until_complete (instance .initialize ())
86
+ loop .run_until_complete (instance .update (1 ))
86
87
87
88
except KeyboardInterrupt :
88
89
_LOGGER .info ("Aborted" )
0 commit comments