validating some other fields sometimes not present
This commit is contained in:
@@ -41,7 +41,7 @@ class FplApi(object):
|
|||||||
self._loop = loop
|
self._loop = loop
|
||||||
self._session = None
|
self._session = None
|
||||||
|
|
||||||
async def get_data(self):
|
async def get_data(self) -> dict:
|
||||||
self._session = aiohttp.ClientSession()
|
self._session = aiohttp.ClientSession()
|
||||||
data = {}
|
data = {}
|
||||||
data["accounts"] = []
|
data["accounts"] = []
|
||||||
@@ -115,7 +115,7 @@ class FplApi(object):
|
|||||||
# self._premise_number = js["data"]["selectedAccount"]["data"]["acctSecSettings"]["premiseNumber"]
|
# self._premise_number = js["data"]["selectedAccount"]["data"]["acctSecSettings"]["premiseNumber"]
|
||||||
return result
|
return result
|
||||||
|
|
||||||
async def __async_get_data(self, account):
|
async def __async_get_data(self, account) -> dict:
|
||||||
_LOGGER.info(f"Getting Data")
|
_LOGGER.info(f"Getting Data")
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ class FplApi(object):
|
|||||||
data.update(await self.__getDataFromApplianceUsage(account, currentBillDate))
|
data.update(await self.__getDataFromApplianceUsage(account, currentBillDate))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
async def __getFromProjectedBill(self, account, premise, currentBillDate):
|
async def __getFromProjectedBill(self, account, premise, currentBillDate) -> dict:
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -192,7 +192,7 @@ class FplApi(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
|
|
||||||
projectedBillData = (await response.json())["data"]
|
projectedBillData = (await response.json())["data"]
|
||||||
|
|
||||||
billToDate = float(projectedBillData["billToDate"])
|
billToDate = float(projectedBillData["billToDate"])
|
||||||
@@ -203,13 +203,13 @@ class FplApi(object):
|
|||||||
data["bill_to_date"] = billToDate
|
data["bill_to_date"] = billToDate
|
||||||
data["projected_bill"] = projectedBill
|
data["projected_bill"] = projectedBill
|
||||||
data["daily_avg"] = dailyAvg
|
data["daily_avg"] = dailyAvg
|
||||||
data["avg_high_temp"] = avgHighTemp
|
data["avg_high_temp"] = avgHighTemp
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
async def __getBBL_async(self, account, projectedBillData):
|
async def __getBBL_async(self, account, projectedBillData) -> dict:
|
||||||
_LOGGER.info(f"Getting budget billing data")
|
_LOGGER.info(f"Getting budget billing data")
|
||||||
data = {}
|
data = {}
|
||||||
|
|
||||||
@@ -295,7 +295,12 @@ class FplApi(object):
|
|||||||
totalPowerUsage = 0
|
totalPowerUsage = 0
|
||||||
if "data" in r["DailyUsage"]:
|
if "data" in r["DailyUsage"]:
|
||||||
for daily in r["DailyUsage"]["data"]:
|
for daily in r["DailyUsage"]["data"]:
|
||||||
if "kwhUsed" in daily.keys():
|
if (
|
||||||
|
"kwhUsed" in daily.keys()
|
||||||
|
and "billingCharge" in daily.keys()
|
||||||
|
and "date" in daily.keys()
|
||||||
|
and "averageHighTemperature" in daily.keys()
|
||||||
|
):
|
||||||
dailyUsage.append(
|
dailyUsage.append(
|
||||||
{
|
{
|
||||||
"usage": daily["kwhUsed"],
|
"usage": daily["kwhUsed"],
|
||||||
@@ -311,7 +316,7 @@ class FplApi(object):
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
async def __getDataFromApplianceUsage(self, account, lastBilledDate):
|
async def __getDataFromApplianceUsage(self, account, lastBilledDate) -> dict:
|
||||||
_LOGGER.info(f"Getting data from applicance usage")
|
_LOGGER.info(f"Getting data from applicance usage")
|
||||||
URL = "https://www.fpl.com/dashboard-api/resources/account/{account}/applianceUsage/{account}"
|
URL = "https://www.fpl.com/dashboard-api/resources/account/{account}/applianceUsage/{account}"
|
||||||
JSON = {"startDate": str(lastBilledDate.strftime("%m%d%Y"))}
|
JSON = {"startDate": str(lastBilledDate.strftime("%m%d%Y"))}
|
||||||
@@ -323,7 +328,7 @@ class FplApi(object):
|
|||||||
)
|
)
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
electric = (await response.json())["data"]["electric"]
|
electric = (await response.json())["data"]["electric"]
|
||||||
|
|
||||||
full = 100
|
full = 100
|
||||||
for e in electric:
|
for e in electric:
|
||||||
rr = round(float(e["percentageDollar"]))
|
rr = round(float(e["percentageDollar"]))
|
||||||
@@ -332,7 +337,7 @@ class FplApi(object):
|
|||||||
else:
|
else:
|
||||||
rr = full
|
rr = full
|
||||||
data[e["category"].replace(" ", "_")] = rr
|
data[e["category"].replace(" ", "_")] = rr
|
||||||
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user