incyclist-services 1.0.34 → 1.0.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,6 +22,7 @@ export declare class DeviceConfigurationService extends EventEmitter {
22
22
  protected logEvent(e: any): void;
23
23
  protected logError(err: Error, fn: string): void;
24
24
  init(): Promise<void>;
25
+ protected verifyCapabilitySettings(): void;
25
26
  protected initCapabilties(): void;
26
27
  protected initInterfaces(): void;
27
28
  isInitialized(): boolean;
@@ -61,6 +61,7 @@ class DeviceConfigurationService extends events_1.default {
61
61
  catch (err) {
62
62
  this.logError(err, 'init()');
63
63
  }
64
+ this.verifyCapabilitySettings();
64
65
  this.emitInitialized();
65
66
  return;
66
67
  }
@@ -97,11 +98,48 @@ class DeviceConfigurationService extends events_1.default {
97
98
  if (info && info.devices.length > 0 && info.selected === undefined)
98
99
  this.select(info.devices[0], capability);
99
100
  }
101
+ this.verifyCapabilitySettings();
100
102
  this.removeLegacySettings();
101
103
  this.logEvent({ message: 'DeviceConfig.init done' });
102
104
  this.emitInitialized();
103
105
  });
104
106
  }
107
+ verifyCapabilitySettings() {
108
+ const { capabilities } = this.settings;
109
+ const bikeCap = capabilities.find(c => c.capability === 'bike');
110
+ if (bikeCap && bikeCap.selected) {
111
+ const bike = bikeCap.selected;
112
+ const power = capabilities.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Power && c.selected !== undefined);
113
+ const control = capabilities.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Control && c.selected !== undefined);
114
+ const speed = capabilities.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Speed && c.selected !== undefined);
115
+ const cadence = capabilities.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Cadence && c.selected !== undefined);
116
+ const adapter = this.getAdapter(bike);
117
+ let changed = false;
118
+ const verify = (uuid, cap) => {
119
+ if (!uuid && adapter.hasCapability(cap)) {
120
+ const setting = capabilities.find(c => c.capability === cap);
121
+ if (!setting) {
122
+ capabilities.push({ capability: cap, devices: [bike], selected: bike, disabled: false });
123
+ changed = true;
124
+ }
125
+ else {
126
+ setting.selected = bike;
127
+ if (!setting.devices.includes(bike))
128
+ setting.devices.push(bike);
129
+ changed = true;
130
+ }
131
+ }
132
+ };
133
+ verify(control, incyclist_devices_1.IncyclistCapability.Control);
134
+ verify(power, incyclist_devices_1.IncyclistCapability.Power);
135
+ verify(speed, incyclist_devices_1.IncyclistCapability.Speed);
136
+ verify(cadence, incyclist_devices_1.IncyclistCapability.Cadence);
137
+ if (changed) {
138
+ this.updateUserSettings();
139
+ this.logEvent({ message: 'capability changed after verification', capabilities });
140
+ }
141
+ }
142
+ }
105
143
  initCapabilties() {
106
144
  if (!this.settings)
107
145
  this.settings = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.0.34",
3
+ "version": "1.0.36",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.24"
6
6
  },