added bill to date sensor and organize sensor initialization file
This commit is contained in:
@@ -15,6 +15,7 @@ from .sensor_DatesSensor import (
|
|||||||
RemainingDaysSensor,
|
RemainingDaysSensor,
|
||||||
)
|
)
|
||||||
from .sensor_ProjectedBillSensor import (
|
from .sensor_ProjectedBillSensor import (
|
||||||
|
BillToDateSensor,
|
||||||
FplProjectedBillSensor,
|
FplProjectedBillSensor,
|
||||||
ProjectedBudgetBillSensor,
|
ProjectedBudgetBillSensor,
|
||||||
ProjectedActualBillSensor,
|
ProjectedActualBillSensor,
|
||||||
@@ -32,64 +33,69 @@ from .sensor_DailyUsageSensor import (
|
|||||||
FplDailyReceivedKWHSensor,
|
FplDailyReceivedKWHSensor,
|
||||||
)
|
)
|
||||||
|
|
||||||
from .sensor_test import TestSensor
|
from .const import CONF_ACCOUNTS, CONF_TERRITORY, DOMAIN, FPL_MAINREGION, FPL_NORTHWEST
|
||||||
|
|
||||||
from .const import DOMAIN, DEBUG
|
ALL_REGIONS = [FPL_MAINREGION, FPL_NORTHWEST]
|
||||||
|
ONLY_MAINREGION = [FPL_MAINREGION]
|
||||||
|
|
||||||
# from .TestSensor import TestSensor
|
sensors = {}
|
||||||
|
|
||||||
|
|
||||||
|
def registerSensor(sensor, regions):
|
||||||
|
"""register all available sensors"""
|
||||||
|
for region in regions:
|
||||||
|
if region in sensors:
|
||||||
|
sensors[region].append(sensor)
|
||||||
|
else:
|
||||||
|
sensors[region] = [sensor]
|
||||||
|
|
||||||
|
|
||||||
|
# bill sensors
|
||||||
|
registerSensor(FplProjectedBillSensor, ALL_REGIONS)
|
||||||
|
registerSensor(BillToDateSensor, ALL_REGIONS)
|
||||||
|
|
||||||
|
# budget billing
|
||||||
|
registerSensor(ProjectedBudgetBillSensor, ONLY_MAINREGION)
|
||||||
|
registerSensor(ProjectedActualBillSensor, ONLY_MAINREGION)
|
||||||
|
registerSensor(DeferedAmountSensor, ONLY_MAINREGION)
|
||||||
|
|
||||||
|
|
||||||
|
# usage sensors
|
||||||
|
registerSensor(DailyAverageSensor, ONLY_MAINREGION)
|
||||||
|
registerSensor(BudgetDailyAverageSensor, ONLY_MAINREGION)
|
||||||
|
registerSensor(ActualDailyAverageSensor, ONLY_MAINREGION)
|
||||||
|
|
||||||
|
registerSensor(FplDailyUsageSensor, ONLY_MAINREGION)
|
||||||
|
registerSensor(FplDailyUsageKWHSensor, ONLY_MAINREGION)
|
||||||
|
|
||||||
|
# date sensors
|
||||||
|
registerSensor(CurrentBillDateSensor, ALL_REGIONS)
|
||||||
|
registerSensor(NextBillDateSensor, ONLY_MAINREGION)
|
||||||
|
registerSensor(ServiceDaysSensor, ALL_REGIONS)
|
||||||
|
registerSensor(AsOfDaysSensor, ALL_REGIONS)
|
||||||
|
registerSensor(RemainingDaysSensor, ALL_REGIONS)
|
||||||
|
|
||||||
|
# KWH sensors
|
||||||
|
registerSensor(ProjectedKWHSensor, ALL_REGIONS)
|
||||||
|
registerSensor(DailyAverageKWHSensor, ONLY_MAINREGION)
|
||||||
|
registerSensor(BillToDateKWHSensor, ALL_REGIONS)
|
||||||
|
registerSensor(NetReceivedKWHSensor, ONLY_MAINREGION)
|
||||||
|
registerSensor(NetDeliveredKWHSensor, ONLY_MAINREGION)
|
||||||
|
registerSensor(FplDailyReceivedKWHSensor, ONLY_MAINREGION)
|
||||||
|
registerSensor(FplDailyDeliveredKWHSensor, ONLY_MAINREGION)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(hass, entry, async_add_devices):
|
async def async_setup_entry(hass, entry, async_add_devices):
|
||||||
"""Setup sensor platform."""
|
"""Setup sensor platform."""
|
||||||
|
|
||||||
accounts = entry.data.get("accounts")
|
accounts = entry.data.get(CONF_ACCOUNTS)
|
||||||
territory = entry.data.get("territory")
|
territory = entry.data.get(CONF_TERRITORY)
|
||||||
|
|
||||||
print(f"setting sensor for {territory}")
|
|
||||||
|
|
||||||
coordinator = hass.data[DOMAIN][entry.entry_id]
|
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
fpl_accounts = []
|
fpl_accounts = []
|
||||||
|
|
||||||
if DEBUG:
|
|
||||||
for account in accounts:
|
for account in accounts:
|
||||||
fpl_accounts.append(TestSensor(coordinator, entry, account))
|
for sensor in sensors[territory]:
|
||||||
|
fpl_accounts.append(sensor(coordinator, entry, account))
|
||||||
fpl_accounts.append(FplProjectedBillSensor(coordinator, entry, account))
|
|
||||||
else:
|
|
||||||
for account in accounts:
|
|
||||||
# Test Sensor
|
|
||||||
# fpl_accounts.append(TestSensor(coordinator, entry, account))
|
|
||||||
|
|
||||||
# bill sensors
|
|
||||||
fpl_accounts.append(FplProjectedBillSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(ProjectedBudgetBillSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(ProjectedActualBillSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(DeferedAmountSensor(coordinator, entry, account))
|
|
||||||
|
|
||||||
# usage sensors
|
|
||||||
fpl_accounts.append(DailyAverageSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(BudgetDailyAverageSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(ActualDailyAverageSensor(coordinator, entry, account))
|
|
||||||
|
|
||||||
fpl_accounts.append(FplDailyUsageSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(FplDailyUsageKWHSensor(coordinator, entry, account))
|
|
||||||
|
|
||||||
# date sensors
|
|
||||||
fpl_accounts.append(CurrentBillDateSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(NextBillDateSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(ServiceDaysSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(AsOfDaysSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(RemainingDaysSensor(coordinator, entry, account))
|
|
||||||
|
|
||||||
# KWH sensors
|
|
||||||
fpl_accounts.append(ProjectedKWHSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(DailyAverageKWHSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(BillToDateKWHSensor(coordinator, entry, account))
|
|
||||||
|
|
||||||
fpl_accounts.append(NetReceivedKWHSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(NetDeliveredKWHSensor(coordinator, entry, account))
|
|
||||||
|
|
||||||
fpl_accounts.append(FplDailyReceivedKWHSensor(coordinator, entry, account))
|
|
||||||
fpl_accounts.append(FplDailyDeliveredKWHSensor(coordinator, entry, account))
|
|
||||||
|
|
||||||
async_add_devices(fpl_accounts)
|
async_add_devices(fpl_accounts)
|
||||||
|
|||||||
@@ -71,3 +71,19 @@ class ProjectedActualBillSensor(FplMoneyEntity):
|
|||||||
@property
|
@property
|
||||||
def native_value(self):
|
def native_value(self):
|
||||||
return self.getData("projected_bill")
|
return self.getData("projected_bill")
|
||||||
|
|
||||||
|
|
||||||
|
class BillToDateSensor(FplMoneyEntity):
|
||||||
|
"""projeted actual bill sensor"""
|
||||||
|
|
||||||
|
# _attr_state_class = STATE_CLASS_TOTAL
|
||||||
|
|
||||||
|
def __init__(self, coordinator, config, account):
|
||||||
|
super().__init__(coordinator, config, account, "Bill To Date")
|
||||||
|
|
||||||
|
@property
|
||||||
|
def native_value(self):
|
||||||
|
if self.getData("budget_bill"):
|
||||||
|
return self.getData("budget_billing_bill_to_date")
|
||||||
|
|
||||||
|
return self.getData("bill_to_date")
|
||||||
|
|||||||
Reference in New Issue
Block a user