added exceptions and get more values from api

This commit is contained in:
Yordan Suarez
2022-08-17 18:30:07 -04:00
parent 731ef9444a
commit d9d27f7ae6
2 changed files with 29 additions and 27 deletions

View File

@@ -107,7 +107,7 @@ class FplMainRegionApiClient:
try: try:
async with async_timeout.timeout(TIMEOUT): async with async_timeout.timeout(TIMEOUT):
await self.session.get(URL_LOGOUT) await self.session.get(URL_LOGOUT)
except Exception: except:
pass pass
async def update(self, account) -> dict: async def update(self, account) -> dict:
@@ -216,7 +216,7 @@ class FplMainRegionApiClient:
data["daily_avg"] = dailyAvg data["daily_avg"] = dailyAvg
data["avg_high_temp"] = avgHighTemp data["avg_high_temp"] = avgHighTemp
except Exception: except:
pass pass
return data return data
@@ -225,6 +225,7 @@ class FplMainRegionApiClient:
"""Get budget billing data""" """Get budget billing data"""
_LOGGER.info("Getting budget billing data") _LOGGER.info("Getting budget billing data")
data = {} data = {}
try: try:
async with async_timeout.timeout(TIMEOUT): async with async_timeout.timeout(TIMEOUT):
response = await self.session.get( response = await self.session.get(
@@ -257,10 +258,6 @@ class FplMainRegionApiClient:
data["budget_billing_projected_bill"] = float(projectedBudgetBill) data["budget_billing_projected_bill"] = float(projectedBudgetBill)
except Exception as e:
_LOGGER.error("Error getting BBL: %s", e)
try:
async with async_timeout.timeout(TIMEOUT): async with async_timeout.timeout(TIMEOUT):
response = await self.session.get( response = await self.session.get(
URL_BUDGET_BILLING_GRAPH.format(account=account) URL_BUDGET_BILLING_GRAPH.format(account=account)
@@ -269,9 +266,8 @@ class FplMainRegionApiClient:
r = (await response.json())["data"] r = (await response.json())["data"]
data["bill_to_date"] = float(r["eleAmt"]) data["bill_to_date"] = float(r["eleAmt"])
data["defered_amount"] = float(r["defAmt"]) data["defered_amount"] = float(r["defAmt"])
except:
except Exception as e: pass
_LOGGER.error("Error getting BBL: %s", e)
return data return data
@@ -351,8 +347,8 @@ class FplMainRegionApiClient:
r["CurrentUsage"]["dailyAverageKWH"] r["CurrentUsage"]["dailyAverageKWH"]
) )
data["billToDateKWH"] = float(r["CurrentUsage"]["billToDateKWH"]) data["billToDateKWH"] = float(r["CurrentUsage"]["billToDateKWH"])
data["recMtrReading"] = int(r["CurrentUsage"]["recMtrReading"]) data["recMtrReading"] = int(r["CurrentUsage"]["recMtrReading"] or 0)
data["delMtrReading"] = int(r["CurrentUsage"]["delMtrReading"]) data["delMtrReading"] = int(r["CurrentUsage"]["delMtrReading"] or 0)
data["billStartDate"] = r["CurrentUsage"]["billStartDate"] data["billStartDate"] = r["CurrentUsage"]["billStartDate"]
except: except:
pass pass
@@ -365,6 +361,7 @@ class FplMainRegionApiClient:
JSON = {"startDate": str(lastBilledDate.strftime("%m%d%Y"))} JSON = {"startDate": str(lastBilledDate.strftime("%m%d%Y"))}
data = {} data = {}
try: try:
async with async_timeout.timeout(TIMEOUT): async with async_timeout.timeout(TIMEOUT):
response = await self.session.post( response = await self.session.post(
@@ -381,8 +378,7 @@ class FplMainRegionApiClient:
else: else:
rr = full rr = full
data[e["category"].replace(" ", "_")] = rr data[e["category"].replace(" ", "_")] = rr
except:
except Exception:
pass pass
return {"energy_percent_by_applicance": data} return {"energy_percent_by_applicance": data}

View File

@@ -1,5 +1,5 @@
"""FPL Northwest data collection api client""" """FPL Northwest data collection api client"""
from datetime import datetime from datetime import datetime, timedelta
import logging import logging
import async_timeout import async_timeout
import boto3 import boto3
@@ -143,25 +143,31 @@ class FplNorthwestRegionApiClient:
programInfo = accountSumary["programInfo"] programInfo = accountSumary["programInfo"]
result["budget_bill"] = False result["budget_bill"] = False
result["bill_to_date"] = billAndMetterInfo["asOfDateAmount"]
result["projected_bill"] = billAndMetterInfo["projBillAmount"] result["projected_bill"] = float(billAndMetterInfo["projBillAmount"] or 0)
result["projectedKWH"] = billAndMetterInfo["projBillKWH"] result["projectedKWH"] = int(billAndMetterInfo["projBillKWH"] or 0)
result["bill_to_date"] = billAndMetterInfo["asOfDateUsage"] result["bill_to_date"] = float(billAndMetterInfo["asOfDateAmount"] or 0)
result["billToDateKWH"] = billAndMetterInfo["asOfDateUsage"] result["billToDateKWH"] = int(billAndMetterInfo["asOfDateUsage"] or 0)
result["daily_avg"] = billAndMetterInfo["dailyAvgAmount"] result["daily_avg"] = float(billAndMetterInfo["dailyAvgAmount"] or 0)
result["dailyAverageKWH"] = billAndMetterInfo["dailyAvgKwh"] result["dailyAverageKWH"] = int(billAndMetterInfo["dailyAvgKwh"] or 0)
result["billStartDate"] = programInfo["currentBillDate"] start = datetime.fromisoformat(programInfo["currentBillDate"])
result["next_bill_date"] = programInfo["nextBillDate"] # + timedelta(days=1)
start = datetime.fromisoformat(result["billStartDate"]) end = datetime.fromisoformat(programInfo["nextBillDate"])
end = datetime.fromisoformat(result["next_bill_date"])
today = datetime.fromisoformat(data["today"]) today = datetime.fromisoformat(data["today"])
result["service_days"] = (end - start).days # result["billStartDate"] = programInfo["currentBillDate"]
result["as_of_days"] = (today - start).days result["current_bill_date"] = start.strftime("%Y-%m-%d")
result["next_bill_date"] = programInfo["nextBillDate"]
service_days = (end - start).days
as_of_days = (today - start).days
result["service_days"] = service_days
result["as_of_days"] = as_of_days
result["remaining_days"] = service_days - as_of_days
return result return result