Use string conversion over isinstance in mqtt message handling if possible (#101364)
This commit is contained in:
parent
c0904c905d
commit
4553de5cbf
2 changed files with 4 additions and 2 deletions
|
@ -177,7 +177,7 @@ class MqttAlarm(MqttEntity, alarm.AlarmControlPanelEntity):
|
|||
|
||||
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
|
||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
|
||||
from collections.abc import Callable
|
||||
import functools
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
|
@ -137,7 +138,8 @@ class MqttDeviceTracker(MqttEntity, TrackerEntity):
|
|||
elif payload == self._config[CONF_PAYLOAD_RESET]:
|
||||
self._location_name = None
|
||||
else:
|
||||
assert isinstance(msg.payload, str)
|
||||
if TYPE_CHECKING:
|
||||
assert isinstance(msg.payload, str)
|
||||
self._location_name = msg.payload
|
||||
|
||||
state_topic: str | None = self._config.get(CONF_STATE_TOPIC)
|
||||
|
|
Loading…
Add table
Reference in a new issue