Refactor providers - nodes and connectivity - #542
Conversation
- Create ConnectivityService class with testRouterType() and fetchRouterConfiguredData() methods - Move JNAP communication logic from Provider to Service layer - Remove JNAP imports from connectivity_provider.dart (jnap/models, jnap/result, jnap/actions) - Add ServiceError mapping via mapJnapErrorToServiceError() for fetchRouterConfiguredData - Add null safety handling for isDefaultPassword and isSetByUser fields - Add unit tests for ConnectivityService (12 tests) - Add unit tests for ConnectivityNotifier delegation (7 tests) - Add unit tests for ConnectivityState, ConnectivityInfo, AvailabilityInfo (28 tests) - Create test data builder at test/mocks/test_data/connectivity_test_data.dart - Add feature specification documents in specs/001-connectivity-service/
- Create NodeDetailService with LED blink methods (startBlinkNodeLED, stopBlinkNodeLED) - Add transformation helpers (transformDeviceToUIValues, transformConnectedDevices) - Refactor NodeDetailNotifier to delegate JNAP operations to Service - Remove JNAP imports from node_detail_provider.dart and node_detail_state.dart - Add currentStatus getter to NodeLightSettingsNotifier for architecture compliance - Update quick_panel.dart and node_detail_view.dart to use Provider getter instead of Service - Move NodeLightStatus.getStatus() logic from State to Provider layer - Add comprehensive unit tests for Service, Provider, and State - Add specification documents, contracts, and checklists
…fier - Create NodeLightSettingsService for JNAP communication - fetchSettings() with forceRemote parameter - saveSettings() with auto re-fetch after save - Error mapping to ServiceError types - Refactor NodeLightSettingsNotifier to delegate to service - Remove direct JNAP imports (better_action.dart, router_repository.dart) - Keep currentStatus getter in Provider (UI transformation logic) - Add comprehensive test coverage - 16 model tests for NodeLightSettings - 9 service tests for NodeLightSettingsService - 10 provider tests for delegation and currentStatus - Add speckit documentation - spec.md, plan.md, tasks.md - Service contract and data model - Requirements checklist
- Format view files - Format test files for service layer refactoring
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||||||||
- Replace .then()/.onError() pattern with async/await and try/catch - Ensure Future completes only after all async operations finish - Add await to SharedPreferences setString/remove calls - Convert Timer callback to async for proper error handling
User description
Create NodeLightSettingsService for JNAP communication
- fetchSettings() with forceRemote parameter
- saveSettings() with auto re-fetch after save
- Error mapping to ServiceError types
Create NodeDetailService with LED blink methods (startBlinkNodeLED, stopBlinkNodeLED)
Create ConnectivityService class with testRouterType() and fetchRouterConfiguredData() methods
PR Type
Enhancement, Tests, Documentation
Description
Create three new service classes for JNAP communication delegation:
NodeLightSettingsService: LED night mode settings fetch/save with auto re-fetchNodeDetailService: Node LED blinking and device transformation helpersConnectivityService: Router type detection and configuration status checkingRefactor three provider notifiers to delegate JNAP operations to service layer:
NodeLightSettingsNotifier: Remove JNAP imports, addcurrentStatusgetterNodeDetailNotifier: Delegate device transformation and LED blinking to serviceConnectivityNotifier: Delegate router type and configuration checks to serviceUpdate UI components to use provider
currentStatusgetter instead of static methods:quick_panel.dartandnode_detail_view.dartnow read from provider notifierAdd comprehensive test coverage across all layers:
NodeLightSettingsServiceNodeDetailServiceConnectivityServiceNodeLightSettingsNotifierNodeDetailNotifierConnectivityNotifierNodeLightSettingsNodeDetailStateCreate test data builders for service mocking and test scenarios
Document specifications with contracts, task breakdowns, quickstart guides, and implementation plans for all three services
Diagram Walkthrough
File Walkthrough
5 files
node_light_settings_service.dart
New NodeLightSettingsService for LED settings JNAP communicationlib/core/jnap/services/node_light_settings_service.dart
operations
fetchSettings()with optionalforceRemoteparameter forcache control
saveSettings()that persists settings and auto re-fetchesfrom device
ServiceErrortypes (UnauthorizedError,UnexpectedError)node_detail_service.dart
New NodeDetailService with LED blink and device transformation methodslib/page/nodes/services/node_detail_service.dart
blinking
startBlinkNodeLED()andstopBlinkNodeLED()methods witherror mapping
transformDeviceToUIValues()helper to convert JNAP devicedata to UI primitives
transformConnectedDevices()helper andgetNodeLightStatus()transformation method
connectivity_service.dart
New ConnectivityService for router type and configuration detectionlib/providers/connectivity/services/connectivity_service.dart
testRouterType()to detect router connection type viaserial number comparison
fetchRouterConfiguredData()to check router passwordconfiguration status
ServiceErrortypes with graceful error handlingquick_panel.dart
Update quick_panel to use provider currentStatus getterlib/page/dashboard/views/components/quick_panel.dart
nodeLightSettingsProvider.notifier.currentStatusgetterinstead of
NodeLightStatus.getStatus()node_detail_view.dart
Update node_detail_view to use provider currentStatus getterlib/page/nodes/views/node_detail_view.dart
nodeLightSettingsProvider.notifier.currentStatusgetterinstead of
NodeLightStatus.getStatus()nodeLightSettingsProviderstate3 files
node_light_settings_provider.dart
Refactor NodeLightSettingsNotifier to delegate to service layerlib/core/jnap/providers/node_light_settings_provider.dart
NodeLightSettingsNotifierto delegate JNAP operations toNodeLightSettingsServiceJNAPAction,routerRepositoryProvider)currentStatusgetter to provide UI-friendlyNodeLightStatusenumderived from settings
fetch()andsave()methods to call service layernode_detail_provider.dart
Refactor NodeDetailNotifier to delegate to NodeDetailServicelib/page/nodes/providers/node_detail_provider.dart
NodeDetailNotifier.createState()to delegate devicetransformation to
NodeDetailServicetoggleBlinkNode()to use service methods with improved errorhandling for
ServiceErrortransformDeviceToUIValues()andtransformConnectedDevices()connectivity_provider.dart
Refactor ConnectivityNotifier to delegate to ConnectivityServicelib/providers/connectivity/connectivity_provider.dart
ConnectivityNotifier._testRouterType()to delegate toConnectivityServiceisRouterConfigured()to delegate toConnectivityService.fetchRouterConfiguredData()12 files
node_light_settings_service_test.dart
Add comprehensive tests for NodeLightSettingsServicetest/core/jnap/services/node_light_settings_service_test.dart
NodeLightSettingsServicefetchSettings()with default and forced remote fetchsaveSettings()with null field exclusion and auto re-fetchUnauthorizedErrorandUnexpectedErrornode_detail_service_test.dart
Add comprehensive tests for NodeDetailServicetest/page/nodes/services/node_detail_service_test.dart
NodeDetailServicestartBlinkNodeLED()andstopBlinkNodeLED()JNAPcommunication
UnauthorizedErrorandUnexpectedErrorconnectivity_service_test.dart
Add comprehensive tests for ConnectivityServicetest/providers/connectivity/connectivity_service_test.dart
ConnectivityServicetestRouterType()with serial number matching scenariosfetchRouterConfiguredData()with various password statesserial number)
node_detail_provider_test.dart
Add comprehensive tests for NodeDetailNotifiertest/page/nodes/providers/node_detail_provider_test.dart
NodeDetailNotifiercreateState()delegation to service transformation methodstoggleBlinkNode()with start/stop scenarios and errorhandling
node_light_settings_provider_test.dart
Add comprehensive tests for NodeLightSettingsNotifiertest/core/jnap/providers/node_light_settings_provider_test.dart
NodeLightSettingsNotifierfetch()andsave()to servicecurrentStatusgetter with all status scenarios (on, off,night)
connectivity_provider_test.dart
Add comprehensive tests for ConnectivityNotifiertest/providers/connectivity/connectivity_provider_test.dart
ConnectivityNotifierisRouterConfigured()to servicenode_light_settings_test.dart
Add comprehensive tests for NodeLightSettings modeltest/core/jnap/models/node_light_settings_test.dart
NodeLightSettingsmodelfromMap()andtoMap()serialization with null fieldhandling
on(),off(),night()) andfromStatus()copyWith(), equality, and JSON roundtrip serializationnode_detail_state_test.dart
Add comprehensive tests for NodeDetailStatetest/page/nodes/providers/node_detail_state_test.dart
NodeDetailStatecopyWith()with partial and full updatesBlinkingStatusenumconnectivity_state_test.dart
Add comprehensive tests for connectivity state modelstest/providers/connectivity/connectivity_state_test.dart
ConnectivityState,ConnectivityInfo,AvailabilityInfo, andRouterTypecopyWith(), equality, and default values for all modelsnode_light_settings_test_data.dart
Add test data builder for NodeLightSettingsServicetest/mocks/test_data/node_light_settings_test_data.dart
NodeLightSettingsServicetestssave)
errors
node_detail_test_data.dart
Add test data builder for NodeDetailServicetest/mocks/test_data/node_detail_test_data.dart
NodeDetailServicetestsstop)
errors
connectivity_test_data.dart
Add test data builder for ConnectivityServicetest/mocks/test_data/connectivity_test_data.dart
ConnectivityServicetestsgetDeviceInfoandfetchIsConfiguredJNAPresponses
test scenarios
25 files
node_light_settings_service_contract.md
Add service contract specification for NodeLightSettingsServicespecs/002-node-light-settings-service/contracts/node_light_settings_service_contract.md
NodeLightSettingsServicescenarios
tasks.md
ConnectivityService extraction tasks and execution planspecs/001-connectivity-service/tasks.md
extraction with 31 tasks organized into 6 phases
efficient implementation
with MVP-first approach
User Stories 1-3
tasks.md
NodeLightSettings service extraction implementation tasksspecs/002-node-light-settings-service/tasks.md
NodeLightSettingsService extraction
implementation
compliance checks
dependencies
tasks.md
NodeDetail service extraction comprehensive task breakdownspecs/001-node-detail-service/tasks.md
extraction
can run in parallel)
compliance verification
mapping
node_detail_service_contract.md
NodeDetailService API contract and method specificationsspecs/001-node-detail-service/contracts/node_detail_service_contract.md
NodeDetailServicewith providerdefinition and class structure
startBlinkNodeLED,stopBlinkNodeLED,transformDeviceToUIValues,transformConnectedDevicesmapJnapErrorToServiceError()for JNAP error mapping
layer
spec.md
NodeDetail service feature specification and requirementsspecs/001-node-detail-service/spec.md
priorities)
delegation, and error handling
compliance and test coverage targets
quickstart.md
ConnectivityService extraction quickstart implementation guidespecs/001-connectivity-service/quickstart.md
extraction in 6 steps
and provider refactoring
quickstart.md
NodeDetail service extraction quickstart guidespecs/001-node-detail-service/quickstart.md
implementation, and transformation helpers
creation patterns
research.md
NodeDetail service extraction research and technical decisionsspecs/001-node-detail-service/research.md
following
RouterPasswordServicereferencemapJnapErrorToServiceError()functionand provider creating state
remove/add
spec.md
ConnectivityService feature specification and requirementsspecs/001-connectivity-service/spec.md
three user stories (all P1)
delegation, and error mapping
compliance and test coverage
detection
spec.md
NodeLightSettings service feature specificationspecs/002-node-light-settings-service/spec.md
priorities)
settings fetch/save, and error handling
and test coverage targets
service-contract.md
Service contract quality assurance checklistspecs/001-node-detail-service/checklists/service-contract.md
handling, statelessness, dependency injection, transformation helpers,
API consistency, boundary conditions, contract-spec alignment, and
testability
requirements
data-model.md
NodeDetail service data model classification and mappingspecs/001-node-detail-service/data-model.md
Application Layer (Service/Provider), Error Layer
RawDevicetoNodeDetailStatewithtransformation logic
NodeLightSettingsimport fromstate file
to Provider state
data-model.md
ConnectivityService data model and entity definitionsspecs/001-connectivity-service/data-model.md
RouterTypeenum,RouterConfiguredDataclass,ConnectivityServiceclass, and provider definitionflow diagram
data models
plan.md
NodeDetail service implementation plan and constitution compliancespecs/001-node-detail-service/plan.md
compliance checks
organization
all articles verified
connectivity_service_contract.md
ConnectivityService API contract and method specificationsspecs/001-connectivity-service/contracts/connectivity_service_contract.md
ConnectivityServicewith providerdefinition
testRouterType()andfetchRouterConfiguredData()with detailed signaturestestRouterType,throws
ServiceErrorforfetchRouterConfiguredData)comprehensive testing contract
research.md
ConnectivityService extraction research and technical decisionsspecs/001-connectivity-service/research.md
existing implementations
mapJnapErrorToServiceError()functionRouterConfiguredDatalocation decision and SharedPreferencesdependency handling
_testRouterType()andisRouterConfigured()extractiondata-model.md
NodeLightSettings service data model and entity definitionsspecs/002-node-light-settings-service/data-model.md
NodeLightSettings,NodeLightStatusenumNodeLightSettingsServiceentity with stateless design andtwo core methods
RouterRepository
requirements.md
NodeLightSettings specification quality validation checklistspecs/002-node-light-settings-service/checklists/requirements.md
markers remain
technology-agnostic
quickstart.md
NodeLightSettings Service Extraction Quickstart Guidespecs/002-node-light-settings-service/quickstart.md
NodeLightSettingsServicefrom the notifierand test structure
tests pass
compliance
plan.md
NodeLightSettings Service Extraction Implementation Planspecs/002-node-light-settings-service/plan.md
context and dependencies
organization
compliance
plan.md
ConnectivityService Extraction Implementation Planspecs/001-connectivity-service/plan.md
ConnectivityServiceextractionfrom provider
framework
architecture compliance
lib/providers/connectivity/services/research.md
NodeLightSettings Service Extraction Phase 0 Researchspecs/002-node-light-settings-service/research.md
DeviceManagerServicepattern as referenceimplementation
NodeLightSettingsNotifierJNAP actions and methodsNodeLightSettings,NodeLightStatus) and errormapping patterns
requirements.md
NodeDetail Service Specification Quality Checklistspecs/001-node-detail-service/checklists/requirements.md
feature
remain
technology-agnostic
passing
requirements.md
ConnectivityService Specification Quality Checklistspecs/001-connectivity-service/checklists/requirements.md
ConnectivityService extraction
specification
passed
1 files