22from colour import Color
33from homeassistant .util import slugify
44from itertools import product
5- from timebox import Timebox
5+ from . timebox import Timebox
66import bluetooth
77import datetime
88import logging
99import math
1010import os
1111
12+ # Width/height of the Timebox (11x11 for the Mini), can be changed for other Timebox support (untested)
13+ TIMEBOX_SIZE = 11
14+
1215# initial connection reply
1316TIMEBOX_HELLO = [0 , 5 , 72 , 69 , 76 , 76 , 79 , 0 ]
1417
@@ -151,18 +154,10 @@ def getFrames(im):
151154 '''
152155 mode = analyseImage (im )['mode' ]
153156
154- p = im .getpalette ()
155157 last_frame = im .convert ('RGBA' )
156158
157159 try :
158160 while True :
159- '''
160- If the GIF uses local colour tables, each frame will have its own palette.
161- If not, we need to apply the global palette to the new frame.
162- '''
163- if not im .getpalette ():
164- im .putpalette (p )
165-
166161 new_frame = Image .new ('RGBA' , im .size )
167162
168163 '''
@@ -181,7 +176,7 @@ def getFrames(im):
181176 pass
182177
183178
184- def process_image (imagedata , sz = 11 , scale = None ):
179+ def process_image (imagedata , sz = TIMEBOX_SIZE , scale = None ):
185180 img = [0 ]
186181 bc = 0
187182 first = True
@@ -208,18 +203,17 @@ def process_image(imagedata, sz=11, scale=None):
208203 return img
209204
210205
211- def load_image (file , sz = 11 , scale = None ):
206+ def load_image (file , sz = TIMEBOX_SIZE , scale = None ):
212207 with Image .open (file ).convert ("RGBA" ) as imagedata :
213208 return process_image (imagedata , sz , scale )
214209
215210
216- def load_gif_frames (imagedata , sz = 11 , scale = None ):
211+ def load_gif_frames (imagedata , sz = TIMEBOX_SIZE , scale = None ):
217212 for f in getFrames (imagedata ):
218213 yield process_image (f , sz , scale )
219214
220215
221216def conv_image (data ):
222- # should be 11x11 px =>
223217 head = [0xbd , 0x00 , 0x44 , 0x00 , 0x0a , 0x0a , 0x04 ]
224218 data = data
225219 ck1 , ck2 = checksum (sum (head ) + sum (data ))
@@ -263,7 +257,7 @@ def handle_action(call):
263257 c = color_convert (Color ("white" ).get_rgb ())
264258
265259 if action == "image" :
266- image = call .data .get (ATTR_IMAGE , "home-assistant-black " )
260+ image = call .data .get (ATTR_IMAGE , "home_assistant_black " )
267261 _LOGGER .debug ('Action : image %s' % (dir_path + "/matrices/" + image + ".png" ))
268262 dev .send (conv_image (load_image (dir_path + "/matrices/" + image + ".png" )))
269263 hass .states .set (entity_id = DOMAIN + "." + slugify (mac ) + "_current_view" ,
0 commit comments