Skip to content

Commit

Permalink
Upgrade pye3dc Dependency to 0.8.0 (#69)
Browse files Browse the repository at this point in the history
Rewrite all Tags / Types to use the new enum.
Fixes #45
  • Loading branch information
torbennehmer authored Oct 20, 2023
2 parents 31535c3 + 10fc5cc commit 8fc9804
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
21 changes: 13 additions & 8 deletions custom_components/e3dc_rscp/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand All @@ -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))
Expand Down Expand Up @@ -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,
)
Expand Down
17 changes: 11 additions & 6 deletions custom_components/e3dc_rscp/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions custom_components/e3dc_rscp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
}
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
pye3dc==0.8.0

0 comments on commit 8fc9804

Please sign in to comment.