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

sysutils/nut: Added Nut widget #4166

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

jamtur01
Copy link

@jamtur01 jamtur01 commented Aug 9, 2024

This is an (opinionated) widget for the Nut UPS plugin.

Screenshot 2024-09-15 at 1 32 33 PM

This is my first contribution, so I am happy to adjust or get any feedback.

Signed-off-by: James Turnbull <[email protected]>
Signed-off-by: James Turnbull <[email protected]>
Signed-off-by: James Turnbull <[email protected]>
Signed-off-by: James Turnbull <[email protected]>
@Monviech Monviech self-assigned this Aug 10, 2024
@Monviech Monviech added the feature Adding new functionality label Aug 10, 2024
Copy link
Member

@Monviech Monviech left a comment

Choose a reason for hiding this comment

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

Hey, I have looked at the code and I tried to give feedback. Some of the feedback is optional.

I hope it helps you.

Just as this is your first contribution, this is my first code review, so I hope I addressed most things correctly here.

Thank you for submitting this widget. :)

sysutils/nut/src/opnsense/www/js/widgets/Nut.js Outdated Show resolved Hide resolved
sysutils/nut/src/opnsense/www/js/widgets/Nut.js Outdated Show resolved Hide resolved
sysutils/nut/src/opnsense/www/js/widgets/Nut.js Outdated Show resolved Hide resolved
sysutils/nut/src/opnsense/www/js/widgets/Nut.js Outdated Show resolved Hide resolved
sysutils/nut/src/opnsense/www/js/widgets/Nut.js Outdated Show resolved Hide resolved
sysutils/nut/src/opnsense/www/js/widgets/Metadata/Nut.xml Outdated Show resolved Hide resolved
sysutils/nut/src/opnsense/www/js/widgets/Metadata/Nut.xml Outdated Show resolved Hide resolved
sysutils/nut/src/opnsense/www/js/widgets/Nut.js Outdated Show resolved Hide resolved
sysutils/nut/src/opnsense/www/js/widgets/Nut.js Outdated Show resolved Hide resolved
2. Addressed native ajax call, added early return with unconfigured message
3. Remove help text
4. Added check for data changes
5. Translate statuses
6. Added keys translation
Signed-off-by: James Turnbull <[email protected]>
@jamtur01
Copy link
Author

@Monviech Thanks for your feedback. I'm not primarily a FE person, so it's useful! One issue since replacing the ajaxGet with the function from the Basewidget is that it's not returning any data. I know the UPS diagnostics can be a little slow, but I've tried it with some retries. Is there something obvious I am doing wrong here? I'll poke at it some more when I have a free minute.

@Monviech
Copy link
Member

Monviech commented Aug 10, 2024

Can you give me the json output of /api/nut/diagnostics/upsstatus then I can test the widget sometime later.

Also how long does the response take, longer than a second?

Cause when its really slow the action that gets the status might need to be cached.

opnsense/core@06d5077

@jamtur01
Copy link
Author

jamtur01 commented Aug 10, 2024

{"response":"battery.charge: 100\nbattery.charge.low: 10\nbattery.charge.warning: 20\nbattery.mfr.date: CPS\nbattery.runtime: 17475\nbattery.runtime.low: 300\nbattery.type: PbAcid\nbattery.voltage: 26.2\nbattery.voltage.nominal: 24\ndevice.mfr: CPS\ndevice.model: CP1500AVRLCD3\ndevice.serial: BHPNY7002755\ndevice.type: ups\ndriver.debug: 0\ndriver.flag.allow_killpower: 0\ndriver.name: usbhid-ups\ndriver.parameter.pollfreq: 30\ndriver.parameter.pollinterval: 2\ndriver.parameter.port: auto\ndriver.paramer.synchronous: auto\ndriver.state: quiet\ndriver.version: 2.8.2\ndriver.version.data: CyberPower HID 0.80\ndriver.version.internal: 0.53\ndriver.version.usb: libusb-1.0.0 (API: 0x1000102)\ninput.voltage: 121.0\ninput.voltage.nominal: 120\noutput.voltage: 121.0\nups.beeper.status: enabled\nups.delay.shutdown: 20\nups.delay.start: 30\nups.load: 0\nups.mfr: CPS\nups.model: CP1500AVRLCD3\nups.productid: 0601\nups.realpower.nominal: 900\nups.serial: BHPNY7002755\nups.status: OL\nups.test.result: No test initiated\nups.timer.shutdown: -60\nups.timer.start: -60\nups.vendorid: 0764\n\n\n"}

In the Service itself, the Diagnostics data takes 1-2 seconds to return.

@Monviech
Copy link
Member

Maybe try to set a cache_ttl here as linked in my prior post. Maybe 30s and see if it gets better. Unsure though.

@fichtner fichtner assigned fichtner and unassigned Monviech Aug 20, 2024
@shomilsaini
Copy link

Any updates on when this will be merged to production?

Thanks

@jamtur01
Copy link
Author

I haven't had a chance to look at this again. I'll try to take a look this w/e.

@jamtur01
Copy link
Author

@Monviech @fichtner @mimugmail This should now be ready for another review. I refactored it to be more like the other UPS plugin and that resolved the issues.

@jamtur01 jamtur01 changed the title Added Nut widget sysutils/nut: Added Nut widget Sep 14, 2024
@jamtur01
Copy link
Author

And I noticed someone else wrote another plugin. shrugs Choose whichever suits you.

@shomilsaini
Copy link

shomilsaini commented Sep 14, 2024

@mimugmail , @jamtur01 - How do i use this in my opnsense?

@wogglenet
Copy link

It would be nice if this calculated the estimated load in watts

Signed-off-by: James Turnbull <[email protected]>
@jamtur01
Copy link
Author

calculated the estimated load in watts

Sure. Done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Adding new functionality
Development

Successfully merging this pull request may close these issues.

5 participants