9 Commits

Author SHA1 Message Date
c2064a76eb Add Web Bluetooth support for browser-based sensor setup
- Add webBluetooth.ts with browser detection and compatibility checks
- Add WebBLEManager implementing IBLEManager for Web Bluetooth API
- Add BrowserNotSupported component showing clear error for Safari/Firefox
- Update services/ble/index.ts to use WebBLEManager on web platform
- Add comprehensive tests for browser detection and WebBLEManager

Works in Chrome/Edge/Opera, shows user-friendly error in unsupported browsers.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-01 10:48:01 -08:00
5f40370dfa Add unit tests for BLE error handling, bulk operations, and WiFi validation
- BLEErrors.test.ts: Tests for BLEError class, parseBLEError function,
  isBLEError, getErrorInfo, getRecoveryActionLabel, and BLELogger utilities
- BLEManager.bulk.test.ts: Tests for bulkDisconnect, bulkReboot, and
  bulkSetWiFi operations including progress callbacks and edge cases
- BLEManager.wifi.test.ts: Tests for WiFi credential validation (SSID/password),
  error scenarios, getWiFiList, getCurrentWiFi, and signal quality

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-01 10:38:56 -08:00
f8156b2dc7 Add BLE auto-reconnect with exponential backoff
- Add ReconnectConfig and ReconnectState types for configurable reconnect behavior
- Implement auto-reconnect in BLEManager with exponential backoff (default: 3 attempts, 1.5x multiplier)
- Add connection monitoring via device.onDisconnected() for unexpected disconnections
- Update BLEContext with reconnectingDevices state and reconnect actions
- Create ConnectionStatusIndicator component for visual connection feedback
- Enhance device settings screen with reconnect UI and manual reconnect capability
- Add comprehensive tests for reconnect logic and UI component

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-31 17:31:15 -08:00
d289dd79a1 Add comprehensive sensor health monitoring system
Implemented a full sensor health monitoring system for WP sensors that
tracks connectivity, WiFi signal strength, communication quality, and
overall device health.

Features:
- Health status calculation (excellent/good/fair/poor/critical)
- WiFi signal quality monitoring (RSSI-based)
- Communication statistics tracking (success rate, response times)
- BLE connection metrics (RSSI, attempt/failure counts)
- Time-based status (online/warning/offline based on last seen)
- Health data caching and retrieval

Components:
- Added SensorHealthMetrics types with detailed health indicators
- Implemented getSensorHealth() and getAllSensorHealth() in BLEManager
- Created SensorHealthCard UI component for health visualization
- Added API endpoints for health history and reporting
- Automatic communication stats tracking on every BLE command

Testing:
- 12 new tests for health monitoring functionality
- All 89 BLE tests passing
- No linting errors

This enables proactive monitoring of sensor health to identify
connectivity issues, poor WiFi signal, or failing devices before they
impact user experience.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-31 16:15:32 -08:00
e34ed5282a Add comprehensive BLE integration tests
Implemented integration tests for BLE functionality covering:
- Connection flow state machine (connecting, discovering, ready)
- Event system (listeners, state changes, connection events)
- WiFi operations (scan, configure, status, reboot)
- Error handling (timeouts, disconnections, concurrent connections)
- Batch operations (multiple device connections, cleanup)
- State machine edge cases (device name, timestamps)

Tests cover both RealBLEManager and MockBLEManager to ensure
consistent behavior across real devices and simulator.

Updated Jest configuration:
- Added expo winter runtime mocks
- Added structuredClone polyfill
- Added React Native module mocks (Platform, PermissionsAndroid, Linking, Alert)
- Updated transform ignore patterns for BLE modules

All 36 tests passing with comprehensive coverage of BLE integration.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-31 15:50:54 -08:00
2c1b37877d Add concurrent connection protection to BLE managers
Prevents race conditions when multiple connection attempts are made
to the same device simultaneously by:
- Adding connectingDevices Set to track in-progress connections
- Checking for concurrent connections before starting new attempt
- Returning early if device is already connected
- Using finally block to ensure cleanup of connecting state
- Clearing connectingDevices set on cleanup

Includes comprehensive test suite for concurrent connection scenarios
including edge cases like rapid connect/disconnect cycles and cleanup
during connection attempts.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-31 15:39:36 -08:00
d9914b74b2 Implement BLE connection state machine
Add comprehensive connection state management to BLE Manager with:
- Connection state enum (DISCONNECTED, CONNECTING, CONNECTED, DISCOVERING, READY, DISCONNECTING, ERROR)
- State tracking for all devices with connection metadata
- Event emission system for state changes and connection events
- Event listeners for monitoring connection lifecycle
- Updated both RealBLEManager and MockBLEManager implementations
- Added test suite for state machine functionality
- Updated jest.setup.js with BLE mocks

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-31 15:33:54 -08:00
a30769387f Add BLE scanning cleanup on screen blur
Implement proper cleanup of BLE scanning operations when users navigate
away from the add-sensor screen to prevent resource waste and potential
issues.

Changes:
- Add useFocusEffect hook to stop BLE scan when screen loses focus
- Remove unused imports (Device, WPDevice, connectDevice, etc.)
- Add comprehensive tests for BLE cleanup behavior
- Add tests for screen unmount/blur scenarios

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-29 12:08:37 -08:00
2b2bd88726 Add BLE cleanup on user logout
Implement comprehensive BLE cleanup functionality that properly
disconnects all devices and releases resources when user logs out.

Changes:
- Add cleanup() method to BLEManager and MockBLEManager
- Update IBLEManager interface to include cleanup
- Add cleanupBLE() to BLEContext to disconnect all devices
- Implement callback mechanism in api.ts for BLE cleanup on logout
- Wire up BLE cleanup in app layout to trigger on logout
- Add unit tests for BLE cleanup functionality

This ensures no BLE connections remain active after logout,
preventing resource leaks and potential connection issues.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-29 10:57:43 -08:00