Skip to content

Commit eb1fe0d

Browse files
committed
Added support for raiseYourHand
1 parent e3905ed commit eb1fe0d

File tree

3 files changed

+47
-4
lines changed

3 files changed

+47
-4
lines changed

src/controllers/DevicesController.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,12 @@ class DevicesController extends Controller {
9494
@allowUpload('file', 1)
9595
async updateDevice(
9696
deviceID: string,
97-
postBody: { app_id?: string, name?: string, file_type?: 'binary' },
97+
postBody: {
98+
app_id?: string,
99+
name?: string,
100+
file_type?: 'binary',
101+
signal: boolean,
102+
},
98103
): Promise<*> {
99104
// 1 rename device
100105
if (postBody.name) {
@@ -117,14 +122,28 @@ class DevicesController extends Controller {
117122
return this.ok({ id: deviceID, status: flashStatus });
118123
}
119124

120-
const file = this.request.files.file[0];
125+
const file =
126+
this.request.files &&
127+
this.request.files.file[0];
128+
121129
if (file && file.originalname.endsWith('.bin')) {
122130
const flashStatus = await this._deviceRepository
123131
.flashBinary(deviceID, file);
124132

125133
return this.ok({ id: deviceID, status: flashStatus });
126134
}
127135

136+
// If signal exists then we want to toggle nyan mode. This just makes the
137+
// LED change colors.
138+
if (!Number.isNaN(postBody.signal)) {
139+
await this._deviceRepository.raiseYourHand(
140+
deviceID,
141+
this.user.id,
142+
!!parseInt(postBody.signal, 10),
143+
);
144+
return this.ok({id: deviceID, ok: true});
145+
}
146+
128147
throw new HttpError('Did not update device');
129148
}
130149

src/repository/DeviceRepository.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,10 @@ class DeviceRepository {
210210
userID: string,
211211
appName: string,
212212
) => {
213-
if (await !this._deviceAttributeRepository.doesUserHaveAccess(deviceID, userID)) {
213+
if (await !this._deviceAttributeRepository.doesUserHaveAccess(
214+
deviceID,
215+
userID,
216+
)) {
214217
throw new HttpError('No device found', 404);
215218
}
216219

@@ -259,6 +262,26 @@ class DeviceRepository {
259262
return await this.getByID(deviceID, userID);
260263
};
261264

265+
raiseYourHand = async (
266+
deviceID: string,
267+
userID: string,
268+
shouldShowSignal: boolean,
269+
): Promise<void> => {
270+
if (await !this._deviceAttributeRepository.doesUserHaveAccess(
271+
deviceID,
272+
userID,
273+
)) {
274+
throw new HttpError('No device found', 404);
275+
}
276+
277+
const device = this._deviceServer.getDevice(deviceID);
278+
if (!device) {
279+
throw new HttpError('Could not get device for ID', 404);
280+
}
281+
282+
return await device.raiseYourHand(shouldShowSignal);
283+
};
284+
262285
renameDevice = async (
263286
deviceID: string,
264287
userID: string,

src/types.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,13 @@ export type DeviceRepository = {
149149
claimDevice(deviceID: string, userID: string): Promise<DeviceAttributes>,
150150
generateClaimCode(userID: string): Promise<string>,
151151
flashBinary(deviceID: string, files: File): Promise<*>,
152-
flashKnownApp(deviceID: string, app: string): Promise<*>,
152+
flashKnownApp(deviceID: string, userID: string, app: string): Promise<*>,
153153
getAll(userID: string): Promise<Array<Device>>,
154154
getByID(deviceID: string, userID: string): Promise<Device>,
155155
getDetailsByID(deviceID: string, userID: string): Promise<*>,
156156
getVariableValue(deviceID: string, userID: string, varName: string): Promise<Object>,
157157
provision(deviceID: string, userID: string, publicKey: string): Promise<*>,
158+
raiseYourHand(deviceID: string, userID: string, shouldShowSignal: boolean): Promise<void>,
158159
renameDevice(deviceID: string, userID: string, name: string): Promise<DeviceAttributes>,
159160
unclaimDevice(deviceID: string, userID: string): Promise<DeviceAttributes>,
160161
};

0 commit comments

Comments
 (0)