-
-
Notifications
You must be signed in to change notification settings - Fork 39
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
Inconsistency between .LastValue and .LastValueNumeric with Channels #7
Comments
Hi @smarrocco,
There is an existing note about this on the wiki, but it's not exactly clear for C# users, so I will add some additional notes both on the Wiki and in the XML documentation Ideally, I'd like to abstract this behavior away and make it possible to get and set values according to the unit the channel has been configured with, however since I can only guess every possible unit that could have a different "raw" value, this introduces a an amount of risk of either malfunctioning or introducing conflicting behavior, which would be even more confusing for the user Regards, |
Understood, thank you for the explanation. |
You can optionally write an extension method that does this for you static class ChannelExtensions
{
public static double? GetLastValue(this Channel channel)
{
if (channel.LastValue == null)
return null;
var str = channel.DisplayLastValue.Substring(0, channel.LastValue.IndexOf(' '));
return Convert.ToDouble(str);
}
} // Get all the last values of all channels on sensor ID 1234
var values = client.GetChannels(1234).Select(c => c.GetLastValue()); The other thing to note is the biggest reason PrtgAPI isn't abstracting this away is it creates a lot of complexity with The issue with this then is that a. modifying these properties now takes twice as many web requests, and more importantly b. if PrtgAPI doesn't know about a certain unit it won't perform any modification, resulting in you modifying potentially hundreds of channels and nobody realizing you've actually been modifying them with the wrong values! Regards, EDIT: updated for PrtgAPI 0.9.0 |
Thank you very much for your work on PrtgAPI. Very straightforward to use and loving it!
I am noticing an inconsistency when performing the following operations to obtain channel values:
Client.GetChannels(ID, "Traffic In").Item(0).LastValue
Client.GetChannels(ID, "Traffic In").Item(0).LastValueNumeric
I was expecting .LastValue to be a string consisting of the .LastValueNumeric + the .Unit property (In this case, "kbits/s".
However, the .LastValue and .LastValueNumeric properties are never the same, returning values such as:
.lastValue=2,333,154 kbits/s
.lastValueNumeric=291644197.08 (with Unit equal to "kbit/s")
Am I misinterpreting the properties?
The text was updated successfully, but these errors were encountered: