Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions src/nwp500/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
__all__ = [
"device_bool_to_python",
"device_bool_from_python",
"tou_status_to_python",
"tou_override_to_python",
"div_10",
]
Expand Down Expand Up @@ -62,26 +61,6 @@ def device_bool_from_python(value: bool) -> int:
return 2 if value else 1


def tou_status_to_python(value: Any) -> bool:
"""Convert Time of Use status to Python bool.

Device representation: 0 = Off/False, 1 = On/True

Args:
value: Device TOU status value.

Returns:
Python boolean.

Example:
>>> tou_status_to_python(1)
True
>>> tou_status_to_python(0)
False
"""
return bool(value == 1)


def tou_override_to_python(value: Any) -> bool:
"""Convert TOU override status to Python bool.

Expand Down
3 changes: 1 addition & 2 deletions src/nwp500/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
div_10,
enum_validator,
tou_override_to_python,
tou_status_to_python,
)
from .enums import (
CurrentOperationMode,
Expand Down Expand Up @@ -56,7 +55,7 @@
Div10 = Annotated[float, BeforeValidator(div_10)]
HalfCelsiusToF = Annotated[float, BeforeValidator(half_celsius_to_fahrenheit)]
DeciCelsiusToF = Annotated[float, BeforeValidator(deci_celsius_to_fahrenheit)]
TouStatus = Annotated[bool, BeforeValidator(tou_status_to_python)]
TouStatus = Annotated[bool, BeforeValidator(device_bool_to_python)]
TouOverride = Annotated[bool, BeforeValidator(tou_override_to_python)]
VolumeCodeField = Annotated[
VolumeCode, BeforeValidator(enum_validator(VolumeCode))
Expand Down
53 changes: 3 additions & 50 deletions tests/test_model_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

Tests cover:
- device_bool_to_python (device 1=False, 2=True)
- tou_status_to_python (TOU status encoding)
- tou_override_to_python (TOU override status encoding)
- div_10 (divide by 10 converter)
- enum_validator (enum validation and conversion)

Note: tou_status field uses device_bool_to_python
(same as all other OnOffFlag fields)
"""

import pytest
Expand All @@ -15,7 +17,6 @@
div_10,
enum_validator,
tou_override_to_python,
tou_status_to_python,
)
from nwp500.enums import DhwOperationSetting, OnOffFlag

Expand Down Expand Up @@ -90,54 +91,6 @@ def test_off_value_variations(self, off_value):
assert device_bool_to_python(off_value) is False


class TestTouStatusConverter:
"""Test tou_status_to_python converter.

TOU (Time of Use) status encoding converts device state to boolean.
Device: 1 = Enabled (True), anything else = Disabled (False)
NOTE: String values are NOT converted to int before comparison.
"""

def test_tou_disabled(self):
"""TOU disabled state: 0 = False."""
result = tou_status_to_python(0)
assert isinstance(result, bool)
assert result is False

def test_tou_enabled(self):
"""TOU enabled state: 1 = True."""
result = tou_status_to_python(1)
assert isinstance(result, bool)
assert result is True

def test_string_disabled(self):
"""String '0' = TOU disabled."""
assert tou_status_to_python("0") is False

def test_string_enabled(self):
"""String '1' is not equal to int 1, so returns False."""
# tou_status_to_python uses: bool(value == 1)
# String "1" != int 1, so result is False
assert tou_status_to_python("1") is False

def test_invalid_value(self):
"""Value other than 1 is treated as False."""
assert tou_status_to_python(2) is False
assert tou_status_to_python(3) is False
assert tou_status_to_python(-1) is False

@pytest.mark.parametrize("enabled_value", [1, 1.0])
def test_enabled_variations(self, enabled_value):
"""Test numeric variations of enabled (value == 1)."""
# Only numeric 1 and float 1.0 equal int 1
assert tou_status_to_python(enabled_value) is True

@pytest.mark.parametrize("disabled_value", [0, "0", 0.0, 2, 3, -1, "1"])
def test_disabled_variations(self, disabled_value):
"""Test various representations of disabled (value != 1)."""
assert tou_status_to_python(disabled_value) is False


class TestTouOverrideConverter:
"""Test tou_override_to_python converter.

Expand Down