From d2dbb6a6550f3380018e2cf2a3558e962d79ab21 Mon Sep 17 00:00:00 2001 From: Matthijs van der Burgh Date: Thu, 12 Sep 2024 09:40:32 +0200 Subject: [PATCH] Satisfy xo --- lib/body.js | 11 ++++++----- lib/ed-robocup.js | 2 +- lib/ed.js | 24 ++++++++++++------------ lib/hardware.js | 22 ++++++++++++++-------- test/initialization.test.js | 4 +++- 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/lib/body.js b/lib/body.js index 8469743..a329a46 100644 --- a/lib/body.js +++ b/lib/body.js @@ -34,15 +34,15 @@ class Body { this.grippers = {}; for (const [partName, part] of Object.entries(parameter_)) { - if (Object.prototype.hasOwnProperty.call(part, 'joint_names')) { + if (Object.hasOwn(part, 'joint_names')) { // eslint-disable-line no-use-extend-native/no-use-extend-native this.jointNames[partName] = part.joint_names; } - if (Object.prototype.hasOwnProperty.call(part, 'default_configurations')) { + if (Object.hasOwn(part, 'default_configurations')) { // eslint-disable-line no-use-extend-native/no-use-extend-native this.defaultConfigurations[partName] = part.default_configurations; } - if (Object.prototype.hasOwnProperty.call(part, 'ac_gripper')) { + if (Object.hasOwn(part, 'ac_gripper')) { // eslint-disable-line no-use-extend-native/no-use-extend-native this.grippers[partName] = new ActionClient({ ros, serverName: part.ac_gripper, @@ -93,7 +93,7 @@ class Body { sendGripperGoal(cmd) { console.log('Robot body: gripper goal:', cmd); - if (!Object.prototype.hasOwnProperty.call(this.grippers, cmd.side)) { + if (!Object.hasOwn(this.grippers, cmd.side)) { // eslint-disable-line no-use-extend-native/no-use-extend-native console.error(`Gripper command side must be one of [${Object.keys(this.grippers)}]. Right now, it is '${cmd.side}'`); return; } @@ -120,7 +120,8 @@ class Body { command: { /* eslint camelcase:0 */ direction, - max_torque: 10}, + max_torque: 10, + }, }, }); diff --git a/lib/ed-robocup.js b/lib/ed-robocup.js index 26f7538..e7dd660 100644 --- a/lib/ed-robocup.js +++ b/lib/ed-robocup.js @@ -111,7 +111,7 @@ export default class EdRobocup extends Ed { } create_walls(callback) { - callback = callback || _.noop; + callback ||= _.noop; this.createWallsService.callService({}, () => { callback(); }); diff --git a/lib/ed.js b/lib/ed.js index fef43f4..320a6b8 100644 --- a/lib/ed.js +++ b/lib/ed.js @@ -89,7 +89,7 @@ class Ed extends EventEmitter2 { // update object const oldObject = this.entities.get(id); - if (Object.prototype.hasOwnProperty.call(entity, 'pose')) { + if (Object.hasOwn(entity, 'pose')) { // eslint-disable-line no-use-extend-native/no-use-extend-native const {position, quaternion} = parseEdPosition(entity.pose); newObject.position = position; newObject.quaternion = quaternion; @@ -99,11 +99,11 @@ class Ed extends EventEmitter2 { oldObject.quaternion && (newObject.quaternion = oldObject.quaternion); } - if (Object.prototype.hasOwnProperty.call(entity, 'mesh')) { + if (Object.hasOwn(entity, 'mesh')) { // eslint-disable-line no-use-extend-native/no-use-extend-native const {vertices, faces} = parseEdMesh(entity.mesh); newObject.vertices = vertices; newObject.faces = faces; - } else if (Object.prototype.hasOwnProperty.call(entity, 'convex_hull')) { + } else if (Object.hasOwn(entity, 'convex_hull')) { // eslint-disable-line no-use-extend-native/no-use-extend-native const {vertices, faces} = parseEdConvexHull(entity.convex_hull); newObject.vertices = vertices; newObject.faces = faces; @@ -116,24 +116,24 @@ class Ed extends EventEmitter2 { this.entities.set(id, newObject); // only queue full objects for update - const props = ['position', 'quaternion', 'vertices', 'faces']; - if (props.every(key => key in newObject)) { + const properties = ['position', 'quaternion', 'vertices', 'faces']; + if (properties.every(key => key in newObject)) { update.push([newObject, oldObject]); } } else { // add object - if (Object.prototype.hasOwnProperty.call(entity, 'pose')) { + if (Object.hasOwn(entity, 'pose')) { // eslint-disable-line no-use-extend-native/no-use-extend-native const {position, quaternion} = parseEdPosition(entity.pose); newObject.position = position; newObject.quaternion = quaternion; } - if (Object.prototype.hasOwnProperty.call(entity, 'mesh')) { + if (Object.hasOwn(entity, 'mesh')) { // eslint-disable-line no-use-extend-native/no-use-extend-native const {vertices, faces} = parseEdMesh(entity.mesh); newObject.vertices = vertices; newObject.faces = faces; - } else if (Object.prototype.hasOwnProperty.call(entity, 'convex_hull')) { + } else if (Object.hasOwn(entity, 'convex_hull')) { // eslint-disable-line no-use-extend-native/no-use-extend-native const {vertices, faces} = parseEdConvexHull(entity.convex_hull); newObject.vertices = vertices; newObject.faces = faces; @@ -142,8 +142,8 @@ class Ed extends EventEmitter2 { this.entities.set(id, newObject); // only queue full objects for update - const props = ['position', 'quaternion', 'vertices', 'faces']; - if (props.every(key => key in newObject)) { + const properties = ['position', 'quaternion', 'vertices', 'faces']; + if (properties.every(key => key in newObject)) { add.push(newObject); } } @@ -192,8 +192,8 @@ function parseEdConvexHull(chull) { // Calculate side triangles for (let i = 0; i < chull.points.length; i++) { - const j = (i + 1) % chull.points.length; - faces.push([j * 2, (i * 2) + 1, i * 2], [j * 2, (j * 2) + 1, (i * 2) + 1]); + const i2 = (i + 1) % chull.points.length; + faces.push([i2 * 2, (i * 2) + 1, i * 2], [i2 * 2, (i2 * 2) + 1, (i * 2) + 1]); } return {vertices, faces}; diff --git a/lib/hardware.js b/lib/hardware.js index b53aba6..6f8b305 100644 --- a/lib/hardware.js +++ b/lib/hardware.js @@ -91,6 +91,7 @@ class Hardware extends EventEmitter2 { * Public status API */ _status = defaultStatus; + get status() { return this._status; } @@ -106,6 +107,7 @@ class Hardware extends EventEmitter2 { } _resetHardwareLater = debounce(this._resetHardware, HARDWARE_TIMEOUT); + _resetHardware() { console.log('hardware message timeout'); this.status = defaultStatus; @@ -118,11 +120,11 @@ class Hardware extends EventEmitter2 { * > hardware.send_command('head', 'start') */ send_command(part, command) { - if (!Object.prototype.hasOwnProperty.call(hardwareIds, part)) { + if (!Object.hasOwn(hardwareIds, part)) { // eslint-disable-line no-use-extend-native/no-use-extend-native throw new RangeError('Invalid part'); } - if (!Object.prototype.hasOwnProperty.call(commands, command)) { + if (!Object.hasOwn(commands, command)) { // eslint-disable-line no-use-extend-native/no-use-extend-native throw new RangeError('Invalid command'); } @@ -141,6 +143,7 @@ class Hardware extends EventEmitter2 { * Public battery API */ _battery = null; + get battery() { return this._battery; } @@ -160,6 +163,7 @@ class Hardware extends EventEmitter2 { } _resetBatteryLater = debounce(this._resetBattery, BATTERY_TIMEOUT); + _resetBattery() { console.log('battery message timeout'); this.battery = null; @@ -169,6 +173,7 @@ class Hardware extends EventEmitter2 { * Public ebutton status API */ _ebuttons = null; + get ebuttons() { return this._ebuttons; } @@ -189,6 +194,7 @@ class Hardware extends EventEmitter2 { } _resetEbuttonsLater = debounce(this._resetEbuttons, EBUTTONS_TIMEOUT); + _resetEbuttons() { console.log('ebuttons message timeout'); this.ebuttons = null; @@ -222,8 +228,8 @@ function diagnosticMessageToStatus(message) { // return all possible actions for a hardware part function getActions(name, part) { - const props = properties[name]; - if (!props) { + const properties_ = properties[name]; + if (!properties_) { return null; } @@ -233,7 +239,7 @@ function getActions(name, part) { const actions = {}; // only show the home action if homeable - if (props.homeable) { + if (properties_.homeable) { actions.home = { enabled: level === levels.IDLE, warning: homed @@ -243,8 +249,8 @@ function getActions(name, part) { // always show start action actions.start = { - enabled: level === levels.IDLE && (homed || !props.homeable_mandatory), - warning: props.homeable && !homed + enabled: level === levels.IDLE && (homed || !properties_.homeable_mandatory), + warning: properties_.homeable && !homed ? 'This part is not yet homed, Are you sure you want to proceed?' : false, }; @@ -260,7 +266,7 @@ function getActions(name, part) { }; // only show reset action if resetable - if (props.resetable) { + if (properties_.resetable) { actions.reset = { enabled: level === levels.ERROR, }; diff --git a/test/initialization.test.js b/test/initialization.test.js index 86a3396..7ad30e0 100644 --- a/test/initialization.test.js +++ b/test/initialization.test.js @@ -3,7 +3,9 @@ import chai from 'chai'; import sinonChai from 'sinon-chai'; import {stub} from 'sinon'; import {Ros} from 'roslib'; -import {Base, Ed, Hardware, Head, Robot} from '../lib/index.js'; +import { + Base, Ed, Hardware, Head, Robot, +} from '../lib/index.js'; chai.use(sinonChai); chai.should();