Merge pull request #23 from adamoutler/master

Sensor metadata update
This commit is contained in:
Yordan Suarez
2022-01-12 19:17:43 -05:00
committed by GitHub
13 changed files with 408 additions and 91 deletions

View File

@@ -24,13 +24,12 @@ class FplProjectedBillSensor(FplSensor):
@property
def device_state_attributes(self):
"""Return the state attributes."""
try:
if "budget_bill" in self.data.keys():
self.attr["budget_bill"] = self.data["budget_bill"]
except:
pass
return self.attr
return self._state
@property
def icon(self):

View File

@@ -3,7 +3,7 @@
NAME = "FPL Integration"
DOMAIN = "fpl"
DOMAIN_DATA = f"{DOMAIN}_data"
VERSION = "0.0.1"
VERSION = "0.1.0"
PLATFORMS = ["sensor"]
REQUIRED_FILES = [
".translations/en.json",

View File

@@ -7,7 +7,7 @@ from datetime import timedelta
from .fplapi import FplApi
from .const import DOMAIN
SCAN_INTERVAL = timedelta(seconds=7200)
SCAN_INTERVAL = timedelta(seconds=1200)
_LOGGER: logging.Logger = logging.getLogger(__package__)

View File

@@ -19,16 +19,13 @@ class FplEntity(CoordinatorEntity):
)
return id
@property
def name(self):
return f"{DOMAIN.upper()} {self.account} {self.sensorName}"
@property
def device_info(self):
return {
"identifiers": {(DOMAIN, self.account)},
"name": f"Account {self.account}",
"model": VERSION,
"name": f"FPL Account {self.account}",
"model": "FPL Monitoring API",
"sw_version": VERSION,
"manufacturer": "Florida Power & Light",
}

View File

@@ -300,6 +300,9 @@ class FplApi(object):
"cost": daily["billingCharge"],
"date": daily["date"],
"max_temperature": daily["averageHighTemperature"],
"netDeliveredKwh": daily["netDeliveredKwh"],
"netReceivedKwh": daily["netReceivedKwh"],
"readTime": daily["readTime"],
}
)
# totalPowerUsage += int(daily["kwhUsed"])
@@ -312,6 +315,7 @@ class FplApi(object):
data["billToDateKWH"] = r["CurrentUsage"]["billToDateKWH"]
data["recMtrReading"] = r["CurrentUsage"]["recMtrReading"]
data["delMtrReading"] = r["CurrentUsage"]["delMtrReading"]
data["billStartDate"] = r["CurrentUsage"]["billStartDate"]
return data
async def __getDataFromApplianceUsage(self, account, lastBilledDate) -> dict:

View File

@@ -12,6 +12,6 @@
"bs4",
"integrationhelper"
],
"homeassistant": "0.96.0",
"homeassistant": "2021.12.7",
"version": "1.0.0"
}

View File

@@ -23,9 +23,14 @@ from .sensor_ProjectedBillSensor import (
from .sensor_AverageDailySensor import (
FplAverageDailySensor,
BudgetDailyAverageSensor,
ActualDailyAverageSensor,
)
from .sensor_DailyUsageSensor import FplDailyUsageKWHSensor, FplDailyUsageSensor
from .sensor_DailyUsageSensor import (
FplDailyUsageKWHSensor,
FplDailyUsageSensor,
FplDailyDeliveredKWHSensor,
FplDailyReceivedKWHSensor,
)
from .const import DOMAIN
from .sensor_AllData import AllDataSensor
@@ -54,10 +59,10 @@ async def async_setup_entry(hass, entry, async_add_devices):
# usage sensors
fpl_accounts.append(FplAverageDailySensor(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))
fpl_accounts.append(FplDailyReceivedKWHSensor(coordinator, entry, account))
fpl_accounts.append(FplDailyDeliveredKWHSensor(coordinator, entry, account))
# date sensors
fpl_accounts.append(CurrentBillDateSensor(coordinator, entry, account))
@@ -70,5 +75,8 @@ async def async_setup_entry(hass, entry, async_add_devices):
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))
async_add_devices(fpl_accounts)

View File

