Skip to content

Fix TOU status showing inverted values#55

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

Fix TOU status showing inverted values#55
eman merged 1 commit intomainfrom
fix/tou-status-inverted

Conversation

@eman
Copy link
Copy Markdown
Owner

@eman eman commented Dec 26, 2025

Problem

TOU (Time of Use) status was always appearing as OFF regardless of the actual state.

Root Cause

The tou_status_to_python converter was using incorrect device protocol encoding:

  • Old (incorrect): 0 = OFF, 1 = ON
  • Correct: 1 = OFF, 2 = ON (standard OnOffFlag encoding)

When the device sent 2 (ON), the converter incorrectly returned False. When the device sent 1 (OFF), it incorrectly returned True. The values were inverted!

Solution

  • Updated tou_status_to_python() to use the correct OnOffFlag encoding where 1=OFF and 2=ON
  • Fixed all TOU status converter tests to match the correct encoding
  • Added documentation noting this uses standard OnOffFlag encoding

Testing

✅ All 378 tests passing
✅ Linting checks passing (ruff)
✅ Type checking passing (mypy on converters.py)
✅ No new errors introduced

The TOU status will now correctly report ON when enabled and OFF when disabled.

@eman eman force-pushed the fix/tou-status-inverted branch from a474c4f to 9f9a3a8 Compare December 26, 2025 04:55
TOU status was always appearing as OFF regardless of actual state.

Root cause: tou_status_to_python converter was using incorrect encoding:
- Old (incorrect): 0 = OFF, 1 = ON
- Correct: 1 = OFF, 2 = ON (standard OnOffFlag encoding)

When device sent 2 (ON), converter returned False. When device sent 1 (OFF),
it incorrectly returned True.

Changes:
- Removed duplicate tou_status_to_python() function
- Updated TouStatus type to use device_bool_to_python (same as all OnOffFlag)
- Removed redundant TOU status converter tests (already covered by device_bool)
- Simplified converters module exports

This eliminates code duplication since tou_status uses the same encoding as
all other OnOffFlag fields in the device protocol.

All 363 tests pass.
@eman eman force-pushed the fix/tou-status-inverted branch from 9f9a3a8 to f3bb418 Compare December 26, 2025 04:58
@eman eman merged commit 96aa1cc into main Dec 26, 2025
7 checks passed
@eman eman deleted the fix/tou-status-inverted branch December 26, 2025 05:02
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