Skip to content

Commit

Permalink
explicit null tests
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Ruddick <[email protected]>
  • Loading branch information
Jonathan Dahan and alexrudd2 committed Feb 17, 2025
1 parent d05fc4c commit 718c8cf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/ebb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class EBB {
}

private write(str: string): Promise<void> {
if (process.env.DEBUG_SAXI_COMMANDS) {
if (process.env.DEBUG_SAXI_COMMANDS != null) {
console.log(`writing: ${str}`);
}
const encoder = new TextEncoder();
Expand Down
30 changes: 15 additions & 15 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { EBB, type Hardware } from './ebb';
type Com = string

const getDeviceInfo = (ebb: EBB | null, com: Com) => {
return { com: ebb ? com : null, hardware: ebb?.hardware };
return { com: ebb != null ? com : null, hardware: ebb?.hardware };
};

export async function startServer (port: number, hardware: Hardware = 'v3', com: Com = null, enableCors = false, maxPayloadSize = '200mb') {
Expand All @@ -42,17 +42,17 @@ export async function startServer (port: number, hardware: Hardware = 'v3', com:

wss.on("connection", (ws) => {
clients.push(ws);
ws.on("message", (message) => {
const msg = JSON.parse(message.toString());
ws.on("message", (message, isBinary) => {
const msg = JSON.parse(isBinary ? message : message.toString());

Check failure on line 46 in src/server.ts

View workflow job for this annotation

GitHub Actions / windows-latest - 18.x

Argument of type 'string | RawData' is not assignable to parameter of type 'string'.

Check failure on line 46 in src/server.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest - 18.x

Argument of type 'string | RawData' is not assignable to parameter of type 'string'.

Check failure on line 46 in src/server.ts

View workflow job for this annotation

GitHub Actions / windows-latest - 20.x

Argument of type 'string | RawData' is not assignable to parameter of type 'string'.

Check failure on line 46 in src/server.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest - 20.x

Argument of type 'string | RawData' is not assignable to parameter of type 'string'.

Check failure on line 46 in src/server.ts

View workflow job for this annotation

GitHub Actions / windows-latest - 22.x

Argument of type 'string | RawData' is not assignable to parameter of type 'string'.

Check failure on line 46 in src/server.ts

View workflow job for this annotation

GitHub Actions / ubuntu-latest - 22.x

Argument of type 'string | RawData' is not assignable to parameter of type 'string'.
switch (msg.c) {
case "ping":
ws.send(JSON.stringify({ c: "pong" }));
break;
case "limp":
if (ebb) { ebb.disableMotors(); }
if (ebb != null) { ebb.disableMotors(); }
break;
case "setPenHeight":
if (ebb) {
if (ebb != null) {
(async () => {
if (await ebb.supportsSR()) {
await ebb.setServoPowerTimeout(10000, true);
Expand Down Expand Up @@ -120,15 +120,15 @@ export async function startServer (port: number, hardware: Hardware = 'v3', com:

app.post("/cancel", (req, res) => {
cancelRequested = true;
if (unpaused) {
if (unpaused != null) {
signalUnpause();
}
unpaused = signalUnpause = null;
res.status(200).end();
});

app.post("/pause", (req, res) => {
if (!unpaused) {
if (unpaused == null) {
unpaused = new Promise(resolve => {
signalUnpause = resolve;
});
Expand All @@ -138,7 +138,7 @@ export async function startServer (port: number, hardware: Hardware = 'v3', com:
});

app.post("/resume", (req, res) => {
if (signalUnpause) {
if (signalUnpause != null) {
signalUnpause();
signalUnpause = unpaused = null;
}
Expand All @@ -164,18 +164,18 @@ export async function startServer (port: number, hardware: Hardware = 'v3', com:

const realPlotter: Plotter = {
async prePlot(initialPenHeight: number): Promise<void> {
await ebb.enableMotors(2);
await ebb.setPenHeight(initialPenHeight, 1000, 1000);
await ebb?.enableMotors(2);
await ebb?.setPenHeight(initialPenHeight, 1000, 1000);
},
async executeMotion(motion: Motion, _progress: [number, number]): Promise<void> {
await ebb.executeMotion(motion);
await ebb?.executeMotion(motion);
},
async postCancel(initialPenHeight: number): Promise<void> {
await ebb.setPenHeight(initialPenHeight, 1000);
await ebb?.setPenHeight(initialPenHeight, 1000);
},
async postPlot(): Promise<void> {
await ebb.waitUntilMotorsIdle();
await ebb.disableMotors();
await ebb?.waitUntilMotorsIdle();
await ebb?.disableMotors();
},
};

Expand Down Expand Up @@ -302,7 +302,7 @@ async function * ebbs (path?: string, hardware: Hardware = 'v3') {
}

export async function connectEBB (hardware: Hardware = 'v3', device: string | undefined): Promise<EBB | null> {
if (!device) {
if (device != null) {
const ebbs = await listEBBs();
if (ebbs.length === 0) return null;
device = ebbs[0];
Expand Down

0 comments on commit 718c8cf

Please sign in to comment.