Skip to content

Commit eae9957

Browse files
authored
Merge pull request #9 from mathoudebine/fix/8-animation-not-working
Fix animation not working with latest HomeAssistant version
2 parents 54e7fb6 + 2d44efb commit eae9957

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

custom_components/timebox_mini/__init__.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
from colour import Color
33
from homeassistant.util import slugify
44
from itertools import product
5-
from timebox import Timebox
5+
from .timebox import Timebox
66
import bluetooth
77
import datetime
88
import logging
99
import math
1010
import 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
1316
TIMEBOX_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

221216
def 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",

custom_components/timebox_mini/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"domain": "timebox_mini",
33
"name": "Timebox Mini",
4-
"version": "1.0",
4+
"version": "1.0.1",
55
"documentation": "https://github.com/mathoudebine/homeassistant-timebox-mini",
66
"issue_tracker": "https://github.com/mathoudebine/homeassistant-timebox-mini/issues",
77
"requirements": [

0 commit comments

Comments
 (0)