diff --git a/custom_components/e3dc_rscp/coordinator.py b/custom_components/e3dc_rscp/coordinator.py index d617674..4582297 100644 --- a/custom_components/e3dc_rscp/coordinator.py +++ b/custom_components/e3dc_rscp/coordinator.py @@ -8,6 +8,7 @@ from e3dc import E3DC # Missing Exports:; SendError, from e3dc._rscpLib import rscpFindTag +from e3dc._rscpTags import RscpTag, RscpType from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_HOST, CONF_PASSWORD, CONF_USERNAME @@ -84,7 +85,7 @@ async def async_connect(self): # Idea: Maybe Port this to e3dc lib, it can query this in one go during startup. self._sw_version = await self._async_e3dc_request_single_tag( - "INFO_REQ_SW_RELEASE" + RscpTag.INFO_REQ_SW_RELEASE ) await self._load_timezone_settings() @@ -160,7 +161,10 @@ async def _async_update_data(self) -> dict[str, Any]: _LOGGER.debug("Polling manual charge information") request_data = await self.hass.async_add_executor_job( - self.e3dc.sendRequest, ("EMS_REQ_GET_MANUAL_CHARGE", "None", None), 3, True + self.e3dc.sendRequest, + (RscpTag.EMS_REQ_GET_MANUAL_CHARGE, RscpType.NoneType, None), + 3, + True, ) self._process_manual_charge(request_data) @@ -237,14 +241,15 @@ def _process_db_data_today(self, db_data: dict[str, Any | None]) -> None: def _process_manual_charge(self, request_data) -> None: """Parse manual charge status.""" self._mydata["manual-charge-active"] = rscpFindTag( - request_data, "EMS_MANUAL_CHARGE_ACTIVE" + request_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. self._mydata["manual-charge-energy"] = ( - 3.65 * rscpFindTag(request_data, "EMS_MANUAL_CHARGE_ENERGY_COUNTER")[2] + 3.65 + * rscpFindTag(request_data, RscpTag.EMS_MANUAL_CHARGE_ENERGY_COUNTER)[2] ) # The timestamp seem to correctly show the UTC Date when manual charging started # Not yet enabled, just for reference. @@ -275,7 +280,7 @@ async def _load_timezone_settings(self): """ try: tz_name: str = await self._async_e3dc_request_single_tag( - "INFO_REQ_TIME_ZONE" + RscpTag.INFO_REQ_TIME_ZONE ) except: _LOGGER.exception("Failed to loade timezone from E3DC") @@ -295,10 +300,10 @@ async def _load_timezone_settings(self): try: # Fallback to compute the offset using current times from E3DC: ts_local: int = int( - await self._async_e3dc_request_single_tag("INFO_REQ_TIME") + await self._async_e3dc_request_single_tag(RscpTag.INFO_REQ_TIME) ) ts_utc: int = int( - await self._async_e3dc_request_single_tag("INFO_REQ_UTC_TIME") + await self._async_e3dc_request_single_tag(RscpTag.INFO_REQ_UTC_TIME) ) delta: int = ts_local - ts_utc tz_offset = int(1800 * round(delta / 1800)) @@ -495,7 +500,7 @@ async def async_manual_charge(self, charge_amount: int) -> None: # no update guard necessary, as we're called from a service, not an entity result_data = await self.hass.async_add_executor_job( self.e3dc.sendRequest, - ("EMS_REQ_START_MANUAL_CHARGE", "Uint32", charge_amount), + (RscpTag.EMS_REQ_START_MANUAL_CHARGE, RscpType.Uint32, charge_amount), 3, True, ) diff --git a/custom_components/e3dc_rscp/diagnostics.py b/custom_components/e3dc_rscp/diagnostics.py index 5fd491a..f925814 100644 --- a/custom_components/e3dc_rscp/diagnostics.py +++ b/custom_components/e3dc_rscp/diagnostics.py @@ -7,6 +7,7 @@ from typing import Any from e3dc import E3DC +from e3dc._rscpTags import RscpTag, RscpType from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant @@ -73,22 +74,26 @@ def _collect_data(self): ), "EMS_REQ_GET_MANUAL_CHARGE": self._query_data_for_dump( lambda: self.e3dc.sendRequestTag( - "EMS_REQ_GET_MANUAL_CHARGE", keepAlive=True + RscpTag.EMS_REQ_GET_MANUAL_CHARGE, keepAlive=True ) ), "DB_REQ_HISTORY_DATA_DAY": self._query_data_for_dump( lambda: self.e3dc.sendRequest( ( - "DB_REQ_HISTORY_DATA_DAY", + RscpTag.DB_REQ_HISTORY_DATA_DAY, "Container", [ ( - "DB_REQ_HISTORY_TIME_START", - "Uint64", + RscpTag.DB_REQ_HISTORY_TIME_START, + RscpType.Uint64, self.coordinator.data["db-day-startts"], ), - ("DB_REQ_HISTORY_TIME_INTERVAL", "Uint64", 86400), - ("DB_REQ_HISTORY_TIME_SPAN", "Uint64", 86400), + ( + RscpTag.DB_REQ_HISTORY_TIME_INTERVAL, + RscpType.Uint64, + 86400, + ), + (RscpTag.DB_REQ_HISTORY_TIME_SPAN, RscpType.Uint64, 86400), ], ), keepAlive=True, diff --git a/custom_components/e3dc_rscp/manifest.json b/custom_components/e3dc_rscp/manifest.json index e286699..d689f4f 100644 --- a/custom_components/e3dc_rscp/manifest.json +++ b/custom_components/e3dc_rscp/manifest.json @@ -12,9 +12,9 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/torbennehmer/hacs-e3dc/issues", "requirements": [ - "pye3dc==0.7.6" + "pye3dc==0.8.0" ], "ssdp": [], "version": "3.2.0", "zeroconf": [] -} +} \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index f22ba18..09234db 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,4 +2,4 @@ colorlog==6.7.0 homeassistant>=2023.8.0 pip>=21.0,<23.3 ruff==0.0.291 -pye3dc==0.7.6 \ No newline at end of file +pye3dc==0.8.0 \ No newline at end of file