Skip to content

Commit

Permalink
Fixed tox errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rospogrigio committed May 24, 2023
1 parent 928f8e9 commit 5f91417
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
48 changes: 24 additions & 24 deletions custom_components/localtuya/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 15 additions & 5 deletions custom_components/localtuya/pytuya/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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}}, ...}
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 5f91417

Please sign in to comment.