Skip to content

Commit

Permalink
properly check for idle gear
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Jun 28, 2024
1 parent 9f0ef41 commit 45fc2ff
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions lib/Backend/device_registry.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,24 @@ BuiltSet<BaseStatefulDevice> getByAction(GetByActionRef ref, BaseAction baseActi
}

@Riverpod(keepAlive: true)
BuiltList<BaseStatefulDevice> getAvailableIdleGear(GetAvailableIdleGearRef ref) {
final BuiltList<BaseStatefulDevice> watch = ref.watch(getAvailableGearProvider);
return watch.where((element) => element.deviceState.value == DeviceState.standby).toBuiltList();
class GetAvailableIdleGear extends _$GetAvailableIdleGear {
@override
BuiltList<BaseStatefulDevice> build() {
for (BaseStatefulDevice baseStatefulDevice in ref.watch(knownDevicesProvider).values) {
baseStatefulDevice.deviceState
..removeListener(_listener)
..addListener(_listener);
}
return getState();
}

BuiltList<BaseStatefulDevice> getState() {
return ref.read(getAvailableGearProvider).where((element) => element.deviceState.value == DeviceState.standby).toBuiltList();
}

void _listener() {
state = getState();
}
}

@Riverpod(keepAlive: true)
Expand Down

0 comments on commit 45fc2ff

Please sign in to comment.