Skip to content

Commit

Permalink
Fix power module when using firmware 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Elanis committed Nov 30, 2023
1 parent aebc077 commit 56f86f5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 33 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
Power monitoring using TPLink Tapo P110
Power monitoring using TPLink Tapo P110

Needs to manually run `pip install --force-reinstall git+https://github.com/almottier/TapoP100.git@778123747e31f1cdea2f069fecb0ae84b536bf08`
26 changes: 1 addition & 25 deletions getData.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,7 @@

class P110B(PyP110.P110):
def getEnergyData(self, startT, endT, intervalT):
URL = f"http://{self.ipAddress}/app?token={self.token}"
Payload = {
"method": "get_energy_data",
"params":{ "end_timestamp": endT, "interval": intervalT, "start_timestamp": startT},
"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 = self.session.post(URL, json=SecurePassthroughPayload, headers=headers, timeout=2)

decryptedResponse = self.tpLinkCipher.decrypt(r.json()["result"]["response"])

return json.loads(decryptedResponse)
return self.request("get_energy_data", { "end_timestamp": endT, "interval": intervalT, "start_timestamp": startT})

###################

Expand Down
14 changes: 7 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async function getData(ip, start, end, interval) {
from: pastMidnight.getTime(),
to: currentDateMidnight.getTime(),
interval: INTERVAL_HOURLY,
data: hourly.result.data
data: hourly.data
});
}

Expand All @@ -103,8 +103,8 @@ async function getData(ip, start, end, interval) {

if(!(await AppDataManager.exists(MODULE_NAME, fileName))) {
const daily = await getData(ip, firstOfMonthMidnight, currentDateMidnight, INTERVAL_DAILY);
daily.result.start_timestamp_eq_date = new Date(daily.result.start_timestamp * 1000);
daily.result.end_timestamp_eq_date = new Date(daily.result.end_timestamp * 1000);
daily.start_timestamp_eq_date = new Date(daily.start_timestamp * 1000);
daily.end_timestamp_eq_date = new Date(daily.end_timestamp * 1000);


// Save to ip-daily-from-to.json
Expand All @@ -114,7 +114,7 @@ async function getData(ip, start, end, interval) {
from: firstOfMonthMidnight.getTime(),
to: currentDateMidnight.getTime(),
interval: INTERVAL_DAILY,
data: daily.result.data.slice(0, (currentDateMidnight.getTime() - firstOfMonthMidnight.getTime()) / (INTERVAL_DAILY * MIN_TO_MS))
data: daily.data.slice(0, (currentDateMidnight.getTime() - firstOfMonthMidnight.getTime()) / (INTERVAL_DAILY * MIN_TO_MS))
});
}

Expand All @@ -127,8 +127,8 @@ async function getData(ip, start, end, interval) {

if(!(await AppDataManager.exists(MODULE_NAME, fileName))) {
const monthly = await getData(ip, firstOfYearMidnight, currentDateMidnight, INTERVAL_MONTHLY);
monthly.result.start_timestamp_eq_date = new Date(monthly.result.start_timestamp * 1000);
monthly.result.end_timestamp_eq_date = new Date(monthly.result.end_timestamp * 1000);
monthly.start_timestamp_eq_date = new Date(monthly.start_timestamp * 1000);
monthly.end_timestamp_eq_date = new Date(monthly.end_timestamp * 1000);


// Save to ip-monthly-from-to.json
Expand All @@ -138,7 +138,7 @@ async function getData(ip, start, end, interval) {
from: firstOfYearMidnight.getTime(),
to: currentDateMidnight.getTime(),
interval: INTERVAL_MONTHLY,
data: monthly.result.data.slice(0, (currentDateMidnight.getTime() - firstOfYearMidnight.getTime()) / (INTERVAL_MONTHLY * MIN_TO_MS))
data: monthly.data.slice(0, (currentDateMidnight.getTime() - firstOfYearMidnight.getTime()) / (INTERVAL_MONTHLY * MIN_TO_MS))
});
}
}
Expand Down

0 comments on commit 56f86f5

Please sign in to comment.