bpennypacker / SenseME-Indigo-Plugin

Indigo Plugin for 'Big Ass Solutions' Haiku Fans with SenseME
GNU General Public License v2.0
5 stars 4 forks source link

Plugin will throw exception when trying to read SenseMe status when fan does not have a light installed #1

Closed ZachBenz closed 7 years ago

ZachBenz commented 7 years ago

The problem is in lines 127-131 of SenseME-Indigo-Plugin/SenseME.indigoPlugin/Contents/Server Plugin/plugin.py:

    msg = "<%s;LIGHT;LEVEL;GET;ACTUAL>" % ( fanName )
    res = self.queryFan(fanIP, msg)
    if res:
        self.light_level[dev.id] = res
        dev.updateStateOnServer('brightness', int(res))

The self.queryFan call succeeds, but the result returned when there is no light installed is the literal 'NOT PRESENT'. Thus, on line 131, the call to int(res) throws an exception as a result:

SenseME Fan Error exception in deviceStartComm(Master Bedroom Fan): invalid literal for int() with base 10: 'NOT PRESENT'

This is because 'NOT PRESENT' can't be interpreted as an int. An exception handler would deal with this situation, as would an explicit check for 'NOT PRESENT'

P.S. Thanks for making this plugin!!

bpennypacker commented 7 years ago

Thanks for catching this! Since we've always had the light in our fan it never occurred to me that this might do something strange like return a literal string as an error condition...

If you submit a pull request with the changes you made I'll gladly incorporate it into the project.

ZachBenz commented 7 years ago

Yeah, their API seems to employ a strange mixing of types willy nilly (ints, literals, etc)! Working on testing out a patch now. Should have a pull request to your shortly. To make Indigo work smoothly with upgrading the plugin, my pull request will have the version number bumped to 0.5.

ZachBenz commented 7 years ago

Note to myself to also address: another consequence of this issue is that the updateStatusString method incorrectly can interpret the light as being 'on' when it doesn't exist, because it checks for a light_level of '0' to say the light is 'off', which of course means 'NOT PRESENT' will fall through to the else and get called 'on'.