Compare commits

6 Commits
master ... dev

Author SHA1 Message Date
Yordan Suarez
a5e9e94ec2 Merge branch 'feature/1-test-feature' into dev 2022-12-14 02:34:01 -05:00
Yordan Suarez
ef776e9cb3 add some comment 2022-12-14 02:33:16 -05:00
Yordan Suarez
77636af8e7 stop using exception for no territory, instead assume main territory 2022-12-06 11:58:45 -05:00
Yordan Suarez
6c337e3c17 added custom exception for no territory 2022-12-06 11:57:03 -05:00
Yordan Suarez
2ae6a1c929 change some debug texts 2022-09-13 18:48:17 -04:00
Yordan Suarez
d7b1f3fd38 update native value if there are valid values from api 2022-09-13 16:53:58 -04:00
8 changed files with 133 additions and 43 deletions

View File

@@ -2,7 +2,7 @@
import json
import logging
from datetime import datetime, timedelta
from datetime import datetime
import aiohttp
import async_timeout
@@ -274,7 +274,7 @@ class FplMainRegionApiClient:
async def __getDataFromEnergyService(
self, account, premise, lastBilledDate
) -> dict:
_LOGGER.info("Getting data from energy service")
_LOGGER.info("Getting energy service data")
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 data from appliance usage")
_LOGGER.info("Getting appliance usage data")
JSON = {"startDate": str(lastBilledDate.strftime("%m%d%Y"))}
data = {}

View File

@@ -11,3 +11,7 @@ class ForceChangePasswordException(WarrantException):
class TokenVerificationException(WarrantException):
"""Raised when token verification fails."""
class NoTerrytoryAvailableException(Exception):
"""Thrown when not possible to determine user territory"""

View File

