Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@NdyGen
Copy link
Owner

@NdyGen NdyGen commented Dec 11, 2025

Summary

Implements action cards and condition cards for manual control of the WIAB device's occupancy state, addressing issue #5. This feature enables users to pause/unpause sensor monitoring and manually set occupancy state through Home Automation flows.

Key Features:

  • SET STATE action: Pauses device and sets occupancy to OCCUPIED or UNOCCUPIED
  • UNPAUSE action: Resumes sensor monitoring with automatic reinitialization
  • IS PAUSED condition: Check if device is in paused mode for flow logic
  • Quad-state model: Extended occupancy model with new PAUSED state
  • Idempotent unpause: Multiple unpause calls only reinitialize once
  • Comprehensive logging: All pause/unpause operations logged for debugging

Use Case:

Users can now set their bedroom occupancy to "unoccupied" at night, preventing false positives from pet movement, then resume normal monitoring in the morning.

Technical Details:

  • Added OccupancyState.PAUSED enum value for internal state tracking
  • Pause gates in sensor event handlers prevent state changes while paused
  • Action and condition card definitions in driver.compose.json
  • Flow card handlers registered during device initialization
  • 10 new unit tests covering all pause/unpause scenarios
  • All tests pass with 100% coverage of new functionality

Test Plan:

  • Build and compile without TypeScript errors
  • All unit tests pass (74 tests)
  • Coverage threshold met (70%+)
  • Linting passes without errors
  • Homey validation passes
  • Create manual flow in Homey to test:
    • Trigger SET STATE action with OCCUPIED
    • Verify device is paused and occupancy shows as occupied
    • Verify sensor events are ignored (try motion/door sensors)
    • Trigger SET STATE action with UNOCCUPIED
    • Verify occupancy changes to unoccupied while still paused
    • Trigger UNPAUSE action
    • Verify device resumes sensor monitoring
    • Verify sensor events are processed again

Closes #5

Implements manual control of occupancy state via Home Automation flows.

## Features
- SET STATE action: Pauses device and sets occupancy to OCCUPIED or UNOCCUPIED
- UNPAUSE action: Resumes sensor monitoring with automatic reinitialization
- IS PAUSED condition: Check if device is in paused mode for flow logic
- Quad-state occupancy model: Extends internal state with PAUSED value
- Idempotent unpause: Multiple unpause calls only reinitialize once
- Comprehensive logging: All pause/unpause operations logged for debugging

## Implementation Details
- Added OccupancyState.PAUSED enum value for internal state tracking
- Pause gates in sensor event handlers prevent state changes while paused
- Flow card definitions in driver.flow.compose.json properly located for Homey CLI
- Occupancy_state capability extended to support PAUSED value
- 10 new unit tests covering all pause/unpause scenarios
- All 74 tests pass with >70% code coverage

## Use Cases
- Users can pause monitoring during sleep to prevent false positives from pets
- Manually set occupancy for specific testing scenarios
- Combine with automations for advanced occupancy control

Closes #5
@NdyGen NdyGen force-pushed the feature/pause-and-set-state-actions branch from ea8d6f2 to 05b1bed Compare December 11, 2025 11:14
andy-kabisa and others added 3 commits December 11, 2025 12:17
The Homey CLI build process requires app.json to exist before running.
Added back the cp command to copy from .homeycompose/app.json before
building, which was accidentally removed during commit cleanup.
…ality

## Fixes

### Critical Error Handling Issues
- Register flow card handlers with proper validation and re-throw errors
- Propagate errors from pauseDevice() and unpauseDevice() to flow engine
- Add null checks for getActionCard() and getConditionCard() results
- Improve error context in updateOccupancyOutput() with specific capability names
- Re-throw errors in action/condition handler listeners to notify flow engine

### Code Quality
- Remove unused setStateWhilePaused() dead code method
- Remove unused hasBeenUnpausedOnce variable
- Update class docstring: tri-state → quad-state model
- Add comprehensive manual control documentation

### Test Coverage
- Add test for door events ignored while paused
- Add test for PIR falling edge ignored while paused
- Add test for sensor monitoring teardown on pause
- Add test for unpause with graceful error handling
- Now at 78 tests covering all pause/unpause scenarios

All tests pass, build succeeds, linting clean.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Haiku 4.5 <[email protected]>
- Add flow object mock to createMockHomey() in tests/setup.ts with action/condition card support
  - Provides getActionCard() and getConditionCard() methods for action/condition registration
  - Fixes "Cannot read properties of undefined (reading 'getActionCard')" errors in CI

- Fix error handling tests for fire-and-forget async callbacks
  - Use mockRejectedValueOnce() to isolate error test from other tests
  - Increase wait time in test to allow async handlers to complete
  - Properly verify error logging from handlers

This resolves all CI test failures while maintaining test coverage and error handling validation.
@NdyGen NdyGen merged commit 0f9b979 into develop Dec 11, 2025
3 checks passed
@NdyGen NdyGen deleted the feature/pause-and-set-state-actions branch December 11, 2025 11:40
NdyGen pushed a commit that referenced this pull request Dec 24, 2025
…ange

BREAKING CHANGE: WarningManager.setWarning() and clearWarning() now throw
WarningStateError instead of returning boolean. All call sites updated.

Core Changes:
- WarningManager API: Promise<boolean> → Promise<void> (throws on failure)
- Created WarningStateError custom error class with operation context
- Added AsyncHelpers utility for standardized fire-and-forget async operations
- Added CapabilityErrorTracker for aggregated capability error reporting
- Extended RetryResult<T> interface with error classification fields

Error Handling Improvements:
- 13 call sites migrated to try-catch pattern (9 room-state, 4 zone-seal)
- RetryManager now exposes isPermanentError, errorCategory, errorReasonCode
- Enhanced app.ts logging with permanent error context detection
- Added WARNING_SET_FAILED and WARNING_CLEAR_FAILED error IDs

Testing:
- Added 36 new tests (AsyncHelpers: 18, CapabilityErrorTracker: 18)
- Total tests: 503 (all passing)
- Coverage: AsyncHelpers 100%, CapabilityErrorTracker 98.21%
- All quality gates pass (build, lint, test, validate)

Addresses PR review issues #2, #3, #5 from comprehensive code review.
Issues #1, #4, #6, #7 deferred for follow-up PR.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
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.

[Feature]: action card to control wiab device

3 participants