Check for data before on sensor state update

This commit is contained in:
Yordan Suarez
2020-11-12 22:19:34 +00:00
parent cd9aef5f31
commit 657905a4da
8 changed files with 175 additions and 122 deletions

View File

@@ -8,21 +8,28 @@ class FplProjectedBillSensor(FplSensor):
@property
def state(self):
data = self.data
if "budget_bill" in data.keys():
if data["budget_bill"]:
if "budget_billing_projected_bill" in data.keys():
self._state = data["budget_billing_projected_bill"]
else:
if "projected_bill" in data.keys():
self._state = data["projected_bill"]
try:
if "budget_bill" in data.keys():
if data["budget_bill"]:
if "budget_billing_projected_bill" in data.keys():
self._state = data["budget_billing_projected_bill"]
else:
if "projected_bill" in data.keys():
self._state = data["projected_bill"]
except:
pass
return self._state
@property
def device_state_attributes(self):
"""Return the state attributes."""
if "budget_bill" in self.data.keys():
self.attr["budget_bill"] = self.data["budget_bill"]
try:
if "budget_bill" in self.data.keys():
self.attr["budget_bill"] = self.data["budget_bill"]
except:
pass
return self.attr
@property