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
186 stars 18 forks source link

Correct `FormatException` when parsing Invariant-locale numbers in user's locale #125

Closed gbakeman closed 7 months ago

gbakeman commented 7 months ago

Several people are reporting that WinNUT is crashing when it attempts to parse the ups.realpower.nominal variable that's returned from the server.

This PR refactors some code in the UPS_Device class related to variable retrieval and parsing. Special precaution is added around the power variable parsing and calculation, and correct variable types are now used throughout (Integer -> Double.) In addition, I now understand that the .Parse() method strictly adheres to the executing machine's locale and will throw the relevant exception should it encounter any number beyond the current locale, unless a locale is manually specified. I've updated how UPS_Device refers to the Invariant culture, which is now used throughout the class. This should completely resolve FormatExceptions revolving around power variable parsing.

However, this fix points to a greater need for parser and variable handling improvements. Specifically, UPS variables and requests should be represented by individual objects with appropriate metadata attached. This will allow for better state control and error handling by the client. Consider prioritizing migrating WinNUT to the NUTDotNet library.