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