@@ -26,10 +26,6 @@ _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."""
@@ -58,7 +54,8 @@ class FplApi:
territoryArray = json_data["data"]["territory"]
if len(territoryArray) == 0:
raise NoTerrytoryAvailableException()
# returns main region by default in case no regions found
return FPL_MAINREGION
self._territory = territoryArray[0]
return territoryArray[0]

View File

@@ -12,12 +12,12 @@ class DailyAverageSensor(FplMoneyEntity):
@property
def native_value(self):
budget = self.getData("budget_bill")
budget_billing_projected_bill = self.getData("budget_billing_daily_avg")
daily_avg = self.getData("daily_avg")
if budget and budget_billing_projected_bill is not None:
return self.getData("budget_billing_daily_avg")
if budget and daily_avg is not None:
self._attr_native_value = daily_avg
return self.getData("daily_avg")
return self._attr_native_value
def customAttributes(self):
"""Return the state attributes."""
@@ -34,7 +34,12 @@ class BudgetDailyAverageSensor(FplMoneyEntity):
@property
def native_value(self):
return self.getData("budget_billing_daily_avg")
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
def customAttributes(self):
"""Return the state attributes."""
@@ -51,7 +56,12 @@ class ActualDailyAverageSensor(FplMoneyEntity):
@property
def native_value(self):
return self.getData("daily_avg")
daily_avg = self.getData("daily_avg")
if daily_avg is not None:
self._attr_native_value = daily_avg
return self._attr_native_value
def customAttributes(self):
"""Return the state attributes."""

View File

@@ -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():
return data[-1]["cost"]
self._attr_native_value = data[-1]["cost"]
return None
return self._attr_native_value
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():
return data[-1]["usage"]
self._attr_native_value = data[-1]["usage"]
return None
return self._attr_native_value
@property
def last_reset(self) -> datetime | None:
@@ -83,9 +83,11 @@ 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():
return data[-1]["netReceivedKwh"]
return 0
self._attr_native_value = data[-1]["netReceivedKwh"]
return self._attr_native_value
def customAttributes(self):
"""Return the state attributes."""
@@ -110,9 +112,11 @@ 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():
return data[-1]["netDeliveredKwh"]
return 0
self._attr_native_value = data[-1]["netDeliveredKwh"]
return self._attr_native_value
def customAttributes(self):
"""Return the state attributes."""

View File

@@ -11,7 +11,12 @@ class CurrentBillDateSensor(FplDateEntity):
@property
def native_value(self):
return datetime.date.fromisoformat(self.getData("current_bill_date"))
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
class NextBillDateSensor(FplDateEntity):
@@ -22,7 +27,12 @@ class NextBillDateSensor(FplDateEntity):
@property
def native_value(self):
return datetime.date.fromisoformat(self.getData("next_bill_date"))
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
class ServiceDaysSensor(FplDayEntity):
@@ -33,7 +43,12 @@ class ServiceDaysSensor(FplDayEntity):
@property
def native_value(self):
return self.getData("service_days")
service_days = self.getData("service_days")
if service_days is not None:
self._attr_native_value = service_days
return self._attr_native_value
class AsOfDaysSensor(FplDayEntity):
@@ -44,7 +59,12 @@ class AsOfDaysSensor(FplDayEntity):
@property
def native_value(self):
return self.getData("as_of_days")
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
class RemainingDaysSensor(FplDayEntity):
@@ -55,4 +75,9 @@ class RemainingDaysSensor(FplDayEntity):
@property
def native_value(self):
return self.getData("remaining_days")
remaining_days = self.getData("remaining_days")
if remaining_days is not None:
self._attr_native_value = remaining_days
return self._attr_native_value

View File

@@ -15,7 +15,12 @@ class ProjectedKWHSensor(FplEnergyEntity):
@property
def native_value(self):
return self.getData("projectedKWH")
projectedKWH = self.getData("projectedKWH")
if projectedKWH is not None:
self._attr_native_value = projectedKWH
return self._attr_native_value
def customAttributes(self):
"""Return the state attributes."""
@@ -32,7 +37,12 @@ class DailyAverageKWHSensor(FplEnergyEntity):
@property
def native_value(self):
return self.getData("dailyAverageKWH")
dailyAverageKWH = self.getData("dailyAverageKWH")
if dailyAverageKWH is not None:
self._attr_native_value = dailyAverageKWH
return self._attr_native_value
def customAttributes(self):
"""Return the state attributes."""
@@ -49,7 +59,12 @@ class BillToDateKWHSensor(FplEnergyEntity):
@property
def native_value(self):
return self.getData("billToDateKWH")
billToDateKWH = self.getData("billToDateKWH")
if billToDateKWH is not None:
self._attr_native_value = billToDateKWH
return self._attr_native_value
def customAttributes(self):
"""Return the state attributes."""
@@ -73,7 +88,12 @@ class NetReceivedKWHSensor(FplEnergyEntity):
@property
def native_value(self):
return self.getData("recMtrReading")
recMtrReading = self.getData("recMtrReading")
if recMtrReading is not None:
self._attr_native_value = recMtrReading
return self._attr_native_value
def customAttributes(self):
"""Return the state attributes."""
@@ -90,7 +110,12 @@ class NetDeliveredKWHSensor(FplEnergyEntity):
@property
def native_value(self):
return self.getData("delMtrReading")
delMtrReading = self.getData("delMtrReading")
if delMtrReading is not None:
self._attr_native_value = delMtrReading
return self._attr_native_value
def customAttributes(self):
"""Return the state attributes."""

View File

@@ -19,10 +19,15 @@ class FplProjectedBillSensor(FplMoneyEntity):
budget = self.getData("budget_bill")
budget_billing_projected_bill = self.getData("budget_billing_projected_bill")
if budget and budget_billing_projected_bill is not None:
return self.getData("budget_billing_projected_bill")
projected_bill = self.getData("projected_bill")
return 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._attr_native_value
def customAttributes(self):
"""Return the state attributes."""
@@ -42,9 +47,13 @@ class DeferedAmountSensor(FplMoneyEntity):
@property
def native_value(self):
if self.getData("budget_bill"):
return self.getData("defered_amount")
return 0
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
class ProjectedBudgetBillSensor(FplMoneyEntity):
@@ -57,7 +66,12 @@ class ProjectedBudgetBillSensor(FplMoneyEntity):
@property
def native_value(self):
return self.getData("budget_billing_projected_bill")
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
class ProjectedActualBillSensor(FplMoneyEntity):
@@ -70,7 +84,12 @@ class ProjectedActualBillSensor(FplMoneyEntity):
@property
def native_value(self):
return self.getData("projected_bill")
projected_bill = self.getData("projected_bill")
if projected_bill is not None:
self._attr_native_value = projected_bill
return self._attr_native_value
class BillToDateSensor(FplMoneyEntity):
@@ -83,7 +102,13 @@ class BillToDateSensor(FplMoneyEntity):
@property
def native_value(self):
if self.getData("budget_bill"):
return self.getData("budget_billing_bill_to_date")
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")
return self.getData("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