Refactor logging to use pp function for improved consistency
This commit is contained in:
@@ -2,9 +2,9 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import datetime
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import datetime
|
|
||||||
|
|
||||||
from kasa import Discover
|
from kasa import Discover
|
||||||
from kasa.exceptions import KasaException
|
from kasa.exceptions import KasaException
|
||||||
@@ -37,7 +37,7 @@ class TplinkT315:
|
|||||||
await self.hubDev.update()
|
await self.hubDev.update()
|
||||||
except KasaException as e:
|
except KasaException as e:
|
||||||
self.hubDev = None
|
self.hubDev = None
|
||||||
print(f"[TplinkT315::connect] Hub Error: {e}")
|
pp(f"[TplinkT315::connect] Hub Error: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -45,7 +45,7 @@ class TplinkT315:
|
|||||||
await self.t315Dev.update()
|
await self.t315Dev.update()
|
||||||
except KasaException as e:
|
except KasaException as e:
|
||||||
self.t315Dev = None
|
self.t315Dev = None
|
||||||
print(f"[TplinkT315::connect] Device Error: {e}")
|
pp(f"[TplinkT315::connect] Device Error: {e}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
@@ -70,6 +70,7 @@ class TplinkT315:
|
|||||||
if self.t315Dev is None:
|
if self.t315Dev is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
await self.hubDev.update()
|
||||||
await self.t315Dev.update()
|
await self.t315Dev.update()
|
||||||
|
|
||||||
featuresOfTempDev = self.t315Dev.features
|
featuresOfTempDev = self.t315Dev.features
|
||||||
@@ -92,7 +93,7 @@ def getSecrets(fileanme):
|
|||||||
|
|
||||||
return secrets
|
return secrets
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print(f"File not found: {fileanme}")
|
pp(f"File not found: {fileanme}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -100,10 +101,10 @@ def getDatetime():
|
|||||||
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
async def main(configs):
|
async def main(configs):
|
||||||
print(f"Start: {getDatetime()}")
|
pp(f"Start: {getDatetime()}")
|
||||||
secrect = getSecrets(configs.get("secret_filepath", DEFAULT_POLLING_INTERVAL))
|
secrect = getSecrets(configs.get("secret_filepath", DEFAULT_POLLING_INTERVAL))
|
||||||
if secrect is None:
|
if secrect is None:
|
||||||
print(f'Cannot read secret file({configs.get("secret_filepath", DEFAULT_POLLING_INTERVAL)})')
|
pp(f'Cannot read secret file({configs.get("secret_filepath", DEFAULT_POLLING_INTERVAL)})')
|
||||||
return
|
return
|
||||||
|
|
||||||
hubIp = secrect["ip"]
|
hubIp = secrect["ip"]
|
||||||
@@ -113,7 +114,7 @@ async def main(configs):
|
|||||||
|
|
||||||
t315 = TplinkT315(hubIp, username, password, devName)
|
t315 = TplinkT315(hubIp, username, password, devName)
|
||||||
if await t315.connect() is False:
|
if await t315.connect() is False:
|
||||||
print(f"Failed to connect to {hubIp}")
|
pp(f"Failed to connect to {hubIp}")
|
||||||
return
|
return
|
||||||
|
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
@@ -150,11 +151,11 @@ async def main(configs):
|
|||||||
|
|
||||||
time.sleep(pollingInterval)
|
time.sleep(pollingInterval)
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\nUser stopped process.")
|
pp("\nUser stopped process.")
|
||||||
break
|
break
|
||||||
|
|
||||||
await t315.disconnect()
|
await t315.disconnect()
|
||||||
print(f"End: {getDatetime()}")
|
pp(f"End: {getDatetime()}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user