@@ -13,12 +13,21 @@ class AllDataSensor(FplEntity):
if budget == True and budget_billing_projected_bill is not None:
return self.getData("budget_billing_projected_bill")
return self.getData("projected_bill")
def defineAttributes(self):
"""Return the state attributes."""
return self.coordinator.data.get(self.account)
try:
self._state=self.getData("projected_bill")
except:
pass
return self._state
@property
def icon(self):
return "mdi:currency-usd"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Budget Projected Bill"
attributes["device_class"] = "monetary"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "$"
return attributes

View File

@@ -13,12 +13,24 @@ class FplAverageDailySensor(FplEntity):
if budget == True and budget_billing_projected_bill is not None:
return self.getData("budget_billing_daily_avg")
return self.getData("daily_avg")
try:
self._state=self.getData("daily_avg")
except:
pass
return self._state
@property
def icon(self):
return "mdi:currency-usd"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Daily Average"
attributes["device_class"] = "monetary"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "$"
return attributes
class BudgetDailyAverageSensor(FplEntity):
def __init__(self, coordinator, config, account):
@@ -26,21 +38,22 @@ class BudgetDailyAverageSensor(FplEntity):
@property
def state(self):
return self.getData("budget_billing_daily_avg")
try:
self._state= self.getData("budget_billing_daily_avg")
except:
pass
return self._state
@property
def icon(self):
return "mdi:currency-usd"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Budget Daily Average"
attributes["device_class"] = "monitary"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "$"
return attributes
class ActualDailyAverageSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Actual Daily Average")
@property
def state(self):
return self.getData("daily_avg")
@property
def icon(self):
return "mdi:currency-usd"

View File

@@ -9,19 +9,34 @@ class FplDailyUsageSensor(FplEntity):
def state(self):
data = self.getData("daily_usage")
if len(data) > 0:
return data[-1]["cost"]
return None
try:
self._state = data[-1]["cost"]
except:
pass
return self._state
def defineAttributes(self):
"""Return the state attributes."""
data = self.getData("daily_usage")
if len(data) > 0:
return {"date": data[-1]["date"]}
return {}
attributes = {}
attributes["friendly_name"] = "Daily Usage"
attributes["device_class"] = "monetary"
attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "$"
if data is not None:
if (
(len(data) > 0)
and (data[-1] is not None)
and (data[-1]["readTime"] is not None)
):
attributes["date"] = data[-1]["readTime"]
if (
(len(data) > 1)
and (data[-2] is not None)
and (data[-2]["readTime"] is not None)
):
attributes["last_reset"] = data[-2]["readTime"]
return attributes
@property
def icon(self):
@@ -36,20 +51,122 @@ class FplDailyUsageKWHSensor(FplEntity):
def state(self):
data = self.getData("daily_usage")
if len(data) > 0:
return data[-1]["usage"]
return None
try:
self._state = data[-1]["usage"]
except:
pass
return self._state
def defineAttributes(self):
"""Return the state attributes."""
data = self.getData("daily_usage")
if len(data) > 0:
return {"date": data[-1]["date"]}
attributes = {}
attributes["friendly_name"] = "Daily Usage"
attributes["device_class"] = "energy"
attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "kWh"
return {}
if data is not None:
if (
(len(data) > 0)
and (data[-1] is not None)
and (data[-1]["readTime"] is not None)
):
attributes["date"] = data[-1]["readTime"]
if (
(len(data) > 1)
and (data[-2] is not None)
and (data[-2]["readTime"] is not None)
):
attributes["last_reset"] = data[-2]["readTime"]
return attributes
@property
def icon(self):
return "mdi:currency-usd"
return "mdi:flash"
class FplDailyReceivedKWHSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Daily Received KWH")
@property
def state(self):
data = self.getData("daily_usage")
try:
self._state = data[-1]["netReceivedKwh"]
except:
pass
return self._state
def defineAttributes(self):
"""Return the state attributes."""
data = self.getData("daily_usage")
attributes = {}
attributes["friendly_name"] = "Daily Return to Grid"
attributes["device_class"] = "energy"
attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "kWh"
if data is not None:
if (
(len(data) > 0)
and (data[-1] is not None)
and (data[-1]["readTime"] is not None)
):
attributes["date"] = data[-1]["readTime"]
if (
(len(data) > 1)
and (data[-2] is not None)
and (data[-2]["readTime"] is not None)
):
attributes["last_reset"] = data[-2]["readTime"]
return attributes
@property
def icon(self):
return "mdi:flash"
class FplDailyDeliveredKWHSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Daily Delivered KWH")
@property
def state(self):
data = self.getData("daily_usage")
try:
self._state = data[-1]["netDeliveredKwh"]
except:
pass
return self._state
def defineAttributes(self):
"""Return the state attributes."""
data = self.getData("daily_usage")
attributes = {}
attributes["friendly_name"] = "Daily Consumption"
attributes["device_class"] = "energy"
attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "kWh"
if data is not None:
if (
(len(data) > 0)
and (data[-1] is not None)
and (data[-1]["readTime"] is not None)
):
attributes["date"] = data[-1]["readTime"]
if (
(len(data) > 1)
and (data[-2] is not None)
and (data[-2]["readTime"] is not None)
):
attributes["last_reset"] = data[-2]["readTime"]
return attributes
@property
def icon(self):
return "mdi:flash"

