@@ -32,6 +32,7 @@ import 'logging_wrappers.dart';
3232import 'move_lists.dart' ;
3333
3434part 'sensors.freezed.dart' ;
35+
3536part 'sensors.g.dart' ;
3637
3738final sensorsLogger = log.Logger ('Sensors' );
@@ -201,16 +202,24 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable<Tr
201202 }
202203
203204 Future <void > sendCommands (String name, Ref ref) async {
204- if (ref.read (getAvailableGearProvider).isEmpty) {
205+ if (ref
206+ .read (getAvailableGearProvider)
207+ .isEmpty) {
205208 return ;
206209 }
207- actions.values.flattened.where ((e) => actionTypes.firstWhere ((element) => element.name == name).uuid == e.uuid).forEach (
208- (TriggerAction triggerAction) async {
210+ actions.values.flattened.where ((e) =>
211+ actionTypes
212+ .firstWhere ((element) => element.name == name)
213+ .uuid == e.uuid).forEach (
214+ (TriggerAction triggerAction) async {
209215 if (triggerAction.isActive.value || triggerAction.actions.isEmpty) {
210216 // 15 second cool-down between moves
211217 return ;
212218 }
213- final List <BaseAction > allActionsMapped = triggerAction.actions.map ((element) => ref.read (getActionFromUUIDProvider (element))).nonNulls.toList ();
219+ final List <BaseAction > allActionsMapped = triggerAction.actions
220+ .map ((element) => ref.read (getActionFromUUIDProvider (element)))
221+ .nonNulls
222+ .toList ();
214223
215224 // no moves exist
216225 if (allActionsMapped.isEmpty) {
@@ -222,20 +231,20 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable<Tr
222231 .read (getAvailableIdleGearForTypeProvider ([DeviceType .ears].toBuiltSet ()))
223232 .where (
224233 (p0) => p0.isTailCoNTROL.value == TailControlStatus .legacy,
225- )
234+ )
226235 .isNotEmpty;
227236 bool hasGlowtipGear = ref
228237 .read (getAvailableIdleGearProvider)
229238 .where (
230239 (p0) => p0.hasGlowtip.value == GlowtipStatus .glowtip,
231- )
240+ )
232241 .isNotEmpty;
233242 final List <BaseAction > moveActions = allActionsMapped
234243 .where ((element) => ! const [ActionCategory .glowtip, ActionCategory .audio].contains (element.actionCategory))
235244 .whereNot (
236- // filter out legacy moves if legacy ears are not connected
245+ // filter out legacy moves if legacy ears are not connected
237246 (element) => (element is EarsMoveList && ! hasLegacyEars),
238- )
247+ )
239248 .toList ();
240249
241250 final List <BaseAction > glowActions = hasGlowtipGear ? allActionsMapped.where ((element) => const [ActionCategory .glowtip].contains (element.actionCategory)).toList () : [];
@@ -266,7 +275,7 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable<Tr
266275 // The goal here is if a user selects multiple moves, send a move to all gear
267276 final Set <DeviceType > baseActionDeviceCategories = baseAction.deviceCategory.where (
268277 // filtering out the first actions ears entry if its a unified move but legacy gear is connected
269- (element) {
278+ (element) {
270279 if (element == DeviceType .ears) {
271280 if (baseAction is CommandAction ) {
272281 return hasLegacyEars;
@@ -278,7 +287,7 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable<Tr
278287 final Set <DeviceType > missingGearAction = flattenedDeviceTypes.difference (baseActionDeviceCategories);
279288 final List <BaseAction > remainingActions = moveActions.where (
280289 // Check if any actions contain the device type of the gear the first action is missing
281- (element) {
290+ (element) {
282291 // filters out remaining CommandActions if legacy ears are connected. Assumes Custom Actions send to ears too
283292 if (baseAction is CommandAction && hasLegacyEars) {
284293 if (element is EarsMoveList ) {
@@ -287,7 +296,10 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable<Tr
287296 return false ;
288297 }
289298 }
290- return element.deviceCategory.toSet ().intersection (missingGearAction).isNotEmpty;
299+ return element.deviceCategory
300+ .toSet ()
301+ .intersection (missingGearAction)
302+ .isNotEmpty;
291303 },
292304 ).toList ();
293305 if (remainingActions.isNotEmpty) {
@@ -303,11 +315,11 @@ abstract class TriggerDefinition extends ChangeNotifier implements Comparable<Tr
303315 for (BaseStatefulDevice baseStatefulDevice in ref
304316 .read (getAvailableIdleGearForTypeProvider (baseAction.deviceCategory.toBuiltSet ()))
305317 .where (
306- // support sending to next device type if 2 actions+ actions are set
318+ // support sending to next device type if 2 actions+ actions are set
307319 (element) => ! sentDeviceTypes.contains (element.baseDeviceDefinition.deviceType),
308- )
320+ )
309321 .where (
310- (element) {
322+ (element) {
311323 // filter out devices without a glowtip if its a glowtip action
312324 if ([ActionCategory .glowtip].contains (baseAction.actionCategory)) {
313325 return element.hasGlowtip.value == GlowtipStatus .glowtip;
@@ -389,7 +401,7 @@ class WalkingTriggerDefinition extends TriggerDefinition {
389401 return ;
390402 }
391403 pedestrianStatusStream = Pedometer .pedestrianStatusStream.listen (
392- (PedestrianStatus event) {
404+ (PedestrianStatus event) {
393405 sensorsLogger.info ("PedestrianStatus:: ${event .status }" );
394406 if (event.status == "walking" ) {
395407 sendCommands ("Walking" , ref);
@@ -399,7 +411,7 @@ class WalkingTriggerDefinition extends TriggerDefinition {
399411 },
400412 );
401413 stepCountStream = Pedometer .stepCountStream.listen (
402- (StepCount event) {
414+ (StepCount event) {
403415 sensorsLogger.fine ("StepCount:: ${event .steps }" );
404416 sendCommands ("Step" , ref);
405417 },
@@ -464,7 +476,9 @@ class EarMicTriggerDefinition extends TriggerDefinition {
464476
465477 @override
466478 Future <bool > isSupported () {
467- return Future .value (ref.read (getKnownGearForTypeProvider (BuiltSet ([DeviceType .ears]))).isNotEmpty);
479+ return Future .value (ref
480+ .read (getKnownGearForTypeProvider (BuiltSet ([DeviceType .ears])))
481+ .isNotEmpty);
468482 }
469483
470484 @override
@@ -478,7 +492,12 @@ class EarMicTriggerDefinition extends TriggerDefinition {
478492 }
479493 rxSubscriptions = [];
480494 ref.read (getAvailableGearForTypeProvider (BuiltSet ([DeviceType .ears]))).forEach ((element) {
481- element.commandQueue.addCommand (BluetoothMessage (message: "ENDLISTEN" , device: element, priority: Priority .low, responseMSG: "LISTEN OFF" , type: CommandType .system, timestamp: DateTime .now ()));
495+ element.commandQueue.addCommand (BluetoothMessage (message: "ENDLISTEN" ,
496+ device: element,
497+ priority: Priority .low,
498+ responseMSG: "LISTEN OFF" ,
499+ type: CommandType .system,
500+ timestamp: DateTime .now ()));
482501 });
483502 }
484503
@@ -488,7 +507,11 @@ class EarMicTriggerDefinition extends TriggerDefinition {
488507 return ;
489508 }
490509 ref.read (getAvailableGearForTypeProvider (BuiltSet ([DeviceType .ears]))).forEach ((element) {
491- element.commandQueue.addCommand (BluetoothMessage (message: "LISTEN FULL" , device: element, priority: Priority .low, type: CommandType .system, timestamp: DateTime .now ()));
510+ element.commandQueue.addCommand (BluetoothMessage (message: "LISTEN FULL" ,
511+ device: element,
512+ priority: Priority .low,
513+ type: CommandType .system,
514+ timestamp: DateTime .now ()));
492515 });
493516 //add listeners on new device paired
494517 deviceRefSubscription = ref.listen (knownDevicesProvider, (previous, next) {
@@ -513,10 +536,14 @@ class EarMicTriggerDefinition extends TriggerDefinition {
513536 }
514537 //Store the current streams to keep them open
515538 rxSubscriptions = ref.read (getAvailableGearForTypeProvider (BuiltSet ([DeviceType .ears]))).map (
516- (element) {
517- element.commandQueue.addCommand (BluetoothMessage (message: "LISTEN FULL" , device: element, priority: Priority .low, type: CommandType .system, timestamp: DateTime .now ()));
539+ (element) {
540+ element.commandQueue.addCommand (BluetoothMessage (message: "LISTEN FULL" ,
541+ device: element,
542+ priority: Priority .low,
543+ type: CommandType .system,
544+ timestamp: DateTime .now ()));
518545 return element.rxCharacteristicStream.listen (
519- (msg) {
546+ (msg) {
520547 if (msg.contains ("LISTEN_FULL BANG" )) {
521548 // we don't store the actions in class as multiple Triggers can exist, so go get them. This is only necessary when the action is dependent on gear being available
522549 sendCommands ("Sound" , ref);
@@ -548,7 +575,9 @@ class EarTiltTriggerDefinition extends TriggerDefinition {
548575
549576 @override
550577 Future <bool > isSupported () {
551- return Future .value (ref.read (getKnownGearForTypeProvider (BuiltSet ([DeviceType .ears]))).isNotEmpty);
578+ return Future .value (ref
579+ .read (getKnownGearForTypeProvider (BuiltSet ([DeviceType .ears])))
580+ .isNotEmpty);
552581 }
553582
554583 @override
@@ -562,7 +591,11 @@ class EarTiltTriggerDefinition extends TriggerDefinition {
562591 }
563592 rxSubscriptions = [];
564593 ref.read (getAvailableGearForTypeProvider (BuiltSet ([DeviceType .ears]))).forEach ((element) {
565- element.commandQueue.addCommand (BluetoothMessage (message: "ENDTILTMODE" , device: element, priority: Priority .low, type: CommandType .system, timestamp: DateTime .now ()));
594+ element.commandQueue.addCommand (BluetoothMessage (message: "ENDTILTMODE" ,
595+ device: element,
596+ priority: Priority .low,
597+ type: CommandType .system,
598+ timestamp: DateTime .now ()));
566599 });
567600 }
568601
@@ -572,7 +605,11 @@ class EarTiltTriggerDefinition extends TriggerDefinition {
572605 return ;
573606 }
574607 ref.read (getAvailableGearForTypeProvider (BuiltSet ([DeviceType .ears]))).forEach ((element) {
575- element.commandQueue.addCommand (BluetoothMessage (message: "TILTMODE START" , device: element, priority: Priority .low, type: CommandType .system, timestamp: DateTime .now ()));
608+ element.commandQueue.addCommand (BluetoothMessage (message: "TILTMODE START" ,
609+ device: element,
610+ priority: Priority .low,
611+ type: CommandType .system,
612+ timestamp: DateTime .now ()));
576613 });
577614 //add listeners on new device paired
578615 deviceRefSubscription = ref.listen (knownDevicesProvider, (previous, next) {
@@ -597,10 +634,14 @@ class EarTiltTriggerDefinition extends TriggerDefinition {
597634 }
598635 //Store the current streams to keep them open
599636 rxSubscriptions = ref.read (getAvailableGearForTypeProvider (BuiltSet ([DeviceType .ears]))).map (
600- (element) {
601- element.commandQueue.addCommand (BluetoothMessage (message: "TILTMODE START" , device: element, priority: Priority .low, type: CommandType .system, timestamp: DateTime .now ()));
637+ (element) {
638+ element.commandQueue.addCommand (BluetoothMessage (message: "TILTMODE START" ,
639+ device: element,
640+ priority: Priority .low,
641+ type: CommandType .system,
642+ timestamp: DateTime .now ()));
602643 return element.rxCharacteristicStream.listen (
603- (msg) {
644+ (msg) {
604645 if (msg.contains ("TILT LEFT" )) {
605646 // we don't store the actions in class as multiple Triggers can exist, so go get them. This is only necessary when the action is dependent on gear being available
606647 sendCommands ("Left" , ref);
@@ -740,7 +781,10 @@ class TailProximityTriggerDefinition extends TriggerDefinition {
740781
741782 @override
742783 Future <void > onDisable () async {
743- if (ref.read (triggerListProvider).where ((element) => element.triggerDefinition == this && element.enabled).isEmpty) {
784+ if (ref
785+ .read (triggerListProvider)
786+ .where ((element) => element.triggerDefinition == this && element.enabled)
787+ .isEmpty) {
744788 btConnectStream? .cancel ();
745789 btConnectStream = null ;
746790 }
@@ -752,8 +796,14 @@ class TailProximityTriggerDefinition extends TriggerDefinition {
752796 return ;
753797 }
754798 btConnectStream = flutterBluePlus.onScanResults.listen (
755- (event) {
756- if (event.where ((element) => ! ref.read (knownDevicesProvider).keys.contains (element.device.remoteId.str)).isNotEmpty && btnearbyCooldown != null && btnearbyCooldown! .isActive) {
799+ (event) {
800+ if (event
801+ .where ((element) =>
802+ ! ref
803+ .read (knownDevicesProvider)
804+ .keys
805+ .contains (element.device.remoteId.str))
806+ .isNotEmpty && btnearbyCooldown != null && btnearbyCooldown! .isActive) {
757807 sendCommands ("Nearby Gear" , ref);
758808
759809 btnearbyCooldown = Timer (const Duration (seconds: 30 ), () {});
@@ -787,12 +837,12 @@ class TriggerAction {
787837
788838 TriggerAction (this .uuid) {
789839 isActive.addListener (
790- () {
840+ () {
791841 if (isActive.value) {
792842 isActiveProgress.value = 0.01 ;
793843 _timer = Timer (
794844 Duration (seconds: HiveProxy .getOrDefault (settings, triggerActionCooldown, defaultValue: triggerActionCooldownDefault)),
795- () {
845+ () {
796846 isActive.value = false ;
797847 _periodicTimer? .cancel ();
798848 _timer? .cancel ();
@@ -803,7 +853,7 @@ class TriggerAction {
803853 );
804854 _periodicTimer = Timer .periodic (
805855 const Duration (milliseconds: 500 ),
806- (Timer timer) {
856+ (Timer timer) {
807857 timer.tick;
808858 double change = (timer.tick + 1 ) / 30 ;
809859 if (change > 1 ) {
@@ -833,7 +883,7 @@ class TriggerList extends _$TriggerList {
833883 List <Trigger > results = [];
834884 ref.listen (
835885 getAvailableGearProvider,
836- (previous, next) {
886+ (previous, next) {
837887 for (Trigger trigger in state) {
838888 if (trigger.storedEnable) {
839889 trigger.enabled = next.isNotEmpty;
@@ -852,21 +902,47 @@ class TriggerList extends _$TriggerList {
852902 sensorsLogger.severe ("Unable to load stored triggers: $e " , e, s);
853903 }
854904 if (results.isEmpty) {
855- TriggerDefinition triggerDefinition = ref.read (triggerDefinitionListProvider).where ((element) => element.uuid == 'ee9379e2-ec4f-40bb-8674-fd223a6edfda' ).first;
905+ TriggerDefinition triggerDefinition = ref
906+ .read (triggerDefinitionListProvider)
907+ .where ((element) => element.uuid == 'ee9379e2-ec4f-40bb-8674-fd223a6edfda' )
908+ .first;
856909 Trigger trigger = Trigger .trigDef (triggerDefinition, '91e3d421-6a52-45ab-a23e-f38e4987a8f5' );
857- trigger.actions.firstWhere ((element) => element.uuid == '77d22961-5a69-465a-bd27-5cf5508d10a6' ).actions.add (ActionRegistry .allCommands.firstWhere ((element) => element.uuid == 'c53e980e-899e-4148-a13e-f57a8f9707f4' ).uuid);
858- trigger.actions.firstWhere ((element) => element.uuid == '77d22961-5a69-465a-bd27-5cf5508d10a6' ).actions.addAll (
859- ActionRegistry .allCommands
860- .where (
861- (element) => element.actionCategory == ActionCategory .glowtip,
862- )
863- .map (
864- (e) => e.uuid,
865- ),
866- );
867- trigger.actions.firstWhere ((element) => element.uuid == '77d22961-5a69-465a-bd27-5cf5508d10a6' ).actions.add (ActionRegistry .allCommands.firstWhere ((element) => element.uuid == 'fdaff205-0a51-46a0-a5fc-4ea283dce079' ).uuid);
868- trigger.actions.firstWhere ((element) => element.uuid == '7424097d-ba24-4d85-b963-bf58e85e289d' ).actions.add (ActionRegistry .allCommands.firstWhere ((element) => element.uuid == '86b13d13-b09c-46ba-a887-b40d8118b00a' ).uuid);
869- trigger.actions.firstWhere ((element) => element.uuid == '7424097d-ba24-4d85-b963-bf58e85e289d' ).actions.add (ActionRegistry .allCommands.firstWhere ((element) => element.uuid == 'd8384bcf-31ed-4b5d-a25a-da3a2f96e406' ).uuid);
910+ trigger.actions
911+ .firstWhere ((element) => element.uuid == '77d22961-5a69-465a-bd27-5cf5508d10a6' )
912+ .actions
913+ .add (ActionRegistry .allCommands
914+ .firstWhere ((element) => element.uuid == 'c53e980e-899e-4148-a13e-f57a8f9707f4' )
915+ .uuid);
916+ trigger.actions
917+ .firstWhere ((element) => element.uuid == '77d22961-5a69-465a-bd27-5cf5508d10a6' )
918+ .actions
919+ .addAll (
920+ ActionRegistry .allCommands
921+ .where (
922+ (element) => element.actionCategory == ActionCategory .glowtip,
923+ )
924+ .map (
925+ (e) => e.uuid,
926+ ),
927+ );
928+ trigger.actions
929+ .firstWhere ((element) => element.uuid == '77d22961-5a69-465a-bd27-5cf5508d10a6' )
930+ .actions
931+ .add (ActionRegistry .allCommands
932+ .firstWhere ((element) => element.uuid == 'fdaff205-0a51-46a0-a5fc-4ea283dce079' )
933+ .uuid);
934+ trigger.actions
935+ .firstWhere ((element) => element.uuid == '7424097d-ba24-4d85-b963-bf58e85e289d' )
936+ .actions
937+ .add (ActionRegistry .allCommands
938+ .firstWhere ((element) => element.uuid == '86b13d13-b09c-46ba-a887-b40d8118b00a' )
939+ .uuid);
940+ trigger.actions
941+ .firstWhere ((element) => element.uuid == '7424097d-ba24-4d85-b963-bf58e85e289d' )
942+ .actions
943+ .add (ActionRegistry .allCommands
944+ .firstWhere ((element) => element.uuid == 'd8384bcf-31ed-4b5d-a25a-da3a2f96e406' )
945+ .uuid);
870946
871947 unawaited (store ());
872948 return [trigger].build ();
@@ -876,15 +952,15 @@ class TriggerList extends _$TriggerList {
876952
877953 Future <void > add (Trigger trigger) async {
878954 state = state.rebuild (
879- (p0) => p0.add (trigger),
955+ (p0) => p0.add (trigger),
880956 );
881957 await store ();
882958 }
883959
884960 Future <void > remove (Trigger trigger) async {
885961 trigger.enabled = false ;
886962 state = state.rebuild (
887- (p0) => p0.remove (trigger),
963+ (p0) => p0.remove (trigger),
888964 );
889965 await store ();
890966 }
0 commit comments