Fixed tox errors

This commit is contained in:
rospogrigio
2023-05-24 11:50:27 +02:00
parent 928f8e985a
commit 5f9141790d
2 changed files with 39 additions and 29 deletions

View File

@@ -566,31 +566,31 @@ class LocalTuyaOptionsFlowHandler(config_entries.OptionsFlow):
} }
) )
return await self.async_step_pick_entity_type() return await self.async_step_pick_entity_type()
else:
self.device_data.update( self.device_data.update(
{ {
CONF_DEVICE_ID: dev_id, CONF_DEVICE_ID: dev_id,
CONF_DPS_STRINGS: self.dps_strings, CONF_DPS_STRINGS: self.dps_strings,
CONF_ENTITIES: [], 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: if user_input[CONF_ENTITIES]:
return self.async_abort( entity_ids = [
reason="no_entities", int(entity.split(":")[0])
description_placeholders={}, for entity in user_input[CONF_ENTITIES]
) ]
if user_input[CONF_ENTITIES]: device_config = self.config_entry.data[CONF_DEVICES][dev_id]
entity_ids = [ self.entities = [
int(entity.split(":")[0]) entity
for entity in user_input[CONF_ENTITIES] for entity in device_config[CONF_ENTITIES]
] if entity[CONF_ID] in entity_ids
device_config = self.config_entry.data[CONF_DEVICES][dev_id] ]
self.entities = [ return await self.async_step_configure_entity()
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) self.dps_strings = await validate_input(self.hass, user_input)
return await self.async_step_pick_entity_type() return await self.async_step_pick_entity_type()

View File

@@ -769,7 +769,7 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger):
try: try:
msg = await self.dispatcher.wait_for(seqno, payload.cmd) msg = await self.dispatcher.wait_for(seqno, payload.cmd)
except Exception as ex: 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 return None
# TODO: Verify stuff, e.g. CRC sequence number? # TODO: Verify stuff, e.g. CRC sequence number?
@@ -889,7 +889,9 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger):
# self.debug("decrypting=%r", payload) # self.debug("decrypting=%r", payload)
payload = cipher.decrypt(payload, False, decode_text=False) payload = cipher.decrypt(payload, False, decode_text=False)
except Exception as ex: 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) return self.error_json(ERR_PAYLOAD)
# self.debug("decrypted 3.x payload=%r", payload) # self.debug("decrypted 3.x payload=%r", payload)
@@ -915,7 +917,12 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger):
# self.debug("decrypting=%r", payload) # self.debug("decrypting=%r", payload)
payload = cipher.decrypt(payload, False) payload = cipher.decrypt(payload, False)
except Exception as ex: 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) return self.error_json(ERR_PAYLOAD)
# self.debug("decrypted 3.x payload=%r", payload) # self.debug("decrypted 3.x payload=%r", payload)
@@ -946,7 +953,9 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger):
try: try:
json_payload = json.loads(payload) json_payload = json.loads(payload)
except Exception as ex: 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) # json_payload = self.error_json(ERR_JSON, payload)
# v3.4 stuffs it into {"data":{"dps":{"1":true}}, ...} # v3.4 stuffs it into {"data":{"dps":{"1":true}}, ...}
@@ -983,9 +992,10 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger):
payload = cipher.decrypt(payload, False, decode_text=False) payload = cipher.decrypt(payload, False, decode_text=False)
except Exception as ex: except Exception as ex:
self.debug( 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, payload,
len(payload), len(payload),
ex,
) )
return False return False