Skip to content

Comments

[Dev Portal] Phase 2: Device Simulation - Battery & Storage Testing#418

Merged
hossain-khan merged 1 commit intomainfrom
feature/dev-portal-phase2-device-simulation
Dec 11, 2025
Merged

[Dev Portal] Phase 2: Device Simulation - Battery & Storage Testing#418
hossain-khan merged 1 commit intomainfrom
feature/dev-portal-phase2-device-simulation

Conversation

@hossain-khan
Copy link
Owner

🎯 Overview

Implements Phase 2 of the Developer Portal - Device Simulation for testing battery and storage alerts without waiting for actual device conditions.

Closes: #410
Epic: #416
Depends on: #417 (Phase 1 - merged)


📋 Changes Made

Enhanced State & Events

  • ✨ Added maxStorageGb, isSimulating, and simulationResult to State
  • ✨ Added SimulateBatteryAlert and SimulateStorageAlert events
  • ✨ Integrated notification senders for actual alert delivery

New Features

  1. Battery Level Simulation

    • Slider from 0% to 100%
    • Shows both simulated and actual battery levels
    • "Simulate Battery Alert" button
  2. Storage Space Simulation

    • Slider from 1GB to device maximum
    • Shows both simulated and actual storage levels
    • "Simulate Storage Alert" button
  3. Notification Sending

    • Sends test alerts to ALL configured notification channels
    • Tracks success/failure count for each channel
    • Shows result via Snackbar with detailed feedback
    • Loading state with CircularProgressIndicator

UI Components

  • DeviceSimulationCard - Dedicated component with sliders and controls
  • ✨ Snackbar integration for user feedback
  • ✨ Loading states during async operations

✨ Features Implemented

1. Battery Simulation

  • Slider from 0% to 100%
  • Display actual battery level for comparison
  • Test alert generation with simulated value
  • Send to all configured channels
  • Success/failure feedback

2. Storage Simulation

  • Slider from 1GB to device max
  • Display actual storage for comparison
  • Test alert generation with simulated value
  • Send to all configured channels
  • Success/failure feedback

3. Alert Delivery

  • Test alerts use ID = -1L (distinguishable from real alerts)
  • Bypass 24-hour cooldown (immediate testing)
  • Send to Email, Telegram, Twilio, Slack, Discord, Webhook
  • Count successes and failures
  • Timber logging for debugging

🎨 UI Demo

┌────────────────────────────────────┐
│ 📱 Device Simulation               │
│ Test notifications with simulated  │
│ values                             │
├────────────────────────────────────┤
│ 🔋 Battery Level                   │
│ Simulated: 15% (Actual: 75%)       │
│ [===========         ] 0% ─── 100% │
│ [Simulate Battery Alert]           │
├────────────────────────────────────┤
│ 💾 Storage Space                   │
│ Simulated: 8 GB (Actual: 45 GB)    │
│ [========            ] 1GB ─── 96GB│
│ [Simulate Storage Alert]           │
└────────────────────────────────────┘

Snackbar: "✓ Battery alert sent! 3 succeeded, 0 failed"

🔍 Testing

Manual Testing Scenarios

  • Move battery slider - values update smoothly
  • Move storage slider - values update smoothly
  • Simulate with NO channels configured - shows error message
  • Simulate with channels configured - notifications sent
  • Test with Email configured - received test email
  • Test with Telegram configured - received test message
  • Verify loading state during sending
  • Check Timber logs for detailed debugging info

Test Results

// Test Alert Structure
RemoteAlert.BatteryAlert(
    alertId = -1L,              // Test ID
    batteryPercentage = 20,      // Threshold
    currentBatteryLevel = 15     // Simulated value
)

RemoteAlert.StorageAlert(
    alertId = -1L,                    // Test ID
    storageMinSpaceGb = 10,           // Threshold
    currentStorageGb = 8.0            // Simulated value
)

📚 Technical Details

Notification Logic

// For each configured notifier
notifiers.forEach { notifier ->
    if (notifier.hasValidConfig()) {
        val result = notifier.sendNotification(testAlert)
        if (result) successCount++ else failCount++
    }
}

// Result feedback
simulationResult = if (successCount > 0) {
    "✓ Alert sent! $successCount succeeded, $failCount failed"
} else {
    "✗ No notifications sent. Configure at least one channel first."
}

State Management

  • Coroutine scope for async operations
  • isSimulating prevents multiple simultaneous sends
  • simulationResult triggers Snackbar display
  • Slider values maintained in local state

Dependencies Added

  • RemoteAlertRepository - For repository access (future use)
  • NotificationSender set - All notification channel implementations
  • Timber - Enhanced logging for debugging

✅ Acceptance Criteria Met

  • Battery slider works from 0-100%
  • Storage slider works from 1GB to device max
  • Actual device values displayed accurately
  • Simulate buttons trigger notifications
  • Test alerts don't create logs (ID = -1L)
  • User receives clear feedback (success/error)
  • Loading state prevents duplicate sends
  • Works with any combination of configured channels

🔗 Integration Points

Depends On

Enables

  • Instant testing of all notification channels
  • No waiting for actual device conditions
  • Rapid iteration during development

🚀 Next Steps

After this PR is merged:


📝 Notes

  • Test alerts will be sent to actual notification channels (Email, Telegram, etc.)
  • Ensure at least one channel is configured before testing
  • Slider values are independent of actual device state
  • No 24-hour cooldown for test alerts
  • Check Timber logs for detailed debugging information

Estimated Development Time: 3-4 hours
Actual Time: ~3.5 hours

- Add battery level simulation with slider (0-100%)
- Add storage space simulation with slider (1GB - Max)
- Implement SimulateBatteryAlert and SimulateStorageAlert events
- Create test RemoteAlert objects with simulated values
- Send notifications to all configured channels
- Display success/failure feedback via Snackbar
- Show loading state during notification sending
- Add DeviceSimulationCard component with sliders and buttons
- Test alerts use negative IDs (-1L) to distinguish from real alerts

Implements: #410
@hossain-khan hossain-khan merged commit 9212c10 into main Dec 11, 2025
4 of 5 checks passed
@hossain-khan hossain-khan deleted the feature/dev-portal-phase2-device-simulation branch December 11, 2025 11:39
@github-actions
Copy link

Code Coverage Report

View Coverage Report

@github-actions
Copy link

📊 APK Size Analysis

Comparing mainfeature/dev-portal-phase2-device-simulation (this PR)

⚠️ Diffuse analysis failed. Check the workflow logs for details.


Generated by Diffuse via diffuse-action

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