Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reorg data extraction to prevent NoneType exceptions #95

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 26 additions & 30 deletions custom_components/alphaess/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,55 +41,51 @@ async def _async_update_data(self):
_onedateenergy = invertor.get("OneDateEnergy", {})
# data from last power data API
_powerdata = invertor.get("LastPower", {})
_gridpowerdetails = _powerdata.get("pgridDetail",{})
_pvpowerdetails = _powerdata.get("ppvDetail",{})

_pv = _onedateenergy.get("epv")
_feedin = _onedateenergy.get("eOutput")
_gridcharge = _onedateenergy.get("eGridCharge")
_charge = _onedateenergy.get("eCharge")
_soc = _powerdata.get("soc")

if _sumdata != None:
# Still will keep in, but will be provided with the timezone difference
inverterdata.update({"Total Load": _sumdata.get("eload")})

if _onedateenergy != None:
_pv = _onedateenergy.get("epv")
_feedin = _onedateenergy.get("eOutput")
_gridcharge = _onedateenergy.get("eGridCharge")
_charge = _onedateenergy.get("eCharge")

if _charge != None and _gridcharge != None:
inverterdata.update({"Solar Production": _pv})
inverterdata.update({"Solar to Load": _pv - _feedin})
inverterdata.update({"Solar to Grid": _feedin})
inverterdata.update({"Solar to Battery": _charge - _gridcharge})

if _pv != None and _feedin != None:
inverterdata.update({"Solar to Load": _pv - _feedin})

if _gridcharge != None:
inverterdata.update({"Grid to Load": _onedateenergy.get("eInput")})
inverterdata.update({"Grid to Battery": _gridcharge})

if _onedateenergy != None:
inverterdata.update({"EV Charger": _onedateenergy.get("eChargingPile")})
inverterdata.update({"Solar Production": _onedateenergy.get("epv")})
inverterdata.update({"Grid to Load": _onedateenergy.get("eInput")})
inverterdata.update({"Charge": _onedateenergy.get("eCharge")})
inverterdata.update({"Charge": _charge})
inverterdata.update({"Discharge": _onedateenergy.get("eDischarge")})
inverterdata.update({"Solar to Grid": _onedateenergy.get("eOutput")})

if _powerdata != None:
inverterdata.update({"Instantaneous Generation": _powerdata.get("ppv")})
inverterdata.update({"EV Charger": _onedateenergy.get("eChargingPile")})

if _pvpowerdetails != None:
inverterdata.update({"Instantaneous PPV1": _pvpowerdetails.get("ppv1")})
inverterdata.update({"Instantaneous PPV2": _pvpowerdetails.get("ppv2")})
inverterdata.update({"Instantaneous PPV3": _pvpowerdetails.get("ppv3")})
inverterdata.update({"Instantaneous PPV4": _pvpowerdetails.get("ppv4")})
if _powerdata != None:
_soc = _powerdata.get("soc")
_gridpowerdetails = _powerdata.get("pgridDetail",{})
_pvpowerdetails = _powerdata.get("ppvDetail",{})

if _soc != None:
# wonder why do we have this twice
inverterdata.update({"Instantaneous Battery SOC": _soc})
inverterdata.update({"State of Charge": _soc})

if _powerdata != None:
inverterdata.update({"Instantaneous Battery I/O": _powerdata.get("pbat")})
inverterdata.update({"Instantaneous Grid I/O Total": _powerdata.get("pgrid")})
inverterdata.update({"Instantaneous Load": _powerdata.get("pload")})

if _gridpowerdetails != None:
inverterdata.update({"Instantaneous Generation": _powerdata.get("ppv")})
# pv power generation details
inverterdata.update({"Instantaneous PPV1": _pvpowerdetails.get("ppv1")})
inverterdata.update({"Instantaneous PPV2": _pvpowerdetails.get("ppv2")})
inverterdata.update({"Instantaneous PPV3": _pvpowerdetails.get("ppv3")})
inverterdata.update({"Instantaneous PPV4": _pvpowerdetails.get("ppv4")})

inverterdata.update({"Instantaneous Grid I/O Total": _powerdata.get("pgrid")})
# grid power usage details
inverterdata.update({"Instantaneous Grid I/O L1": _gridpowerdetails.get("pmeterL1")})
inverterdata.update({"Instantaneous Grid I/O L2": _gridpowerdetails.get("pmeterL2")})
inverterdata.update({"Instantaneous Grid I/O L3": _gridpowerdetails.get("pmeterL3")})
Expand Down
Loading