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

@@ -14,8 +14,8 @@ jobs:
platform: platform:
- ubuntu-latest - ubuntu-latest
python-version: python-version:
- 3.7 - 3.9
- 3.8 - 3.10
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }} - name: Set up Python ${{ matrix.python-version }}

View File

@@ -81,6 +81,7 @@ async def async_setup_entry(
] ]
if entities_to_setup: if entities_to_setup:
tuyainterface = hass.data[DOMAIN][TUYA_DEVICES][dev_id] tuyainterface = hass.data[DOMAIN][TUYA_DEVICES][dev_id]
dps_config_fields = list(get_dps_for_platform(flow_schema)) 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._interface.start_heartbeat()
self.status_updated(status) 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 ( if (self._default_reset_dpids is not None) and (
len(self._default_reset_dpids) > 0 len(self._default_reset_dpids) > 0
): ):
@@ -232,10 +233,10 @@ class TuyaDevice(pytuya.TuyaListener, pytuya.ContextualLogger):
self._interface.start_heartbeat() self._interface.start_heartbeat()
self.status_updated(status) self.status_updated(status)
else: else:
self.error(f"Initial state update failed, giving up: %r", ex) self.error("Initial state update failed, giving up: %r", ex)
# return # return
except (UnicodeDecodeError, json.decoder.JSONDecodeError) as ex: 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() await self.update_local_key()
if self._interface is not None: 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() detected_dps = await interface.detect_available_dps()
except Exception as ex: except Exception as ex:
try: 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: if len(reset_ids) > 0:
await interface.reset(reset_ids) await interface.reset(reset_ids)
detected_dps = await interface.detect_available_dps() detected_dps = await interface.detect_available_dps()
@@ -493,7 +495,7 @@ class LocalTuyaOptionsFlowHandler(config_entries.OptionsFlow):
else: else:
errors["base"] = "discovery_failed" errors["base"] = "discovery_failed"
except Exception as ex: except Exception as ex:
_LOGGER.exception("discovery failed") _LOGGER.exception("discovery failed: %s", ex)
errors["base"] = "discovery_failed" errors["base"] = "discovery_failed"
devices = { devices = {
@@ -604,9 +606,8 @@ class LocalTuyaOptionsFlowHandler(config_entries.OptionsFlow):
defaults[CONF_LOCAL_KEY], defaults[CONF_LOCAL_KEY],
) )
defaults[CONF_LOCAL_KEY] = cloud_devs[dev_id].get(CONF_LOCAL_KEY) defaults[CONF_LOCAL_KEY] = cloud_devs[dev_id].get(CONF_LOCAL_KEY)
placeholders = { note = "\nNOTE: a new local_key has been retrieved using cloud API"
"for_device": f" for device `{dev_id}`.\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) schema = schema_defaults(options_schema(self.entities), **defaults)
else: else:
defaults[CONF_PROTOCOL_VERSION] = "3.3" defaults[CONF_PROTOCOL_VERSION] = "3.3"

View File

@@ -923,9 +923,11 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger):
if not isinstance(payload, str): if not isinstance(payload, str):
try: try:
payload = payload.decode() payload = payload.decode()
except Exception: except Exception as ex:
self.debug("payload was not string type and decoding failed") 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: if "data unvalid" in payload:
self.dev_type = "type_0d" self.dev_type = "type_0d"
self.debug( self.debug(
@@ -943,7 +945,8 @@ class TuyaProtocol(asyncio.Protocol, ContextualLogger):
try: try:
json_payload = json.loads(payload) json_payload = json.loads(payload)
except Exception: 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}}, ...} # v3.4 stuffs it into {"data":{"dps":{"1":true}}, ...}
if ( if (

View File

@@ -1,13 +1,13 @@
[tox] [tox]
skipsdist = true skipsdist = true
envlist = py{38,39}, lint, typing envlist = py{39,310}, lint, typing
skip_missing_interpreters = True skip_missing_interpreters = True
cs_exclude_words = hass,unvalid cs_exclude_words = hass,unvalid
[gh-actions] [gh-actions]
python = python =
3.8: clean, py38, lint, typing
3.9: clean, py39, lint, typing 3.9: clean, py39, lint, typing
3.10: clean, py310, lint, typing
[testenv] [testenv]
passenv = TOXENV,CI passenv = TOXENV,CI