Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7e0edbbec | ||
|
|
26ab05ca30 |
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime, timedelta
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import async_timeout
|
import async_timeout
|
||||||
|
|
||||||
@@ -274,7 +274,7 @@ class FplMainRegionApiClient:
|
|||||||
async def __getDataFromEnergyService(
|
async def __getDataFromEnergyService(
|
||||||
self, account, premise, lastBilledDate
|
self, account, premise, lastBilledDate
|
||||||
) -> dict:
|
) -> dict:
|
||||||
_LOGGER.info("Getting energy service data")
|
_LOGGER.info("Getting data from energy service")
|
||||||
|
|
||||||
date = str(lastBilledDate.strftime("%m%d%Y"))
|
date = str(lastBilledDate.strftime("%m%d%Y"))
|
||||||
JSON = {
|
JSON = {
|
||||||
@@ -357,7 +357,7 @@ class FplMainRegionApiClient:
|
|||||||
|
|
||||||
async def __getDataFromApplianceUsage(self, account, lastBilledDate) -> dict:
|
async def __getDataFromApplianceUsage(self, account, lastBilledDate) -> dict:
|
||||||
"""get data from appliance usage"""
|
"""get data from appliance usage"""
|
||||||
_LOGGER.info("Getting appliance usage data")
|
_LOGGER.info("Getting data from appliance usage")
|
||||||
|
|
||||||
JSON = {"startDate": str(lastBilledDate.strftime("%m%d%Y"))}
|
JSON = {"startDate": str(lastBilledDate.strftime("%m%d%Y"))}
|
||||||
data = {}
|
data = {}
|
||||||
|
|||||||
@@ -11,7 +11,3 @@ class ForceChangePasswordException(WarrantException):
|
|||||||
|
|
||||||
class TokenVerificationException(WarrantException):
|
class TokenVerificationException(WarrantException):
|
||||||
"""Raised when token verification fails."""
|
"""Raised when token verification fails."""
|
||||||
|
|
||||||
|
|
||||||
class NoTerrytoryAvailableException(Exception):
|
|
||||||
"""Thrown when not possible to determine user territory"""
|
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ _LOGGER = logging.getLogger(__package__)
|
|||||||
URL_TERRITORY = API_HOST + "/cs/customer/v1/territoryid/public/territory"
|
URL_TERRITORY = API_HOST + "/cs/customer/v1/territoryid/public/territory"
|
||||||
|
|
||||||
|
|
||||||
|
class NoTerrytoryAvailableException(Exception):
|
||||||
|
"""Thrown when not possible to determine user territory"""
|
||||||
|
|
||||||
|
|
||||||
class FplApi:
|
class FplApi:
|
||||||
"""A class for getting energy usage information from Florida Power & Light."""
|
"""A class for getting energy usage information from Florida Power & Light."""
|
||||||
|
|
||||||
@@ -54,8 +58,7 @@ class FplApi:
|
|||||||
|
|
||||||
territoryArray = json_data["data"]["territory"]
|
territoryArray = json_data["data"]["territory"]
|
||||||
if len(territoryArray) == 0:
|
if len(territoryArray) == 0:
|
||||||
# returns main region by default in case no regions found
|
raise NoTerrytoryAvailableException()
|
||||||
return FPL_MAINREGION
|
|
||||||
|
|
||||||
self._territory = territoryArray[0]
|
self._territory = territoryArray[0]
|
||||||
return territoryArray[0]
|
return territoryArray[0]
|
||||||
|
|||||||
@@ -12,12 +12,12 @@ class DailyAverageSensor(FplMoneyEntity):
|
|||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
budget = self.getData("budget_bill")
|
budget = self.getData("budget_bill")
|
||||||
daily_avg = self.getData("daily_avg")
|
budget_billing_projected_bill = self.getData("budget_billing_daily_avg")
|
||||||
|
|
||||||
if budget and daily_avg is not None:
|
if budget and budget_billing_projected_bill is not None:
|
||||||
self._attr_native_value = daily_avg
|
return self.getData("budget_billing_daily_avg")
|
||||||
|
|
||||||
return self._attr_native_value
|
return self.getData("daily_avg")
|
||||||
|
|
||||||
def customAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
@@ -34,12 +34,7 @@ class BudgetDailyAverageSensor(FplMoneyEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
budget_billing_daily_avg = self.getData("budget_billing_daily_avg")
|
return self.getData("budget_billing_daily_avg")
|
||||||
|
|
||||||
if budget_billing_daily_avg is not None:
|
|
||||||
self._attr_native_value = budget_billing_daily_avg
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
def customAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
@@ -56,12 +51,7 @@ class ActualDailyAverageSensor(FplMoneyEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
daily_avg = self.getData("daily_avg")
|
return self.getData("daily_avg")
|
||||||
|
|
||||||
if daily_avg is not None:
|
|
||||||
self._attr_native_value = daily_avg
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
def customAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
|
|||||||
@@ -19,9 +19,9 @@ class FplDailyUsageSensor(FplMoneyEntity):
|
|||||||
data = self.getData("daily_usage")
|
data = self.getData("daily_usage")
|
||||||
|
|
||||||
if data is not None and len(data) > 0 and "cost" in data[-1].keys():
|
if data is not None and len(data) > 0 and "cost" in data[-1].keys():
|
||||||
self._attr_native_value = data[-1]["cost"]
|
return data[-1]["cost"]
|
||||||
|
|
||||||
return self._attr_native_value
|
return None
|
||||||
|
|
||||||
def customAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
@@ -48,9 +48,9 @@ class FplDailyUsageKWHSensor(FplEnergyEntity):
|
|||||||
data = self.getData("daily_usage")
|
data = self.getData("daily_usage")
|
||||||
|
|
||||||
if data is not None and len(data) > 0 and "usage" in data[-1].keys():
|
if data is not None and len(data) > 0 and "usage" in data[-1].keys():
|
||||||
self._attr_native_value = data[-1]["usage"]
|
return data[-1]["usage"]
|
||||||
|
|
||||||
return self._attr_native_value
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def last_reset(self) -> datetime | None:
|
def last_reset(self) -> datetime | None:
|
||||||
@@ -83,11 +83,9 @@ class FplDailyReceivedKWHSensor(FplEnergyEntity):
|
|||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
data = self.getData("daily_usage")
|
data = self.getData("daily_usage")
|
||||||
|
|
||||||
if data is not None and len(data) > 0 and "netReceivedKwh" in data[-1].keys():
|
if data is not None and len(data) > 0 and "netReceivedKwh" in data[-1].keys():
|
||||||
self._attr_native_value = data[-1]["netReceivedKwh"]
|
return data[-1]["netReceivedKwh"]
|
||||||
|
return 0
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
def customAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
@@ -112,11 +110,9 @@ class FplDailyDeliveredKWHSensor(FplEnergyEntity):
|
|||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
data = self.getData("daily_usage")
|
data = self.getData("daily_usage")
|
||||||
|
|
||||||
if data is not None and len(data) > 0 and "netDeliveredKwh" in data[-1].keys():
|
if data is not None and len(data) > 0 and "netDeliveredKwh" in data[-1].keys():
|
||||||
self._attr_native_value = data[-1]["netDeliveredKwh"]
|
return data[-1]["netDeliveredKwh"]
|
||||||
|
return 0
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
def customAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
|
|||||||
@@ -11,12 +11,7 @@ class CurrentBillDateSensor(FplDateEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
current_bill_date = self.getData("current_bill_date")
|
return datetime.date.fromisoformat(self.getData("current_bill_date"))
|
||||||
|
|
||||||
if current_bill_date is not None:
|
|
||||||
self._attr_native_value = datetime.date.fromisoformat(current_bill_date)
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
|
|
||||||
class NextBillDateSensor(FplDateEntity):
|
class NextBillDateSensor(FplDateEntity):
|
||||||
@@ -27,12 +22,7 @@ class NextBillDateSensor(FplDateEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
next_bill_date = self.getData("next_bill_date")
|
return datetime.date.fromisoformat(self.getData("next_bill_date"))
|
||||||
|
|
||||||
if next_bill_date is not None:
|
|
||||||
self._attr_native_value = datetime.date.fromisoformat(next_bill_date)
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
|
|
||||||
class ServiceDaysSensor(FplDayEntity):
|
class ServiceDaysSensor(FplDayEntity):
|
||||||
@@ -43,12 +33,7 @@ class ServiceDaysSensor(FplDayEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
service_days = self.getData("service_days")
|
return self.getData("service_days")
|
||||||
|
|
||||||
if service_days is not None:
|
|
||||||
self._attr_native_value = service_days
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
|
|
||||||
class AsOfDaysSensor(FplDayEntity):
|
class AsOfDaysSensor(FplDayEntity):
|
||||||
@@ -59,12 +44,7 @@ class AsOfDaysSensor(FplDayEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
as_of_days = self.getData("as_of_days")
|
return self.getData("as_of_days")
|
||||||
|
|
||||||
if as_of_days is not None:
|
|
||||||
self._attr_native_value = as_of_days
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
|
|
||||||
class RemainingDaysSensor(FplDayEntity):
|
class RemainingDaysSensor(FplDayEntity):
|
||||||
@@ -75,9 +55,4 @@ class RemainingDaysSensor(FplDayEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
remaining_days = self.getData("remaining_days")
|
return self.getData("remaining_days")
|
||||||
|
|
||||||
if remaining_days is not None:
|
|
||||||
self._attr_native_value = remaining_days
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|||||||
@@ -15,12 +15,7 @@ class ProjectedKWHSensor(FplEnergyEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
projectedKWH = self.getData("projectedKWH")
|
return self.getData("projectedKWH")
|
||||||
|
|
||||||
if projectedKWH is not None:
|
|
||||||
self._attr_native_value = projectedKWH
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
def customAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
@@ -37,12 +32,7 @@ class DailyAverageKWHSensor(FplEnergyEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
dailyAverageKWH = self.getData("dailyAverageKWH")
|
return self.getData("dailyAverageKWH")
|
||||||
|
|
||||||
if dailyAverageKWH is not None:
|
|
||||||
self._attr_native_value = dailyAverageKWH
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
def customAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
@@ -59,12 +49,7 @@ class BillToDateKWHSensor(FplEnergyEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
billToDateKWH = self.getData("billToDateKWH")
|
return self.getData("billToDateKWH")
|
||||||
|
|
||||||
if billToDateKWH is not None:
|
|
||||||
self._attr_native_value = billToDateKWH
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
def customAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
@@ -88,12 +73,7 @@ class NetReceivedKWHSensor(FplEnergyEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
recMtrReading = self.getData("recMtrReading")
|
return self.getData("recMtrReading")
|
||||||
|
|
||||||
if recMtrReading is not None:
|
|
||||||
self._attr_native_value = recMtrReading
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
def customAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
@@ -110,12 +90,7 @@ class NetDeliveredKWHSensor(FplEnergyEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
delMtrReading = self.getData("delMtrReading")
|
return self.getData("delMtrReading")
|
||||||
|
|
||||||
if delMtrReading is not None:
|
|
||||||
self._attr_native_value = delMtrReading
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
def customAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
|
|||||||
@@ -19,15 +19,10 @@ class FplProjectedBillSensor(FplMoneyEntity):
|
|||||||
budget = self.getData("budget_bill")
|
budget = self.getData("budget_bill")
|
||||||
budget_billing_projected_bill = self.getData("budget_billing_projected_bill")
|
budget_billing_projected_bill = self.getData("budget_billing_projected_bill")
|
||||||
|
|
||||||
projected_bill = self.getData("projected_bill")
|
|
||||||
|
|
||||||
if budget and budget_billing_projected_bill is not None:
|
if budget and budget_billing_projected_bill is not None:
|
||||||
self._attr_native_value = self.getData("budget_billing_projected_bill")
|
return self.getData("budget_billing_projected_bill")
|
||||||
else:
|
|
||||||
if projected_bill is not None:
|
|
||||||
self._attr_native_value = projected_bill
|
|
||||||
|
|
||||||
return self._attr_native_value
|
return self.getData("projected_bill")
|
||||||
|
|
||||||
def customAttributes(self):
|
def customAttributes(self):
|
||||||
"""Return the state attributes."""
|
"""Return the state attributes."""
|
||||||
@@ -47,13 +42,9 @@ class DeferedAmountSensor(FplMoneyEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
budget_bill = self.getData("budget_bill")
|
if self.getData("budget_bill"):
|
||||||
defered_amount = self.getData("defered_amount")
|
return self.getData("defered_amount")
|
||||||
|
return 0
|
||||||
if budget_bill and defered_amount is not None:
|
|
||||||
self._attr_native_value = defered_amount
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectedBudgetBillSensor(FplMoneyEntity):
|
class ProjectedBudgetBillSensor(FplMoneyEntity):
|
||||||
@@ -66,12 +57,7 @@ class ProjectedBudgetBillSensor(FplMoneyEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
budget_billing_projected_bill = self.getData("budget_billing_projected_bill")
|
return self.getData("budget_billing_projected_bill")
|
||||||
|
|
||||||
if budget_billing_projected_bill is not None:
|
|
||||||
self._attr_native_value = budget_billing_projected_bill
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
|
|
||||||
class ProjectedActualBillSensor(FplMoneyEntity):
|
class ProjectedActualBillSensor(FplMoneyEntity):
|
||||||
@@ -84,12 +70,7 @@ class ProjectedActualBillSensor(FplMoneyEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
projected_bill = self.getData("projected_bill")
|
return self.getData("projected_bill")
|
||||||
|
|
||||||
if projected_bill is not None:
|
|
||||||
self._attr_native_value = projected_bill
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|
||||||
|
|
||||||
class BillToDateSensor(FplMoneyEntity):
|
class BillToDateSensor(FplMoneyEntity):
|
||||||
@@ -102,13 +83,7 @@ class BillToDateSensor(FplMoneyEntity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
budget_bill = self.getData("budget_bill")
|
if self.getData("budget_bill"):
|
||||||
budget_billing_bill_to_date = self.getData("budget_billing_bill_to_date")
|
return self.getData("budget_billing_bill_to_date")
|
||||||
bill_to_date = self.getData("bill_to_date")
|
|
||||||
|
|
||||||
if budget_bill:
|
return self.getData("bill_to_date")
|
||||||
self._attr_native_value = budget_billing_bill_to_date
|
|
||||||
else:
|
|
||||||
self._attr_native_value = bill_to_date
|
|
||||||
|
|
||||||
return self._attr_native_value
|
|
||||||
|
|||||||
Reference in New Issue
Block a user