Skip to content

Commit

Permalink
Update sensor.py
Browse files Browse the repository at this point in the history
Fix not received raw data which causes KeyError: 'pv1Current'
  • Loading branch information
webmake authored Apr 25, 2023
1 parent d5ac830 commit 4f7209e
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions custom_components/foxess/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ async def getAddresbook(hass, headersData, allData, deviceID,username, hashedPas
token = None
else:
_LOGGER.debug(
"FoxESS Addressbook data fetched correcly "+restAddressBook.data)
"FoxESS Addressbook data fetched correctly "+restAddressBook.data)
allData['addressbook'] = response

async def getReport(hass, headersData, allData, deviceID):
Expand Down Expand Up @@ -360,7 +360,7 @@ async def getRaw(hass, headersData, allData, deviceID):
_LOGGER.error("Unable to get Raw data from FoxESS Cloud")
return False
else:
_LOGGER.debug("FoxESS Raw data fetched correcly " +
_LOGGER.debug("FoxESS Raw data fetched correctly " +
restRaw.data[:150] + " ... ")
allData['raw'] = {}
for item in json.loads(restRaw.data)['result']:
Expand Down Expand Up @@ -390,7 +390,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> str | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["generationPower"]
return None

Expand All @@ -416,7 +416,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> str | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["gridConsumptionPower"]
return None

Expand All @@ -442,7 +442,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> str | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["feedinPower"]
return None

Expand All @@ -468,7 +468,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> str | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["batDischargePower"]
return None

Expand All @@ -494,7 +494,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> str | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["batChargePower"]
return None

Expand All @@ -520,7 +520,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> str | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["loadsPower"]
return None

Expand All @@ -546,7 +546,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["pv1Current"]
return None

Expand All @@ -572,7 +572,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["pv1Power"]
return None

Expand All @@ -598,7 +598,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["pv1Volt"]
return None

Expand All @@ -624,7 +624,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["pv2Current"]
return None

Expand All @@ -650,7 +650,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["pv2Power"]
return None

Expand All @@ -676,7 +676,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["pv2Volt"]
return None

Expand All @@ -702,7 +702,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["pv3Current"]
return None

Expand All @@ -728,7 +728,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["pv3Power"]
return None

Expand All @@ -754,7 +754,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["pv3Volt"]
return None

Expand All @@ -780,7 +780,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["pv4Current"]
return None

Expand All @@ -806,7 +806,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["pv4Power"]
return None

Expand All @@ -832,7 +832,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["pv4Volt"]
return None

Expand All @@ -858,7 +858,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["pvPower"]
return None

Expand All @@ -884,7 +884,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["RCurrent"]
return None

Expand All @@ -910,7 +910,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["RFreq"]
return None

Expand All @@ -936,7 +936,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["RPower"]
return None

Expand All @@ -961,7 +961,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> str | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["meterPower2"]
return None

Expand All @@ -987,7 +987,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["RVolt"]
return None

Expand All @@ -1013,7 +1013,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["SCurrent"]
return None

Expand All @@ -1039,7 +1039,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["SFreq"]
return None

Expand All @@ -1065,7 +1065,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["SPower"]
return None

Expand All @@ -1091,7 +1091,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["SVolt"]
return None

Expand All @@ -1117,7 +1117,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["TCurrent"]
return None

Expand All @@ -1143,7 +1143,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["TFreq"]
return None

Expand All @@ -1169,7 +1169,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["TPower"]
return None

Expand All @@ -1195,7 +1195,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["TVolt"]
return None

Expand All @@ -1221,7 +1221,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["ReactivePower"] * 1000
return None

Expand Down Expand Up @@ -1520,7 +1520,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
loads = float(self.coordinator.data["raw"]["loadsPower"])
if self.coordinator.data["raw"]["batChargePower"] is None:
charge = 0
Expand Down Expand Up @@ -1565,7 +1565,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["SoC"]
return None

Expand Down Expand Up @@ -1594,7 +1594,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["batTemperature"]
return None

Expand All @@ -1619,7 +1619,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["ambientTemperation"]
return None

Expand All @@ -1644,7 +1644,7 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["boostTemperation"]
return None

Expand All @@ -1669,6 +1669,6 @@ def __init__(self, coordinator, name, deviceID):

@property
def native_value(self) -> float | None:
if self.coordinator.data["online"]:
if self.coordinator.data["online"] and self.coordinator.data["raw"]:
return self.coordinator.data["raw"]["invTemperation"]
return None

0 comments on commit 4f7209e

Please sign in to comment.