incyclist-devices 1.5.12 → 1.5.13

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.
@@ -45,6 +45,7 @@ export default class DaumAdapterBase extends IncyclistDevice implements DeviceAd
45
45
  isStopped(): boolean;
46
46
  initData(): void;
47
47
  start(props?: any): Promise<any>;
48
+ stopUpdatePull(): void;
48
49
  startUpdatePull(): void;
49
50
  connect(): void;
50
51
  close(): any;
@@ -165,6 +165,15 @@ class DaumAdapterBase extends device_1.default {
165
165
  start(props) {
166
166
  throw new Error('Method not implemented.');
167
167
  }
168
+ stopUpdatePull() {
169
+ if (!this.iv)
170
+ return;
171
+ if (this.iv.sync)
172
+ clearInterval(this.iv.sync);
173
+ if (this.iv.update)
174
+ clearInterval(this.iv.update);
175
+ this.iv = undefined;
176
+ }
168
177
  startUpdatePull() {
169
178
  if (this.iv)
170
179
  return;
@@ -18,5 +18,10 @@ export default class DaumClassicAdapter extends DaumAdapter {
18
18
  relaunch(props: any): Promise<unknown>;
19
19
  start(props: any): Promise<unknown>;
20
20
  launch(props: any, isRelaunch?: boolean): Promise<unknown>;
21
+ startRide(props?: {
22
+ user?: any;
23
+ bikeSettings?: any;
24
+ gear?: any;
25
+ }): Promise<unknown>;
21
26
  getCurrentBikeData(): any;
22
27
  }
@@ -114,59 +114,10 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
114
114
  }
115
115
  launch(props, isRelaunch = false) {
116
116
  return __awaiter(this, void 0, void 0, function* () {
117
- const opts = props || {};
118
- const { user, bikeSettings } = opts;
119
- if (user && user.weight)
120
- this.userSettings.weight = user.weight;
121
- if (bikeSettings && bikeSettings.weight)
122
- this.bikeSettings.weight = bikeSettings.weight;
123
- this.initData();
124
117
  if (isRelaunch) {
125
118
  yield this.stop();
126
119
  }
127
- let startState = {};
128
- return (0, utils_1.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
129
- try {
130
- if (!this.bike.isConnected())
131
- yield this.bike.saveConnect();
132
- yield this.getBike().resetDevice();
133
- if (!startState.setProg) {
134
- yield this.getBike().setProg(0);
135
- startState.setProg = true;
136
- }
137
- if (!startState.setPerson) {
138
- yield this.getBike().setPerson(user);
139
- startState.setPerson = true;
140
- }
141
- if (!startState.setBikeType) {
142
- const bikeType = this.getCyclingMode().getSetting('bikeType') || 'race';
143
- yield this.getBike().setBikeType(bikeType.toLowerCase());
144
- startState.setBikeType = true;
145
- }
146
- if (!startState.startProg) {
147
- yield this.getBike().startProg();
148
- startState.startProg = true;
149
- }
150
- if (!startState.setGear) {
151
- yield this.bike.setGear(this.cyclingData.gear || (opts.gear || 10));
152
- startState.setGear = true;
153
- }
154
- const startRequest = this.getCyclingMode().getBikeInitRequest();
155
- yield this.sendRequest(startRequest);
156
- startState.checkRunData = true;
157
- const data = yield this.bike.runData();
158
- if (startRequest.targetPower && startRequest.targetPower !== 25 && data.power === 25) {
159
- throw new Error('invalid device response: runData');
160
- }
161
- return data;
162
- }
163
- catch (err) {
164
- if (startState.checkRunData) {
165
- startState = {};
166
- }
167
- throw (new Error(`could not start device, reason:${err.message}`));
168
- }
169
- }), 5, 1000)
120
+ return this.startRide(props)
170
121
  .then(data => {
171
122
  this.stopped = false;
172
123
  this.paused = false;
@@ -175,6 +126,61 @@ class DaumClassicAdapter extends DaumAdapter_1.default {
175
126
  });
176
127
  });
177
128
  }
129
+ startRide(props = {}) {
130
+ this.stopUpdatePull();
131
+ const { user, bikeSettings } = props;
132
+ if (user && user.weight)
133
+ this.userSettings.weight = user.weight;
134
+ if (bikeSettings && bikeSettings.weight)
135
+ this.bikeSettings.weight = bikeSettings.weight;
136
+ this.initData();
137
+ let startState = {};
138
+ return (0, utils_1.runWithRetries)(() => __awaiter(this, void 0, void 0, function* () {
139
+ try {
140
+ if (!this.bike.isConnected())
141
+ yield this.bike.saveConnect();
142
+ yield this.getBike().resetDevice();
143
+ if (!startState.setProg) {
144
+ yield this.getBike().setProg(0);
145
+ startState.setProg = true;
146
+ }
147
+ if (!startState.setPerson) {
148
+ yield this.getBike().setPerson(user);
149
+ startState.setPerson = true;
150
+ }
151
+ if (!startState.setBikeType) {
152
+ const bikeType = this.getCyclingMode().getSetting('bikeType') || 'race';
153
+ yield this.getBike().setBikeType(bikeType.toLowerCase());
154
+ startState.setBikeType = true;
155
+ }
156
+ if (!startState.startProg) {
157
+ yield this.getBike().startProg();
158
+ startState.startProg = true;
159
+ }
160
+ if (!startState.setGear) {
161
+ yield this.bike.setGear(this.cyclingData.gear || (props.gear || 10));
162
+ startState.setGear = true;
163
+ }
164
+ const startRequest = this.getCyclingMode().getBikeInitRequest();
165
+ yield this.sendRequest(startRequest);
166
+ startState.checkRunData = true;
167
+ const data = yield this.bike.runData();
168
+ if (startRequest.targetPower && startRequest.targetPower !== 25 && data.power === 25) {
169
+ throw new Error('invalid device response: runData');
170
+ }
171
+ this.stopped = false;
172
+ this.paused = false;
173
+ this.startUpdatePull();
174
+ return data;
175
+ }
176
+ catch (err) {
177
+ if (startState.checkRunData) {
178
+ startState = {};
179
+ }
180
+ throw (new Error(`could not start device, reason:${err.message}`));
181
+ }
182
+ }), 5, 1000);
183
+ }
178
184
  getCurrentBikeData() {
179
185
  return this.getBike().runData();
180
186
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "1.5.12",
3
+ "version": "1.5.13",
4
4
  "dependencies": {
5
5
  "@serialport/parser-byte-length": "^9.0.1",
6
6
  "@serialport/parser-delimiter": "^9.0.1",