-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add class P110 with getEnergyUsage()
P110 inherits from P100
- Loading branch information
1 parent
345eacc
commit cbc3ff7
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from PyP100 import PyP100 | ||
|
||
import json | ||
import logging | ||
import requests | ||
import time | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
class P110(PyP100.P100): | ||
|
||
def getEnergyUsage(self): | ||
URL = f"http://{self.ipAddress}/app?token={self.token}" | ||
Payload = { | ||
"method": "get_energy_usage", | ||
"requestTimeMils": int(round(time.time() * 1000)), | ||
} | ||
|
||
headers = { | ||
"Cookie": self.cookie | ||
} | ||
|
||
EncryptedPayload = self.tpLinkCipher.encrypt(json.dumps(Payload)) | ||
|
||
SecurePassthroughPayload = { | ||
"method":"securePassthrough", | ||
"params":{ | ||
"request": EncryptedPayload | ||
} | ||
} | ||
_LOGGER.debug("getEnergyUsage %s", self.ipAddress) | ||
r = requests.post(URL, json=SecurePassthroughPayload, headers=headers) | ||
|
||
decryptedResponse = self.tpLinkCipher.decrypt(r.json()["result"]["response"]) | ||
|
||
return decryptedResponse |