Skip to content

Commit

Permalink
error handling for custom0 rooms, path color fix
Browse files Browse the repository at this point in the history
  • Loading branch information
oven-lab committed Dec 10, 2023
1 parent c1b72a9 commit 268cd03
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
6 changes: 5 additions & 1 deletion custom_components/tuya_cloud_map_extractor/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ async def async_step_colorconf(self, user_input=None):
user_input[CONF_BG_COLOR] = [0, 0, 0]
if not CONF_WALL_COLOR in user_input:
user_input[CONF_WALL_COLOR] = [0, 0, 0]
if not CONF_PATH_COLOR in user_input:
user_input[CONF_PATH_COLOR] = [0, 0, 0]

if CONF_ROOM_COLORS in user_input:
if user_input[CONF_ROOM_COLORS]:
Expand Down Expand Up @@ -157,7 +159,9 @@ async def async_step_colorconf(self, user_input=None):
CONF_WALL_COLOR: selector(
{"color_rgb": {}} # TODO: default value of [255, 255, 255]
),
CONF_PATH_COLOR: selector({"color_rgb": {}}),
CONF_PATH_COLOR: selector(
{"color_rgb": {}}
),
}

if "roominfo" in self.map_header:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,6 @@ class ClientSecretError(Exception):

class DeviceIDError(Exception):
pass

class PixelValueNotDefined(Exception):
pass
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np

from .pylz4 import uncompress
from .const import default_colors, types
from .const import default_colors, types, PixelValueNotDefined

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -39,7 +39,12 @@ def to_array_custom0(
pixeltype = types.custom0.get(
pixellist[width_counter + height_counter * width]
)
pixel = colors[pixeltype]

if pixeltype != None:
pixel = colors[pixeltype]
else:
raise PixelValueNotDefined

line.append(pixel)
width_counter = width_counter + 1
pixels.append(line)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .v1 import decode_v1, to_array_v1, decode_path_v1
from .custom0 import decode_custom0, to_array_custom0
from .tuya import get_download_link
from .const import PixelValueNotDefined

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -66,6 +67,7 @@ def render_layout(raw_map: bytes, header: dict, colors: dict) -> Image.Image:

if protoVer == "custom0":
array = to_array_custom0(pixellist, width, height, colors)

if protoVer == "1":
rooms = header["roominfo"]
array = to_array_v1(pixellist, width, height, rooms, colors)
Expand Down Expand Up @@ -123,9 +125,19 @@ def get_map(
+ str(base64.b64encode(bytes(str(map_link), "utf-8")))
+ " Thank you!"
)
_LOGGER.error(e)
_LOGGER.exception(e)

image = render_layout(raw_map=mapDataArr, header=header, colors=colors)
try:
image = render_layout(raw_map=mapDataArr, header=header, colors=colors)
except PixelValueNotDefined as e:
_LOGGER.error(
"Unsupported data type. Include the following data in a github issue to request the data format to be added: "
+ str(response.status_code)
+ str(base64.b64encode(response.content))
+ str(base64.b64encode(bytes(str(map_link), "utf-8")))
+ " Thank you!"
)
raise e

if urls == {}:
header["urls"] = {
Expand Down

0 comments on commit 268cd03

Please sign in to comment.