Tox fixes

This commit is contained in:
rospogrigio
2023-02-07 09:57:27 +01:00
parent 999d50ee4e
commit 6d0e407e7e
5 changed files with 20 additions and 15 deletions

View File

@@ -81,6 +81,7 @@ async def async_setup_entry(
]
if entities_to_setup:
tuyainterface = hass.data[DOMAIN][TUYA_DEVICES][dev_id]
dps_config_fields = list(get_dps_for_platform(flow_schema))
@@ -213,7 +214,7 @@ class TuyaDevice(pytuya.TuyaListener, pytuya.ContextualLogger):
self._interface.start_heartbeat()
self.status_updated(status)
except Exception as ex: # pylint: disable=broad-except
except Exception as ex:
if (self._default_reset_dpids is not None) and (
len(self._default_reset_dpids) > 0
):
@@ -232,10 +233,10 @@ class TuyaDevice(pytuya.TuyaListener, pytuya.ContextualLogger):
self._interface.start_heartbeat()
self.status_updated(status)
else:
self.error(f"Initial state update failed, giving up: %r", ex)
self.error("Initial state update failed, giving up: %r", ex)
# return
except (UnicodeDecodeError, json.decoder.JSONDecodeError) as ex:
self.exception(f"Initial state update failed, trying key update")
self.warning("Initial state update failed (%s), trying key update", ex)
await self.update_local_key()
if self._interface is not None:

View File

@@ -258,7 +258,9 @@ async def validate_input(hass: core.HomeAssistant, data):
detected_dps = await interface.detect_available_dps()
except Exception as ex:
try:
_LOGGER.debug("Initial state update failed (%s), trying reset command", ex)
_LOGGER.debug(
"Initial state update failed (%s), trying reset command", ex
)
if len(reset_ids) > 0:
await interface.reset(reset_ids)
detected_dps = await interface.detect_available_dps()
@@ -493,7 +495,7 @@ class LocalTuyaOptionsFlowHandler(config_entries.OptionsFlow):
else:
errors["base"] = "discovery_failed"
except Exception as ex:
_LOGGER.exception("discovery failed")
_LOGGER.exception("discovery failed: %s", ex)
errors["base"] = "discovery_failed"
devices = {
@@ -604,9 +606,8 @@ class LocalTuyaOptionsFlowHandler(config_entries.OptionsFlow):
defaults[CONF_LOCAL_KEY],
)
defaults[CONF_LOCAL_KEY] = cloud_devs[dev_id].get(CONF_LOCAL_KEY)
placeholders = {
"for_device": f" for device `{dev_id}`.\nNOTE: a new local_key has been retrieved using cloud API"
}
note = "\nNOTE: a new local_key has been retrieved using cloud API"
placeholders = {"for_device": f" for device `{dev_id}`.{note}"}
schema = schema_defaults(options_schema(self.entities), **defaults)
else:
defaults[CONF_PROTOCOL_VERSION] = "3.3"

View File

@@ -923,9 +923,11 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger):
if not isinstance(payload, str):
try:
payload = payload.decode()
except Exception:
except Exception as ex:
self.debug("payload was not string type and decoding failed")
return self.error_json(ERR_JSON, payload)
raise DecodeError("payload was not a string: %s", ex)
# return self.error_json(ERR_JSON, payload)
if "data unvalid" in payload:
self.dev_type = "type_0d"
self.debug(
@@ -943,7 +945,8 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger):
try:
json_payload = json.loads(payload)
except Exception:
json_payload = self.error_json(ERR_JSON, payload)
raise DecodeError("could not decrypt data: wrong local_key?")
# json_payload = self.error_json(ERR_JSON, payload)
# v3.4 stuffs it into {"data":{"dps":{"1":true}}, ...}
if (