Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use string conversion over isinstance in mqtt message handling if possible #101364

Merged
merged 2 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion homeassistant/components/mqtt/alarm_control_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _setup_from_config(self, config: ConfigType) -> None:

if (code := self._config.get(CONF_CODE)) is None:
self._attr_code_format = None
elif code == REMOTE_CODE or (isinstance(code, str) and code.isdigit()):
elif code == REMOTE_CODE or str(code).isdigit():
self._attr_code_format = alarm.CodeFormat.NUMBER
else:
self._attr_code_format = alarm.CodeFormat.TEXT
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/mqtt/device_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from collections.abc import Callable
import functools
from typing import TYPE_CHECKING

import voluptuous as vol

Expand Down Expand Up @@ -137,7 +138,8 @@ def message_received(msg: ReceiveMessage) -> None:
elif payload == self._config[CONF_PAYLOAD_RESET]:
self._location_name = None
else:
assert isinstance(msg.payload, str)
jbouwh marked this conversation as resolved.
Show resolved Hide resolved
if TYPE_CHECKING:
assert isinstance(msg.payload, str)
self._location_name = msg.payload

state_topic: str | None = self._config.get(CONF_STATE_TOPIC)
Expand Down