Skip to content

Commit

Permalink
Emergency workaround manual charging API (#118)
Browse files Browse the repository at this point in the history
Apparently, E3DC changed the manual charging API with firmware release
P10_2023_06. Since then pye3dc reports an unknown tag, which then throws
an exception. For now, we'll just catch it and provide dummy values for
the manual charging sensors.

works around #114
  • Loading branch information
torbennehmer authored Mar 7, 2024
2 parents 073c7e6 + aaf26e9 commit 9a2c59d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
51 changes: 29 additions & 22 deletions custom_components/e3dc_rscp/e3dc_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,28 +118,35 @@ def get_db_data(self, timestamp: int, timespan_seconds: int) -> dict[str, Any]:
@e3dc_call
def get_manual_charge(self) -> dict[str, Any]:
"""Poll manual charging state."""
data = self.e3dc.sendRequest(
(RscpTag.EMS_REQ_GET_MANUAL_CHARGE, RscpType.NoneType, None), keepAlive=True
)

result: dict[str, Any] = {}
result["active"] = rscpFindTag(data, RscpTag.EMS_MANUAL_CHARGE_ACTIVE)[2]

# These seem to be kAh per individual cell, so this is considered very strange.
# To get this working for a start, we assume 3,65 V per cell, taking my own unit
# as a base, but this obviously will need some real work to base this on
# current voltages.
# Round to Watts, this should prevent negative values in the magnitude of 10^-6,
# which are probably floating point errors.
tmp = rscpFindTag(data, RscpTag.EMS_MANUAL_CHARGE_ENERGY_COUNTER)[2]
powerfactor = 3.65
result["energy"] = round(tmp * powerfactor, 3)

# The timestamp seem to correctly show the UTC Date when manual charging started
# Not yet enabled, just for reference.
# self._mydata["manual-charge-start"] = rscpFindTag(
# request_data, "EMS_MANUAL_CHARGE_LASTSTART"
# )[2]
try:
data = self.e3dc.sendRequest(
(RscpTag.EMS_REQ_GET_MANUAL_CHARGE, RscpType.NoneType, None), keepAlive=True
)

result: dict[str, Any] = {}
result["active"] = rscpFindTag(data, RscpTag.EMS_MANUAL_CHARGE_ACTIVE)[2]

# These seem to be kAh per individual cell, so this is considered very strange.
# To get this working for a start, we assume 3,65 V per cell, taking my own unit
# as a base, but this obviously will need some real work to base this on
# current voltages.
# Round to Watts, this should prevent negative values in the magnitude of 10^-6,
# which are probably floating point errors.
tmp = rscpFindTag(data, RscpTag.EMS_MANUAL_CHARGE_ENERGY_COUNTER)[2]
powerfactor = 3.65
result["energy"] = round(tmp * powerfactor, 3)

# The timestamp seem to correctly show the UTC Date when manual charging started
# Not yet enabled, just for reference.
# self._mydata["manual-charge-start"] = rscpFindTag(
# request_data, "EMS_MANUAL_CHARGE_LASTSTART"
# )[2]
except SendError:
_LOGGER.debug("Failed to query manual charging data, might be related to a recent E3DC API change, ignoring the error, reverting to empty defaults.")
result: dict[str, Any] = {}
result["active"] = False
result["energy"] = 0
result["possible_API_bug"] = "got send error"

return result

Expand Down
2 changes: 1 addition & 1 deletion custom_components/e3dc_rscp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
"pye3dc==0.9.0"
],
"ssdp": [],
"version": "3.6.0",
"version": "3.6.1-beta.1",
"zeroconf": []
}

0 comments on commit 9a2c59d

Please sign in to comment.