nutdotnet / WinNUT-Client

WinForms-based client for monitoring your Uninterruptible Power Supply (UPS) connected to a Network UPS Tools (NUT) server.
GNU General Public License v3.0
226 stars 20 forks source link

Define UPS_States values as pow of 2 to fix state change detection #71

Closed supersmile2009 closed 1 year ago

supersmile2009 commented 1 year ago

The existing state detection logic relies on bitwise operations to compare old and new state and to extract the changed state flags. However it's fundamentally broken due to UPS_States enum not using the power of 2 values. Bitwise logic produces invalid states change set because of that.

I discovered it while I was trying to make this client follow FSD signal from the server. But it never detects the change for FSD state. The only case when it starts the shutdown procedure is if you connect to the server which is already in FSD state.

gbakeman commented 1 year ago

Sorry for taking so long to get to this; usual real life activities so projects had to be put on hold.

I could've sworn enum values were auto-generated in powers of two when using the FlagsAttribute, but sure enough, they need to be manually defined. Thank you so much for this, I'm just trying to get my VM with upsd up so I can figure out how I even missed this and then merge your changes.

Thank you for contributing!

supersmile2009 commented 1 year ago

Hey @gbakeman. You have nothing to be sorry about. It's open source, everyone has different capacity for this kind of work. I'd actually say it was a fairly decent response time considering that you're just a single maintainer here and have other job. Thanks for finding time to take a look at it and merging!