incyclist-services 1.0.33 → 1.0.35

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;
@@ -97,11 +97,41 @@ class DeviceConfigurationService extends events_1.default {
97
97
  if (info && info.devices.length > 0 && info.selected === undefined)
98
98
  this.select(info.devices[0], capability);
99
99
  }
100
+ this.verifyCapabilitySettings();
100
101
  this.removeLegacySettings();
101
102
  this.logEvent({ message: 'DeviceConfig.init done' });
102
103
  this.emitInitialized();
103
104
  });
104
105
  }
106
+ verifyCapabilitySettings() {
107
+ const { capabilities } = this.settings;
108
+ const bikeCap = capabilities.find(c => c.capability === 'bike');
109
+ if (bikeCap && bikeCap.selected) {
110
+ const bike = bikeCap.selected;
111
+ const power = capabilities.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Power && c.selected !== undefined);
112
+ const control = capabilities.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Control && c.selected !== undefined);
113
+ const speed = capabilities.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Speed && c.selected !== undefined);
114
+ const cadence = capabilities.find(c => c.capability === incyclist_devices_1.IncyclistCapability.Cadence && c.selected !== undefined);
115
+ const adapter = this.getAdapter(bike);
116
+ const verify = (uuid, cap) => {
117
+ if (!uuid && adapter.hasCapability(cap)) {
118
+ const setting = capabilities.find(c => c.capability === cap);
119
+ if (!setting) {
120
+ capabilities.push({ capability: cap, devices: [bike], selected: bike, disabled: false });
121
+ }
122
+ else {
123
+ setting.selected = bike;
124
+ if (!setting.devices.includes(bike))
125
+ setting.devices.push(bike);
126
+ }
127
+ }
128
+ };
129
+ verify(control, incyclist_devices_1.IncyclistCapability.Control);
130
+ verify(power, incyclist_devices_1.IncyclistCapability.Power);
131
+ verify(speed, incyclist_devices_1.IncyclistCapability.Speed);
132
+ verify(cadence, incyclist_devices_1.IncyclistCapability.Cadence);
133
+ }
134
+ }
105
135
  initCapabilties() {
106
136
  if (!this.settings)
107
137
  this.settings = {};
@@ -681,7 +711,7 @@ class DeviceConfigurationService extends events_1.default {
681
711
  if (capability) {
682
712
  capabilites = (_b = this.settings) === null || _b === void 0 ? void 0 : _b.capabilities.filter(c => c.capability === capability);
683
713
  }
684
- return capabilites.filter(c => c.capability !== 'bike' && !(c.disabled === true)).map(c => {
714
+ return capabilites.filter(c => c.capability !== 'bike' && !(c.disabled === true) && c.selected).map(c => {
685
715
  const { capability, selected } = c;
686
716
  return { capability: capability, selected };
687
717
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-services",
3
- "version": "1.0.33",
3
+ "version": "1.0.35",
4
4
  "peerDependencies": {
5
5
  "gd-eventlog": "^0.1.24"
6
6
  },