diff --git a/custom_components/localtuya/config_flow.py b/custom_components/localtuya/config_flow.py index b2c99faed..5c87e2547 100644 --- a/custom_components/localtuya/config_flow.py +++ b/custom_components/localtuya/config_flow.py @@ -566,31 +566,31 @@ async def async_step_configure_device(self, user_input=None): } ) return await self.async_step_pick_entity_type() - else: - self.device_data.update( - { - CONF_DEVICE_ID: dev_id, - CONF_DPS_STRINGS: self.dps_strings, - CONF_ENTITIES: [], - } + + self.device_data.update( + { + CONF_DEVICE_ID: dev_id, + CONF_DPS_STRINGS: self.dps_strings, + CONF_ENTITIES: [], + } + ) + if len(user_input[CONF_ENTITIES]) == 0: + return self.async_abort( + reason="no_entities", + description_placeholders={}, ) - if len(user_input[CONF_ENTITIES]) == 0: - return self.async_abort( - reason="no_entities", - description_placeholders={}, - ) - if user_input[CONF_ENTITIES]: - entity_ids = [ - int(entity.split(":")[0]) - for entity in user_input[CONF_ENTITIES] - ] - device_config = self.config_entry.data[CONF_DEVICES][dev_id] - self.entities = [ - entity - for entity in device_config[CONF_ENTITIES] - if entity[CONF_ID] in entity_ids - ] - return await self.async_step_configure_entity() + if user_input[CONF_ENTITIES]: + entity_ids = [ + int(entity.split(":")[0]) + for entity in user_input[CONF_ENTITIES] + ] + device_config = self.config_entry.data[CONF_DEVICES][dev_id] + self.entities = [ + entity + for entity in device_config[CONF_ENTITIES] + if entity[CONF_ID] in entity_ids + ] + return await self.async_step_configure_entity() self.dps_strings = await validate_input(self.hass, user_input) return await self.async_step_pick_entity_type() diff --git a/custom_components/localtuya/pytuya/__init__.py b/custom_components/localtuya/pytuya/__init__.py index 9d076e34b..e2abc58dc 100644 --- a/custom_components/localtuya/pytuya/__init__.py +++ b/custom_components/localtuya/pytuya/__init__.py @@ -769,7 +769,7 @@ async def exchange(self, command, dps=None): try: msg = await self.dispatcher.wait_for(seqno, payload.cmd) except Exception as ex: - self.debug("Wait was aborted for seqno %d", seqno) + self.debug("Wait was aborted for seqno %d (%s)", seqno, ex) return None # TODO: Verify stuff, e.g. CRC sequence number? @@ -889,7 +889,9 @@ def _decode_payload(self, payload): # self.debug("decrypting=%r", payload) payload = cipher.decrypt(payload, False, decode_text=False) except Exception as ex: - self.debug("incomplete payload=%r (len:%d)", payload, len(payload)) + self.debug( + "incomplete payload=%r with len:%d (%s)", payload, len(payload), ex + ) return self.error_json(ERR_PAYLOAD) # self.debug("decrypted 3.x payload=%r", payload) @@ -915,7 +917,12 @@ def _decode_payload(self, payload): # self.debug("decrypting=%r", payload) payload = cipher.decrypt(payload, False) except Exception as ex: - self.debug("incomplete payload=%r (len:%d)", payload, len(payload)) + self.debug( + "incomplete payload=%r with len:%d (%s)", + payload, + len(payload), + ex, + ) return self.error_json(ERR_PAYLOAD) # self.debug("decrypted 3.x payload=%r", payload) @@ -946,7 +953,9 @@ def _decode_payload(self, payload): try: json_payload = json.loads(payload) except Exception as ex: - raise DecodeError("could not decrypt data: wrong local_key?") + raise DecodeError( + "could not decrypt data: wrong local_key? (exception %s)", ex + ) # json_payload = self.error_json(ERR_JSON, payload) # v3.4 stuffs it into {"data":{"dps":{"1":true}}, ...} @@ -983,9 +992,10 @@ async def _negotiate_session_key(self): payload = cipher.decrypt(payload, False, decode_text=False) except Exception as ex: self.debug( - "session key step 2 decrypt failed, payload=%r (len:%d)", + "session key step 2 decrypt failed, payload=%r with len:%d (%s)", payload, len(payload), + ex, ) return False