Skip to content

Fix TOU status always showing False#57

Merged
eman merged 1 commit intomainfrom
fix/tou-status-always-false
Dec 26, 2025
Merged

Fix TOU status always showing False#57
eman merged 1 commit intomainfrom
fix/tou-status-always-false

Conversation

@eman
Copy link
Copy Markdown
Owner

@eman eman commented Dec 26, 2025

Problem

TOU status was always reporting False regardless of actual device state.

Root Cause

Version 7.2.1 incorrectly used device_bool_to_python converter (1/2 encoding) for the touStatus field, but the device actually uses standard 0/1 encoding:

  • 0 = disabled/False
  • 1 = enabled/True

Solution

Use Python's built-in bool() which naturally handles 0/1 encoding. This is simpler and clearer than creating a custom converter.

Changes

  • src/nwp500/models.py: Changed TouStatus to use BeforeValidator(bool)
  • tests/test_model_converters.py: Added TestBuiltinBoolForTouStatus with 15 test cases
  • docs/protocol/quick_reference.rst: Updated to note touStatus uses 0/1 encoding (exception to standard 1/2)
  • CHANGELOG.rst: Added Version 7.2.2 entry

Validation

✅ All 378 tests passing (+1 new test class)
✅ Linting: All checks passed
✅ Type checking: No issues found

Testing

# Device value → Python bool
bool(0)  # False (TOU disabled) ✓
bool(1)  # True (TOU enabled) ✓

Fixes the issue where TOU status always appeared as False.

Root cause: touStatus field was incorrectly using device_bool_to_python
converter (1/2 encoding), but the device uses standard 0/1 encoding.

Solution: Use Python's built-in bool() which naturally handles 0=False,
1=True encoding. This is simpler than a custom converter.

Changes:
- models.py: Use BeforeValidator(bool) for TouStatus field
- tests: Added TestBuiltinBoolForTouStatus with 15 test cases
- docs: Updated quick_reference.rst noting touStatus exception
- CHANGELOG.rst: Added Version 7.2.2 entry

Device encoding: 0=disabled/False, 1=enabled/True

Fixes issue where TOU status always reported False regardless of
actual device state.

All 378 tests passing.
@eman eman merged commit 903bd26 into main Dec 26, 2025
7 checks passed
@eman eman deleted the fix/tou-status-always-false branch December 26, 2025 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant