Skip to content

Commit

Permalink
Add class P110 with getEnergyUsage()
Browse files Browse the repository at this point in the history
P110 inherits from P100
  • Loading branch information
realzoulou committed Dec 29, 2021
1 parent 345eacc commit cbc3ff7
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions PyP100/PyP110.py
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

0 comments on commit cbc3ff7

Please sign in to comment.