diff --git a/custom_components/tuya_cloud_map_extractor/config_flow.py b/custom_components/tuya_cloud_map_extractor/config_flow.py index a1cc014..f2e2881 100644 --- a/custom_components/tuya_cloud_map_extractor/config_flow.py +++ b/custom_components/tuya_cloud_map_extractor/config_flow.py @@ -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]: @@ -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: diff --git a/custom_components/tuya_cloud_map_extractor/tuya_vacuum_map_extractor/const.py b/custom_components/tuya_cloud_map_extractor/tuya_vacuum_map_extractor/const.py index 5061221..c03ebff 100644 --- a/custom_components/tuya_cloud_map_extractor/tuya_vacuum_map_extractor/const.py +++ b/custom_components/tuya_cloud_map_extractor/tuya_vacuum_map_extractor/const.py @@ -223,3 +223,6 @@ class ClientSecretError(Exception): class DeviceIDError(Exception): pass + +class PixelValueNotDefined(Exception): + pass diff --git a/custom_components/tuya_cloud_map_extractor/tuya_vacuum_map_extractor/custom0.py b/custom_components/tuya_cloud_map_extractor/tuya_vacuum_map_extractor/custom0.py index d04c137..cc14c9e 100644 --- a/custom_components/tuya_cloud_map_extractor/tuya_vacuum_map_extractor/custom0.py +++ b/custom_components/tuya_cloud_map_extractor/tuya_vacuum_map_extractor/custom0.py @@ -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__) @@ -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) diff --git a/custom_components/tuya_cloud_map_extractor/tuya_vacuum_map_extractor/main.py b/custom_components/tuya_cloud_map_extractor/tuya_vacuum_map_extractor/main.py index 38834ba..45f88e0 100644 --- a/custom_components/tuya_cloud_map_extractor/tuya_vacuum_map_extractor/main.py +++ b/custom_components/tuya_cloud_map_extractor/tuya_vacuum_map_extractor/main.py @@ -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__) @@ -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) @@ -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"] = {