Skip to content

Commit

Permalink
chore: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bennymeg committed Mar 31, 2024
1 parent bdc4cde commit 0087c54
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 100 deletions.
7 changes: 7 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@
"@typescript-eslint"
],
"rules": {
"semi": "off",
"indent": "off",
"space-before-function-paren": "off",
"no-useless-constructor": "off",
"no-multiple-empty-lines": "off",
"no-unreachable": "off",
"no-unused-vars": "off"
}
}
2 changes: 1 addition & 1 deletion butter/mas/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ import { Response } from './interfaces/response';
import { __version__ } from './environment';

// Exposes Butter MAS Python API
export { ClientFactory, HttpClient, Response, __version__ }; // TcpClient, UdpClient
export { ClientFactory, HttpClient, Response, __version__ }; // TcpClient, UdpClient
55 changes: 29 additions & 26 deletions butter/mas/clients/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export class Client {

/**
* Creates an instance of Client.
*
*
* @param {string} ip
* @param {number} [port=3000]
* @param {string} [protocol='http']
* @memberof Client
*/
constructor(ip: string, port: number=3000, protocol: string='http') {
constructor(ip: string, port: number = 3000, protocol: string = 'http') {
this._timeout = 40;
this.ip = ip;
this.port = port;
Expand Down Expand Up @@ -67,11 +67,12 @@ export class Client {
* @returns response containing all the available (loaded) robot animations
* @memberof Client
*/
getAvailableAnimations(reload: boolean=false): Response {
getAvailableAnimations(reload: boolean = false): Response {
const builder = new PacketBuilder(this.ip, this.port, this.protocol).addCommand('animate');

if (reload)
if (reload) {
builder.addParameter('reload');
}

const packet = builder.addParameter('list').build();

Expand All @@ -82,21 +83,22 @@ export class Client {
/**
* Get available (loaded) robot sound assets
*
* @param {boolean} [reload=false]
* @param {boolean} [reload=false]
* @returns response containing all the available (loaded) robot sound assets
* @memberof Client
*/
getAvailableSounds(reload: boolean=false): Response {
getAvailableSounds(reload: boolean = false): Response {
const builder = new PacketBuilder(this.ip, this.port, this.protocol).addCommand('audio');

if (reload)
if (reload) {
builder.addParameter('reload');
}

const packet = builder.addParameter('list').build();

return packet.send(this._timeout);
}


/**
* Get all available motor registers (for Dynamixel motors only)
Expand All @@ -106,7 +108,7 @@ export class Client {
* @returns response containing all the available motor registers
* @memberof Client
*/
getAvailableMotorRegisters(motorName: string, readableOnly: boolean=false): Response {
getAvailableMotorRegisters(motorName: string, readableOnly: boolean = false): Response {
const packet = new PacketBuilder(this.ip, this.port, this.protocol)
.addCommand('dxl')
.addArguments('get', motorName)
Expand Down Expand Up @@ -168,7 +170,7 @@ export class Client {
const packet = new PacketBuilder(this.ip, this.port, this.protocol)
.addCommand('dxl')
.addArguments('set', motorName, registerName, value)
.build();
.build();

return packet.send(this._timeout);
}
Expand Down Expand Up @@ -197,7 +199,7 @@ export class Client {
return packet.send(this._timeout);
}


/**
* Move motor to a certain position (relative to the motor's zero position) in fixed duration
*
Expand All @@ -214,36 +216,37 @@ export class Client {
.addArguments(motorName, position)
.addKeyValuePair('duration', duration)
.addKeyValuePair('units', units)
.build();
.build();

return packet.send(this._timeout);
}


/**
* Move motor to a certain direction (relative to the motor's current position)
*
* @param {string} motorName motor name (as configured on the configurator)
* @param {string} direction motor movement direction (left, right, stop)
* @param {number} [velocity] motor movement speed (in units / sec)
* @param {RotationUnits} [units='radians'] rotation units
* @param {RotationUnits} [units='radians'] rotation units
* @returns response containing execution result
* @memberof Client
*/
moveMotorInDirection(motorName: string, direction: string, velocity?: number, units: RotationUnits = 'radians'): Response {
const direction_code = direction.toLowerCase() == 'right' ? 1 : direction.toLowerCase() == 'left' ? -1 : 0
// eslint-disable-next-line camelcase
const direction_code = direction.toLowerCase() === 'right' ? 1 : direction.toLowerCase() === 'left' ? -1 : 0
const packet = new PacketBuilder(this.ip, this.port, this.protocol)
.addCommand('move')
.addArguments(motorName, direction_code)
.addKeyValuePair('velocity', velocity)
.addKeyValuePair('units', units)
.addParameter('continuously')
.build();
.build();

return packet.send(this._timeout);
}


/**
* Move motor a certain amount of steps (relative to the motor's current position)
*
Expand All @@ -252,18 +255,18 @@ export class Client {
* @param {number} steps amount of steps to move
* @param {number} [velocity] motor movement speed (in radians / sec)
* @param {string} [interpolator] interpolation function
* @param {RotationUnits} [units='radians'] rotation units
* @param {RotationUnits} [units='radians'] rotation units
* @returns response containing execution result
* @memberof Client
*/
// moveMotorInSteps(motorName: string, direction: string, steps: number, velocity?: number, interpolator?: string, units: RotationUnits = 'radians'): Response {
// const direction_code = direction.toLowerCase() == 'right' ? 1 : direction.toLowerCase() == 'left' ? -1 : 0
// const packet = new PacketBuilder(this.ip, this.port, this.protocol).addCommand('move').addArguments(motorName, direction_code)
// .addKeyValuePair('steps', steps)
// .addKeyValuePair('velocity', velocity)
// .addKeyValuePair('velocity', velocity)
// .addKeyValuePair('interpolator', interpolator)
// .addKeyValuePair('units', units)
// .build();
// .build();
// return packet.send(this._timeout);
// }

Expand All @@ -281,8 +284,8 @@ export class Client {
const packet = new PacketBuilder(this.ip, this.port, this.protocol)
.addCommand('animate')
.addArgument(animationName)
.addKeyValuePair("lenient", lenient)
.addKeyValuePair("relative", relative)
.addKeyValuePair('lenient', lenient)
.addKeyValuePair('relative', relative)
.build();

return packet.send(this._timeout);
Expand All @@ -299,7 +302,7 @@ export class Client {
const packet = new PacketBuilder(this.ip, this.port, this.protocol)
.addCommand('animate')
.addParameter('pause')
.build();
.build();

return packet.send(this._timeout);
}
Expand All @@ -315,7 +318,7 @@ export class Client {
const packet = new PacketBuilder(this.ip, this.port, this.protocol)
.addCommand('animate')
.addParameter('resume')
.build();
.build();

return packet.send(this._timeout);
}
Expand Down Expand Up @@ -369,7 +372,7 @@ export class Client {
return packet.send(this._timeout);
}


/**
* Pause current audio playback (if available) on the robot
*
Expand Down Expand Up @@ -416,4 +419,4 @@ export class Client {

return packet.send(this._timeout);
}
}
}
19 changes: 9 additions & 10 deletions butter/mas/clients/client_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { UdpClient } from './client_udp';
* @class ClientFactory
*/
export class ClientFactory {

/**
* Creates new client
*
Expand All @@ -19,13 +18,13 @@ export class ClientFactory {
* @returns requested client
* @memberof ClientFactory
*/
getClient(ip: string, port?: number, protocol: string="http") {
if (protocol == "http") {
getClient(ip: string, port?: number, protocol: string = 'http') {
if (protocol === 'http') {
return port ? new HttpClient(ip, port) : new HttpClient(ip);
} else if (protocol == "tcp") {
} else if (protocol === 'tcp') {
throw new Error('Not Implemented');
return port ? new TcpClient(ip, port) : new TcpClient(ip);
} else if (protocol == "udp") {
} else if (protocol === 'udp') {
throw new Error('Not Implemented');
return port ? new UdpClient(ip, port) : new UdpClient(ip);
} else {
Expand All @@ -41,17 +40,17 @@ export class ClientFactory {
* @returns
* @memberof ClientFactory
*/
getClientClass(protocol: string="http") {
if (protocol == "http") {
getClientClass(protocol: string = 'http') {
if (protocol === 'http') {
return HttpClient;
} else if (protocol == "tcp") {
} else if (protocol === 'tcp') {
throw new Error('Not Implemented');
return TcpClient;
} else if (protocol == "udp") {
} else if (protocol === 'udp') {
throw new Error('Not Implemented');
return UdpClient;
} else {
return null;
}
}
}
}
2 changes: 1 addition & 1 deletion butter/mas/clients/client_http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class HttpClient extends Client {
* @param {string} [protocol='http']
* @memberof HttpClient
*/
constructor(ip: string, port: number=3000, protocol: string='http') {
constructor(ip: string, port: number = 3000, protocol: string = 'http') {
super(ip, port, protocol);
}
}
2 changes: 1 addition & 1 deletion butter/mas/clients/client_tcp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class TcpClient extends Client {
* @param {string} [protocol='tcp']
* @memberof TcpClient
*/
constructor(ip: string, port: number=3003, protocol: string='tcp') {
constructor(ip: string, port: number = 3003, protocol: string = 'tcp') {
super(ip, port, protocol);
}
}
2 changes: 1 addition & 1 deletion butter/mas/clients/client_udp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class UdpClient extends Client {
* @param {string} [protocol='udp']
* @memberof UdpClient
*/
constructor(ip: string, port: number=3030, protocol: string='udp') {
constructor(ip: string, port: number = 3030, protocol: string = 'udp') {
super(ip, port, protocol);
}
}
5 changes: 3 additions & 2 deletions butter/mas/environment.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const __version__ = '2.2.0'
export const app_name = '@butter-robotics/mas-javascript-api'
export const __version__ = '2.4.0';
// eslint-disable-next-line camelcase
export const app_name = '@butter-robotics/mas-javascript-api';
40 changes: 19 additions & 21 deletions butter/mas/packets/packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class Packet {
port: number;
query: string;


/**
* Creates an instance of Packet.
* @param {string} ip robot IP
Expand Down Expand Up @@ -45,9 +45,7 @@ export class Packet {
* @memberof Packet
*/
protected generateResponse(content: ResponseData): Response {
let response: Response;

response = {
const response: Response = {
data: content,
status: 200,
statusText: 'OK'
Expand All @@ -73,7 +71,7 @@ export class Packet {
* @returns
* @memberof Packet
*/
protected generateEmptyResponse(error: any=null, errorType: string='unknown'): Response {
protected generateEmptyResponse(error: any = null, errorType: string = 'unknown'): Response {
let response: Response;

response = {
Expand All @@ -83,14 +81,14 @@ export class Packet {
parameters: null
},
response: {
status: "Failed",
status: 'Failed',
data: null,
metadata: {
handler: "unknown",
exception: `Request resolved with an ${errorType} error. ${error.message}.`,
timestamp: 0,
duration: 0,
asynchronous: false
metadata: {
handler: 'unknown',
exception: `Request resolved with an ${errorType} error. ${error.message}.`,
timestamp: 0,
duration: 0,
asynchronous: false
}
},
executed: false
Expand Down Expand Up @@ -122,14 +120,14 @@ export class Packet {
parameters: null
},
response: {
status: "Failed",
status: 'Failed',
data: null,
metadata: {
handler: "unknown",
exception: `Request resolved with an ${errorType} error. ${error.message}.`,
timestamp: 0,
duration: 0,
asynchronous: false
metadata: {
handler: 'unknown',
exception: `Request resolved with an ${errorType} error. ${error.message}.`,
timestamp: 0,
duration: 0,
asynchronous: false
}
},
executed: false
Expand All @@ -145,6 +143,6 @@ export class Packet {


equals(other: any) {
return other instanceof Packet && this.ip == other.ip && this.port == other.port && this.query == other.query;
return other instanceof Packet && this.ip === other.ip && this.port === other.port && this.query === other.query;
}
}
}
Loading

0 comments on commit 0087c54

Please sign in to comment.