-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtest.py
84 lines (65 loc) · 2.06 KB
/
test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
""" "Test the component."""
import json
import logging
import time
from lghorizon import LGHorizonApi
api: LGHorizonApi
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(levelname)s - %(message)s",
)
_Logger = logging.getLogger()
file_handler = logging.FileHandler("logfile.log", mode="w")
file_handler.setLevel(logging.DEBUG)
_Logger.addHandler(file_handler)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
_Logger.addHandler(console_handler)
secrets: dict[str, str] = None
def read_secrets(file_path):
"""Read secrets from file."""
try:
with open(file_path, "r", encoding="UTF-8") as file:
return json.load(file)
except FileNotFoundError:
print(f"Error: Secrets file not found at {file_path}")
return {}
except json.JSONDecodeError:
print(f"Error: Unable to decode JSON in {file_path}")
return {}
def event_loop():
"""Default event loop."""
while True:
time.sleep(1) # Simulate some work
# Check for a breaking condition
if break_condition():
break
def break_condition():
"""Break event loop on conditions."""
# Implement your breaking condition logic here
return False # Change this condition based on your requirements
if __name__ == "__main__":
try:
secrets = read_secrets("secrets.json")
refresh_token: str = None
if "refresh_token" in secrets:
refresh_token = secrets["refresh_token"]
profile_id: str = None
if "profile_id" in secrets:
profile_id = secrets["profile_id"]
api = LGHorizonApi(
secrets["username"],
secrets["password"],
secrets["country"],
# identifier="DTV3907048",
refresh_token=refresh_token,
profile_id=profile_id,
)
api.connect()
event_loop()
except KeyboardInterrupt:
print("\nScript interrupted by user.")
finally:
print("Script is exiting.")
if api:
api.disconnect()