Skip to content

Commit

Permalink
tweak get fault log
Browse files Browse the repository at this point in the history
  • Loading branch information
zxdavb committed Aug 16, 2024
1 parent ad23c13 commit 9b38bc1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
13 changes: 6 additions & 7 deletions src/ramses_rf/system/faultlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ class FaultLog: # 0418 # TODO: use a NamedTuple
in the system log.
New entries are added to the top of the log (log_idx=0), and the log_idx is
incremented for all exisiting log enties.
incremented for all existing log enties.
"""

_MAX_LOG_IDX = 0x3E
_MAX_LOG_IDX = 0x3F # evohome controller only keeps most recent 64 entries

def __init__(self, tcs: _LogbookT) -> None:
self._tcs: _LogbookT = tcs
Expand Down Expand Up @@ -280,7 +280,8 @@ async def get_faultlog(

self._is_getting = True

for idx in range(start, min(start + limit, 64)):
# TODO: handle exc.RamsesException (RQ retries exceeded)
for idx in range(start, min(start + limit, self._MAX_LOG_IDX + 1)):
cmd = Command.get_system_log_entry(self.id, idx)
pkt = await self._gwy.async_send_cmd(cmd, wait_for_reply=True)

Expand All @@ -304,16 +305,14 @@ def faultlog(self) -> dict[FaultIdxT, FaultLogEntry]:

return {idx: self._log[dtm] for idx, dtm in self._map.items()}

def is_current(self, force_io: bool | None = None) -> bool:
def is_current(self, force_io: bool | None = None) -> bool: # TODO
"""Return True if the local fault log is identical to the controllers.
If force_io, retrieve the 0th log entry and check it is identical to the local
copy.
"""

if not self._is_current:
return False
return True
return self._is_current

@property
def latest_event(self) -> FaultLogEntry | None:
Expand Down
11 changes: 3 additions & 8 deletions src/ramses_rf/system/heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from types import SimpleNamespace
from typing import TYPE_CHECKING, Any, NoReturn, TypeVar

from ramses_rf import exceptions as exc
from ramses_rf.const import (
SYS_MODE_MAP,
SZ_ACTUATORS,
Expand Down Expand Up @@ -717,13 +716,9 @@ async def get_faultlog(
limit: int | None = None,
force_refresh: bool = False,
) -> dict[FaultIdxT, FaultLogEntry] | None:
try:
return await self._faultlog.get_faultlog(
start=start, limit=limit, force_refresh=force_refresh
)
except exc.RamsesException as err:
_LOGGER.error("%s: Failed to get faultlog: %s", self, err)
return None
return await self._faultlog.get_faultlog(
start=start, limit=limit, force_refresh=force_refresh
)

@property
def active_faults(self) -> tuple[str, ...] | None:
Expand Down
2 changes: 1 addition & 1 deletion src/ramses_tx/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def _put_system_log_entry(
_log_idx = 0
if not isinstance(_log_idx, str):
_log_idx = f"{_log_idx:02X}"
assert 0 <= int(_log_idx, 16) <= 0x3E
assert 0 <= int(_log_idx, 16) <= 0x3F # TODO: is it 0x3E or 0x3F?

if timestamp is None:
timestamp = dt.now() #
Expand Down

0 comments on commit 9b38bc1

Please sign in to comment.