Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to list all registered decoders by the plugin #114

Merged
merged 9 commits into from Oct 27, 2021

Conversation

rolljee
Copy link
Contributor

@rolljee rolljee commented Oct 20, 2021

This Pull Request add the support of a new action In the controller device-manager/devices called listDecoders

Added a new controller called DecodersController with his dedicated DecodersService with a new action called list

This new action allow the user the print out all currently registered decoders by the plugin

Close #114

@rolljee rolljee self-assigned this Oct 20, 2021
@Aschen
Copy link
Contributor

Aschen commented Oct 20, 2021

Actually it would be better to have a DecoderController since in the futur we may be able to modify existing decoder. A use-case could be to update the code used to decode payloads dynamically


```js
{
"controller": "device-manager/device",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should rather be in a dedicated decoder controller

"node": "knode-shaggy-salmon-94717",
"requestId": "e74e2d34-6699-4dbf-8f38-874c6d2b9e1a",
"result": {
"size": 2,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless property, if we want the array size we can just read the length property (or it's equivalent in another language)

@@ -36,6 +36,13 @@ export class DeviceService {
this.decoders = decoders;
}

async listDecoders() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be interesting to return the name of each decoder and info about this decoder. For now I can only think about the kind of measures decoded by the decoder. In the future we may add other information like mandatory payload properties, number of decoded payloads, ...

* List all available decoders
*/
async listDecoders () {
return this.deviceService.listDecoders();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicking: IMHO it's better to return a variable and then return it in the controller action. The purpose of this is to be able to see the return of an API action directly by seeing the code of the method

@Aschen
Copy link
Contributor

Aschen commented Oct 20, 2021

Can you change the PR title to have a nice changelog also please?

@rolljee rolljee changed the title add feature list-decoders Allow to list all registered decoders by the plugin Oct 20, 2021
@rolljee
Copy link
Contributor Author

rolljee commented Oct 20, 2021

@Aschen I took the shortcut in order to see if we needed a dedicated controller for this purpose, i'll glady move the code 👍

@Aschen
Copy link
Contributor

Aschen commented Oct 20, 2021

Also, this PR is missing appropriate labels

@rolljee rolljee requested a review from Aschen October 21, 2021 14:59
lib/controllers/DecodersController.ts Outdated Show resolved Hide resolved
lib/core-classes/DecodersService.ts Outdated Show resolved Hide resolved
lib/core-classes/DecodersService.ts Outdated Show resolved Hide resolved
@rolljee rolljee mentioned this pull request Oct 22, 2021
@rolljee rolljee linked an issue Oct 22, 2021 that may be closed by this pull request
@rolljee rolljee requested a review from Aschen October 25, 2021 09:22
actions: {
list: {
handler: this.list.bind(this),
http: [{ verb: 'get', path: 'device-manager/decoders/_list' }]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In REST spec a get to the name of the resource in plural form mean to list elements

Suggested change
http: [{ verb: 'get', path: 'device-manager/decoders/_list' }]
http: [{ verb: 'get', path: 'device-manager/decoders' }]

@@ -63,8 +69,9 @@ export abstract class Decoder {
/**
* @param deviceModel Device model for this decoder
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments should be updated as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but this hasn't changed 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was talking about the constructor now takes 2 params instead of one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, i didn't understud it that way ! i'll change that with the last Nitpiking you added

throw new PreconditionError(`Missing property "${path}" in payload`);
}
}
}

static serialize(decoders: Map<string, Decoder>): DecoderConstructor[] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The serialize method should rather be an instance method, meaning the Decoder is responsible of it's own serialization decoder.serialize().
The DecoderService.list method should then call this method for every decoder

@@ -0,0 +1,4 @@
export interface DecoderConstructor {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be DecoderContent instead (like the file name which is good since it represents the serialized content of a decoder)


async list(): Promise<DecoderContent[]> {
const decoders = Array
.from(this.decoders.keys())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you could use this.decoders.values() to directly access the values

@rolljee rolljee merged commit 644cc26 into 1-dev Oct 27, 2021
@rolljee rolljee deleted the feat/list-decoders branch October 27, 2021 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an action to list available decoders
2 participants