Skip to content

Commit

Permalink
swap code block, correct doc typos
Browse files Browse the repository at this point in the history
  • Loading branch information
zxdavb committed Oct 18, 2024
1 parent 79b2ee7 commit c71b498
Showing 1 changed file with 24 additions and 25 deletions.
49 changes: 24 additions & 25 deletions src/ramses_tx/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,30 +643,6 @@ def _parse_hvac_temp(param_name: str, value: HexStr4) -> Mapping[str, float | No


# 31DA[30:34]
def parse_bypass_position(value: HexStr2) -> PayDictT.BYPASS_POSITION:
"""Return the bypass position (%), usually fully open or closed (0%, no bypass).
The sensor value is None if there is no sensor present (is not an error).
The dict does not include the key if there is a sensor fault.
"""

# TODO: remove this...
if not isinstance(value, str) or len(value) != 2:
raise ValueError(f"Invalid value: {value}, is not a 2-char hex string")

if value == "EF": # Not implemented
return {SZ_BYPASS_POSITION: None}

if int(value[:2], 16) & 0xF0 == 0xF0:
return _faulted_device(SZ_BYPASS_POSITION, value) # type: ignore[return-value]

bypass_pos = int(value, 16) / 200 # was: hex_to_percent(value)
assert bypass_pos <= 1.0, value

return {SZ_BYPASS_POSITION: bypass_pos}


# 31DA[34:36]
def parse_capabilities(value: HexStr4) -> PayDictT.CAPABILITIES:
"""Return the speed capabilities (a bitmask).
Expand Down Expand Up @@ -709,6 +685,30 @@ def parse_capabilities(value: HexStr4) -> PayDictT.CAPABILITIES:
}


# 31DA[34:36]
def parse_bypass_position(value: HexStr2) -> PayDictT.BYPASS_POSITION:
"""Return the bypass position (%), usually fully open or closed (0%, no bypass).
The sensor value is None if there is no sensor present (is not an error).
The dict does not include the key if there is a sensor fault.
"""

# TODO: remove this...
if not isinstance(value, str) or len(value) != 2:
raise ValueError(f"Invalid value: {value}, is not a 2-char hex string")

if value == "EF": # Not implemented
return {SZ_BYPASS_POSITION: None}

if int(value[:2], 16) & 0xF0 == 0xF0:
return _faulted_device(SZ_BYPASS_POSITION, value) # type: ignore[return-value]

bypass_pos = int(value, 16) / 200 # was: hex_to_percent(value)
assert bypass_pos <= 1.0, value

return {SZ_BYPASS_POSITION: bypass_pos}


# 31DA[36:38] # TODO: WIP (3 more bits), also 22F3?
def parse_fan_info(value: HexStr2) -> PayDictT.FAN_INFO:
"""Return the fan info (current speed, and...).
Expand All @@ -724,7 +724,6 @@ def parse_fan_info(value: HexStr2) -> PayDictT.FAN_INFO:
# if value == "EF": # TODO: Not implemented???
# return {SZ_FAN_INFO: None}

assert int(value, 16) & 0x1F <= 0x19, f"invalid fan_info: {int(value, 16) & 0x1F}"
assert int(value, 16) & 0xE0 in (
0x00,
0x20,
Expand Down

0 comments on commit c71b498

Please sign in to comment.