dkorunic / iSMC

Apple SMC CLI tool that can decode and display temperature, fans, battery, power, voltage and current information
GNU General Public License v3.0
122 stars 13 forks source link

json output to return float or int instead of string #18

Closed tenox7 closed 1 year ago

tenox7 commented 1 year ago

could you please make -o json return values in float or int (for rpm) instead all string? it's really troubling to parse string in to float from supposed to be better than ascii format... :)

in addition, instead of

"value": "28.20 °C"
"value": "16.21 V"

the °C or V or RPM should be another field in json, for example "unit"

  "PMU vbuck5": {
  "key": "",
  "type": "hid",
  "value": 16.15
  "unit": "V"
},

thank you!

dkorunic commented 1 year ago

That would require all output to be radically different, having unit in separate field (or column, depending on output type). While it is perfectly doable, it would break compatibility for everyone already using iSMC outputs for whatever reason..

tenox7 commented 1 year ago

sorry I just added this to my original comment as well :)

tenox7 commented 1 year ago

ok so maybe we can have two values, one as string, for compatibility and a new one as other type?

"PMU vbuck5": {
  "key": "",
  "type": "hid",
  "value": "16.15 V",   // unchanged
  "float": 16.15,       // new 
  "unit": "V"           // new
},

this would not break existing schema / clients

tenox7 commented 1 year ago

parsing "28.20 °C" in Go while unmarshalling Json is absolutely hideous, requires 10 lines of code, you need to split it in to fields by space then go through strconv.ParseFloat(slice[0]), error check each step 😭

dkorunic commented 1 year ago

Done in https://github.com/dkorunic/iSMC/releases/tag/v0.7.0, closing.

tenox7 commented 1 year ago

Thank you!