anthturner / TPLinkSmartDevices

C# Library for Discovering and Operating TP-Link Smart Devices (HS100/105/110, LB100/110/120/130)
Apache License 2.0
40 stars 18 forks source link

Added support for the metering and reporting capabilities of the HS110 #2

Closed TheBauwssss closed 5 years ago

TheBauwssss commented 5 years ago

I had to make a change to the parsing code that may break devices other than the HS110 (see https://github.com/anthturner/TPLinkSmartDevices/commit/f3ae9e5a30a55b1d74ee09a46b446f0332419035 for more details).

Basically I had to change this

PoweredOnSince = DateTime.Now - TimeSpan.FromSeconds((int)sysInfo.system.get_sysinfo.on_time);

to this

PoweredOnSince = DateTime.Now - TimeSpan.FromSeconds((int)sysInfo.on_time);

This might be a change needed for all devices or it might be a change that is only needed for the HS110. I cannot test this because I only own the HS110. I reccommend testing this before accepting this pull request.

anthturner commented 5 years ago

I agree this may well break something in the future but I'm time-strapped to maintain this and unless there's an issue reported around the structure change, I don't see a good reason to stop and corner-case it.

If you want to submit a corresponding PR, my suggestion would be to null-check your changed object reference, follow it if true, otherwise fall back to the original code. That'll save an Exception context and still cover the case you need. I'm assuming this is just an EU change, but it may also be a miss on my part.

Thanks for contributing!