View File

@@ -1,66 +1,117 @@
from .fplEntity import FplEntity
import datetime
class CurrentBillDateSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Current Bill Date")
super().__init__(coordinator, config, account, "Billing Current Date")
@property
def state(self):
return self.getData("current_bill_date")
try:
self._state= datetime.date.fromisoformat(self.getData("current_bill_date"))
except:
pass
return self._state
@property
def icon(self):
return "mdi:calendar"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["device_class"] = "date"
attributes["friendly_name"] = "Billing Current"
return attributes
class NextBillDateSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Next Bill Date")
super().__init__(coordinator, config, account, "Billing Next")
@property
def state(self):
return self.getData("next_bill_date")
try:
self._state= datetime.date.fromisoformat(self.getData("next_bill_date"))
except:
pass
return self._state
@property
def icon(self):
return "mdi:calendar"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["device_class"] = "date"
attributes["friendly_name"] = "Billing Next"
return attributes
class ServiceDaysSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Service Days")
super().__init__(coordinator, config, account, "Billing Total Days")
@property
def state(self):
return self.getData("service_days")
try:
self._state= self.getData("service_days")
except:
pass
return self._state
@property
def icon(self):
return "mdi:calendar"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["unit_of_measurement"] = "days"
attributes["friendly_name"] = "Billing Total"
return attributes
class AsOfDaysSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "As Of Days")
super().__init__(coordinator, config, account, "Billing As Of")
@property
def state(self):
return self.getData("as_of_days")
try:
self._state= self.getData("as_of_days")
except:
pass
return self._state
@property
def icon(self):
return "mdi:calendar"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["unit_of_measurement"] = "days"
attributes["friendly_name"] = "Billing As Of"
return attributes
class RemainingDaysSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Remaining Days")
super().__init__(coordinator, config, account, "Billing Remaining")
@property
def state(self):
return self.getData("remaining_days")
try:
self._state= self.getData("remaining_days")
except:
pass
return self._state
@property
def icon(self):
return "mdi:calendar"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["unit_of_measurement"] = "days"
attributes["friendly_name"] = "Billing Remaining"
return attributes

View File

@@ -3,62 +3,140 @@ from .fplEntity import FplEntity
class ProjectedKWHSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Projected KWH")
super().__init__(coordinator, config, account, "Projected")
@property
def state(self):
return self.getData("projectedKWH")
try:
self._state = self.getData("projectedKWH")
except:
pass
return self._state
@property
def icon(self):
return "mdi:flash"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Projected KWH"
attributes["device_class"] = "energy"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "kWh"
return attributes
class DailyAverageKWHSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Daily Average KWH")
super().__init__(coordinator, config, account, "Daily Average")
@property
def state(self):
return self.getData("dailyAverageKWH")
try:
self._state = self.getData("dailyAverageKWH")
except:
pass
return self._state
@property
def icon(self):
return "mdi:flash"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Daily Average"
attributes["device_class"] = "energy"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "kWh"
return attributes
class BillToDateKWHSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Bill To Date KWH")
super().__init__(coordinator, config, account, "Bill To Date")
@property
def state(self):
return self.getData("billToDateKWH")
try:
self._state = self.getData("billToDateKWH")
except:
pass
return self._state
@property
def icon(self):
return "mdi:flash"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Billing Usage"
attributes["device_class"] = "energy"
attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "kWh"
if self.getData("billStartDate") is not None:
attributes["last_reset"] = self.getData("billStartDate")
return attributes
class NetReceivedKWHSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Received Meter Reading KWH")
super().__init__(coordinator, config, account, "Received Reading")
@property
def state(self):
return self.getData("recMtrReading")
try:
self._state = self.getData("recMtrReading")
except:
pass
return self._state
@property
def icon(self):
return "mdi:flash"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Meter Return to Grid"
attributes["device_class"] = "energy"
attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "kWh"
if self.getData("billStartDate") is not None:
attributes["last_reset"] = self.getData("billStartDate")
return attributes
class NetDeliveredKWHSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Delivered Meter Reading KWH")
super().__init__(coordinator, config, account, "Delivered Reading")
@property
def state(self):
return self.getData("delMtrReading")
try:
self._state = self.getData("delMtrReading")
except:
try:
self._state = self.getData("billToDateKWH")
except:
pass
return self._state
@property
def icon(self):
return "mdi:flash"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Meter Consumption"
attributes["device_class"] = "energy"
attributes["state_class"] = "total_increasing"
attributes["unit_of_measurement"] = "kWh"
if self.getData("billStartDate") is not None:
attributes["last_reset"] = self.getData("billStartDate")
return attributes

View File

@@ -10,20 +10,22 @@ class FplProjectedBillSensor(FplEntity):
budget = self.getData("budget_bill")
budget_billing_projected_bill = self.getData("budget_billing_projected_bill")
try:
if budget == True and budget_billing_projected_bill is not None:
return self.getData("budget_billing_projected_bill")
return self.getData("projected_bill")
self._state = self.getData("budget_billing_projected_bill")
else:
self._state = self.getData("projected_bill")
except:
self._state = None
return self._state
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
try:
if self.getData("budget_bill") == True:
attributes["budget_bill"] = self.getData("budget_bill")
except:
pass
attributes["friendly_name"] = "Projected Bill Payment Due"
attributes["device_class"] = "monetary"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "$"
return attributes
@property
@@ -34,18 +36,30 @@ class FplProjectedBillSensor(FplEntity):
# Defered Amount
class DeferedAmountSensor(FplEntity):
def __init__(self, coordinator, config, account):
super().__init__(coordinator, config, account, "Defered Amount")
super().__init__(coordinator, config, account, "Deferred Amount")
@property
def state(self):
if self.getData("budget_bill") == True:
return self.getData("defered_amount")
return 0
try:
self._state = self.getData("deferred_amount")
except:
self._state = 0
pass
return self._state
@property
def icon(self):
return "mdi:currency-usd"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Deferred Amount"
attributes["device_class"] = "monetary"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "$"
return attributes
class ProjectedBudgetBillSensor(FplEntity):
def __init__(self, coordinator, config, account):
@@ -53,12 +67,25 @@ class ProjectedBudgetBillSensor(FplEntity):
@property
def state(self):
return self.getData("budget_billing_projected_bill")
try:
self._state = self.getData("budget_billing_projected_bill")
except:
pass
return self._state
@property
def icon(self):
return "mdi:currency-usd"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Projected Budget Bill"
attributes["device_class"] = "monitary"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "$"
return attributes
class ProjectedActualBillSensor(FplEntity):
def __init__(self, coordinator, config, account):
@@ -66,8 +93,22 @@ class ProjectedActualBillSensor(FplEntity):
@property
def state(self):
return self.getData("projected_bill")
try:
self._state = self.getData("projected_bill")
except:
pass
return self._state
@property
def icon(self):
return "mdi:currency-usd"
def defineAttributes(self):
"""Return the state attributes."""
attributes = {}
attributes["friendly_name"] = "Projected Actual Bill"
attributes["device_class"] = "monitary"
attributes["state_class"] = "total"
attributes["unit_of_measurement"] = "$"
return attributes