Include proper calculation for budget billing
This commit is contained in:
@@ -124,7 +124,7 @@ class FplApi(object):
|
|||||||
if programs["BBL"]:
|
if programs["BBL"]:
|
||||||
# budget billing
|
# budget billing
|
||||||
data["budget_bill"] = True
|
data["budget_bill"] = True
|
||||||
bblData = await self.getBBL_async(account)
|
bblData = await self.getBBL_async(account, data)
|
||||||
data.update(bblData)
|
data.update(bblData)
|
||||||
|
|
||||||
data.update(
|
data.update(
|
||||||
@@ -161,21 +161,50 @@ class FplApi(object):
|
|||||||
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
async def getBBL_async(self, account):
|
async def getBBL_async(self, account, projectedBillData):
|
||||||
_LOGGER.info(f"Getting budget billing data")
|
_LOGGER.info(f"Getting budget billing data")
|
||||||
|
data = {}
|
||||||
|
|
||||||
|
URL = "https://www.fpl.com/api/resources/account/{account}/budgetBillingGraph/premiseDetails"
|
||||||
|
async with async_timeout.timeout(TIMEOUT, loop=self._loop):
|
||||||
|
response = await self._session.get(URL.format(account=account))
|
||||||
|
if response.status == 200:
|
||||||
|
r = (await response.json())["data"]
|
||||||
|
dataList = r["graphData"]
|
||||||
|
|
||||||
|
startIndex = len(dataList) - 1
|
||||||
|
|
||||||
|
billingCharge = 0
|
||||||
|
budgetBillDeferBalance = r["defAmt"]
|
||||||
|
|
||||||
|
projectedBill = projectedBillData["projected_bill"]
|
||||||
|
asOfDays = projectedBillData["as_of_days"]
|
||||||
|
|
||||||
|
for det in dataList:
|
||||||
|
billingCharge += det["actuallBillAmt"]
|
||||||
|
|
||||||
|
calc1 = (projectedBill + billingCharge) / 12
|
||||||
|
calc2 = (1 / 12) * (budgetBillDeferBalance)
|
||||||
|
|
||||||
|
projectedBudgetBill = round(calc1 + calc2, 2)
|
||||||
|
bbDailyAvg = round(projectedBudgetBill / 30, 2)
|
||||||
|
bbAsOfDateAmt = round(projectedBudgetBill / 30 * asOfDays, 2)
|
||||||
|
|
||||||
|
data["budget_billing_daily_avg"] = bbDailyAvg
|
||||||
|
data["budget_billing_bill_to_date"] = bbAsOfDateAmt
|
||||||
|
|
||||||
|
data["budget_billing_projected_bill"] = float(projectedBudgetBill)
|
||||||
|
|
||||||
URL = "https://www.fpl.com/api/resources/account/{account}/budgetBillingGraph"
|
URL = "https://www.fpl.com/api/resources/account/{account}/budgetBillingGraph"
|
||||||
|
|
||||||
async with async_timeout.timeout(TIMEOUT, loop=self._loop):
|
async with async_timeout.timeout(TIMEOUT, loop=self._loop):
|
||||||
response = await self._session.get(URL.format(account=account))
|
response = await self._session.get(URL.format(account=account))
|
||||||
if response.status == 200:
|
if response.status == 200:
|
||||||
r = (await response.json())["data"]
|
r = (await response.json())["data"]
|
||||||
data = {}
|
|
||||||
data["projected_budget_bill"] = float(r["bbAmt"])
|
|
||||||
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"])
|
||||||
return data
|
|
||||||
|
|
||||||
return []
|
return data
|
||||||
|
|
||||||
async def getDataFromEnergyService(self, account, premise, lastBilledDate):
|
async def getDataFromEnergyService(self, account, premise, lastBilledDate):
|
||||||
_LOGGER.info(f"Getting data from energy service")
|
_LOGGER.info(f"Getting data from energy service")
|
||||||
|
|||||||
@@ -87,8 +87,8 @@ class FplSensor(Entity):
|
|||||||
if type(data) is dict:
|
if type(data) is dict:
|
||||||
if "budget_bill" in data.keys():
|
if "budget_bill" in data.keys():
|
||||||
if data["budget_bill"]:
|
if data["budget_bill"]:
|
||||||
if "projected_budget_bill" in data.keys():
|
if "budget_billing_projected_bill" in data.keys():
|
||||||
state = data["projected_budget_bill"]
|
state = data["budget_billing_projected_bill"]
|
||||||
else:
|
else:
|
||||||
if "projected_bill" in data.keys():
|
if "projected_bill" in data.keys():
|
||||||
state = data["projected_bill"]
|
state = data["projected_bill"]
|
||||||
|
|||||||
Reference in New Issue
Block a user