I've been poking around the guts of the plugin and noticed at least one thing.
C4W had put in some
indigo.server.log output in the color processing part of
homekit.py and commented them out (probably for release.)
I uncommented them and got a slightly better idea of what it was doing...I'm certainly no real programmer and have the simplest grasp on Python.
It looks like the plugin is getting values from the HomeKit app (in my case, the Home app on my phone or Mac.) that get processed as HSV in some cases, and some he has formatted as HST...with Temperature not Value...not sure what this exactly means.
One of the functions calls the python
colorsys library to convert HSV to RGB...here's the code as it is in the plugin:
- Code: Select all
r, g, b = colorsys.hsv_to_rgb(h, s, v)
r, g, b = [x*255.0 for x in r, g, b]
Now, here's the output from the logging I uncommented as I tried a color that gave the
chr() arg not in range(256) error...
- Code: Select all
HomeKit Bridge Converting H: 0.616666666667 | S: 0.2 | V: 0.41
HomeKit Bridge R: 83.64 | G: 89.913 | B: 104.55
Z-Wave Error chr() arg not in range(256)
So, if you look at the RGB values returned by the code above, you see B is 104.55. These three RGB numbers would work in a 0-255 scale and should give the correct color, but Indigo wants a percent value for the RGB values...and 104.55 exceeds that, hence the error. The output of the raw HSVtoRGB before the *255 part is:
- Code: Select all
>>> import colorsys
>>> colorsys.hsv_to_rgb(0.616666666667, 0.2, 0.41)
(0.328, 0.352599999999836, 0.41)
I modified the code to multiply by 100 not by 255, since the HSVtoRGG process outputs a value from 0.0 to 1.0, so technically it's already covered from the 0-255 scale to 0-100, just cut down to 1/100th.
- Code: Select all
r, g, b = colorsys.hsv_to_rgb(h, s, v)
r, g, b = [x*100.0 for x in r, g, b]
Using this, the same input as before now gives the following RGB values
R = 20.0899999999
G = 13.12
B = 41.0
So Indigo doesn't choke on these values since they won't exceed 100 now, and the colors match pretty close.
NOW...the part I'm banging my head against the wall on...
Sometimes it doesn't say "Adding Saturation to service" or "Adding Hue to service" as seen in this successful log set:
- Code: Select all
HomeKit Bridge Adding Saturation to service
HomeKit Bridge H: -1 | S: 20.0 | T: -1
HomeKit Bridge Adding Hue to service
HomeKit Bridge H: 222.0 | S: 20.0 | T: -1
HomeKit Bridge Setting color for 012 - Composite
It instead will say
- Code: Select all
HomeKit Bridge Adding ColorTemperature to service
HomeKit Bridge H: -1 | S: -1 | T: 3125.0
Z-Wave Error chr() arg not in range(256)
So it's trying to use a color temperature instead...and there's a bit of code for handling that, but something in there is not converting to usable RGB values. Here's the code block for this:
- Code: Select all
if hkservice.colortemperature != -1:
# Color temps are completely independant of color (at least when using a Hue bulb integrated from the Hue app in Home it is, it can be white to orange
kelvin = 1000000 / value # Convert mireds to Kelvin for the conversion
r, g, b = calcs.convert_K_to_RGB(kelvin) # Convert Kelvin to RGB
indigo.dimmer.setColorLevels (devId, redLevel=r, greenLevel=g, blueLevel=b)
This is where I spew long strings of profanity at Python, because I have tried every way of putting in the logs the RGB values EXACTLY the same way as in the other section, but ANY changes in this block will give an Invalid Syntax error and break the plugin loading.
- Code: Select all
indigo.server.log (u'R: {} | G: {} | B: {}'.format(r,g,b))
That's exactly the same line that works perfectly fine in the other parts of this to log the R G and B values...but if I try to put it (or ANY perfectly valid python code) anywhere in that block, it breaks.
Really disliking Python right now...I thought PowerShell was a pain in the butt...seriously...I cannot for the life of me figure out how/where it's breaking syntax or indentation...I get this
- Code: Select all
HomeKit Bridge Error Error in plugin execution InitializeMain:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "plugin.py", line 82, in __init__
File "/Library/Application Support/Perceptive Automation/Indigo 7.4/Plugins/EPS HomeKit Bridge.indigoPlugin/Contents/Server Plugin/lib/eps.py", line 130, in loadLibs
SyntaxError: ('invalid syntax', ('/Library/Application Support/Perceptive Automation/Indigo 7.4/Plugins/EPS HomeKit Bridge.indigoPlugin/Contents/Server Plugin/lib/homekit.py', 2892, 22, " indigo.server.log (u'R: {} | G: {} | B: {}'.format(r,g,b))\n"))
If anyone who is better at this than me has any ideas how to see what the RGB values are when the
if hkservice.colortemperature != -1: block calls the
indigo.dimmer.setColorLevels (devId, redLevel=r, greenLevel=g, blueLevel=b) command after doing the Kelvin conversion call...
My head hurts...
Thanks
Ross