1
0
mirror of https://github.com/home-assistant/core.git synced 2026-02-15 07:36:16 +00:00

Remove parentheses for except statements where it is not needed in mqtt integration (#162398)

This commit is contained in:
Jan Bouwhuis
2026-02-06 11:49:42 +01:00
committed by GitHub
parent 866cd52ada
commit a5b16e3694
5 changed files with 10 additions and 10 deletions

View File

@@ -560,7 +560,7 @@ async def websocket_subscribe(
payload = cast(bytes, mqttmsg.payload).decode(
DEFAULT_ENCODING
) # not str because encoding is set to None
except (AttributeError, UnicodeDecodeError):
except AttributeError, UnicodeDecodeError:
# Convert non UTF-8 payload to a string presentation
payload = str(mqttmsg.payload)

View File

@@ -175,7 +175,7 @@ async def async_publish(
# requires bytes as payload
try:
outgoing_payload = outgoing_payload.encode(encoding)
except (AttributeError, LookupError, UnicodeEncodeError):
except AttributeError, LookupError, UnicodeEncodeError:
_LOGGER.error(
"Can't encode payload for publishing %s on %s with encoding %s",
payload,
@@ -1179,7 +1179,7 @@ class MQTT:
if subscription.encoding is not None:
try:
payload = msg.payload.decode(subscription.encoding)
except (AttributeError, UnicodeDecodeError):
except AttributeError, UnicodeDecodeError:
_LOGGER.warning(
"Can't decode payload %s on %s with encoding %s (for %s)",
msg.payload[0:8192],

View File

@@ -1022,7 +1022,7 @@ def validate_field(
return
try:
user_input[field] = validator(user_input[field])
except (ValueError, vol.Error, vol.Invalid):
except ValueError, vol.Error, vol.Invalid:
errors[field] = error
@@ -3882,7 +3882,7 @@ def validate_user_input(
merged_user_input[field] = (
validator(value) if validator is not None else value
)
except (ValueError, vol.Error, vol.Invalid):
except ValueError, vol.Error, vol.Invalid:
data_schema_field = data_schema_fields[field]
errors[data_schema_field.section or field] = (
data_schema_field.error or "invalid_input"
@@ -5107,7 +5107,7 @@ def async_convert_to_pem(
encryption_algorithm=NoEncryption(),
)
return pem_key_data.decode("utf-8")
except (TypeError, ValueError, SSLError):
except TypeError, ValueError, SSLError:
_LOGGER.exception("Error converting %s file data to PEM format", pem_type.name)
return None
@@ -5507,7 +5507,7 @@ def check_certicate_chain() -> str | None:
try:
with open(private_key, "rb") as client_key_file:
load_pem_private_key(client_key_file.read(), password=None)
except (TypeError, ValueError):
except TypeError, ValueError:
return "client_key_error"
# Check the certificate chain
context = SSLContext(PROTOCOL_TLS_CLIENT)

View File

@@ -278,7 +278,7 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity):
y = float(values["color"]["y"])
self._attr_color_mode = ColorMode.XY
self._attr_xy_color = (x, y)
except (KeyError, TypeError, ValueError):
except KeyError, TypeError, ValueError:
_LOGGER.warning(
"Invalid or incomplete color value '%s' received for entity %s",
values,
@@ -316,7 +316,7 @@ class MqttLightJson(MqttEntity, LightEntity, RestoreEntity):
except KeyError:
pass
except (TypeError, ValueError):
except TypeError, ValueError:
_LOGGER.warning(
"Invalid brightness value '%s' received for entity %s",
values["brightness"],

View File

@@ -58,7 +58,7 @@ def convert_outgoing_mqtt_payload(
if isinstance(payload, str) and payload.startswith(("b'", 'b"')):
try:
native_object = literal_eval(payload)
except (ValueError, TypeError, SyntaxError, MemoryError):
except ValueError, TypeError, SyntaxError, MemoryError:
pass
else:
if isinstance(native_object, bytes):