mirror of
https://github.com/XiaoMi/ha_xiaomi_home.git
synced 2026-01-18 08:00:42 +08:00
perf: reduce the number of judgments
This commit is contained in:
parent
7b7553c5f8
commit
8abf087c3e
@ -122,36 +122,28 @@ class Notify(MIoTActionEntity, NotifyEntity):
|
|||||||
return
|
return
|
||||||
in_value: list[dict] = []
|
in_value: list[dict] = []
|
||||||
for index, prop in enumerate(self.spec.in_):
|
for index, prop in enumerate(self.spec.in_):
|
||||||
if (
|
if prop.format_ == 'str':
|
||||||
prop.format_ == 'str'
|
if isinstance(in_list[index], (bool, int, float, str)):
|
||||||
and isinstance(in_list[index], (bool, int, float, str))
|
in_value.append(
|
||||||
):
|
{'piid': prop.iid, 'value': str(in_list[index])})
|
||||||
in_value.append(
|
continue
|
||||||
{'piid': prop.iid, 'value': str(in_list[index])})
|
elif prop.format_ == 'bool':
|
||||||
continue
|
if isinstance(in_list[index], (bool, int)):
|
||||||
if (
|
# yes, no, on, off, true, false and other bool types
|
||||||
prop.format_ == 'bool'
|
# will also be parsed as 0 and 1 of int.
|
||||||
and isinstance(in_list[index], (bool, int))
|
in_value.append(
|
||||||
):
|
{'piid': prop.iid, 'value': bool(in_list[index])})
|
||||||
# yes, no, on, off, true, false and other bool types will also
|
continue
|
||||||
# be parsed as 0 and 1 of int.
|
elif prop.format_ == 'float':
|
||||||
in_value.append(
|
if isinstance(in_list[index], (int, float)):
|
||||||
{'piid': prop.iid, 'value': bool(in_list[index])})
|
in_value.append(
|
||||||
continue
|
{'piid': prop.iid, 'value': in_list[index]})
|
||||||
if (
|
continue
|
||||||
prop.format_ == 'float'
|
elif prop.format_ == 'int':
|
||||||
and isinstance(in_list[index], (int, float))
|
if isinstance(in_list[index], int):
|
||||||
):
|
in_value.append(
|
||||||
in_value.append(
|
{'piid': prop.iid, 'value': in_list[index]})
|
||||||
{'piid': prop.iid, 'value': in_list[index]})
|
continue
|
||||||
continue
|
|
||||||
if (
|
|
||||||
prop.format_ == 'int'
|
|
||||||
and isinstance(in_list[index], int)
|
|
||||||
):
|
|
||||||
in_value.append(
|
|
||||||
{'piid': prop.iid, 'value': in_list[index]})
|
|
||||||
continue
|
|
||||||
# Invalid params type, raise error.
|
# Invalid params type, raise error.
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
'action exec failed, %s(%s), invalid params item, '
|
'action exec failed, %s(%s), invalid params item, '
|
||||||
|
|||||||
@ -141,36 +141,28 @@ class ActionText(MIoTActionEntity, TextEntity):
|
|||||||
f'invalid action params, {value}')
|
f'invalid action params, {value}')
|
||||||
in_value: list[dict] = []
|
in_value: list[dict] = []
|
||||||
for index, prop in enumerate(self.spec.in_):
|
for index, prop in enumerate(self.spec.in_):
|
||||||
if (
|
if prop.format_ == 'str':
|
||||||
prop.format_ == 'str'
|
if isinstance(in_list[index], (bool, int, float, str)):
|
||||||
and isinstance(in_list[index], (bool, int, float, str))
|
in_value.append(
|
||||||
):
|
{'piid': prop.iid, 'value': str(in_list[index])})
|
||||||
in_value.append(
|
continue
|
||||||
{'piid': prop.iid, 'value': str(in_list[index])})
|
elif prop.format_ == 'bool':
|
||||||
continue
|
if isinstance(in_list[index], (bool, int)):
|
||||||
if (
|
# yes, no, on, off, true, false and other bool types
|
||||||
prop.format_ == 'bool'
|
# will also be parsed as 0 and 1 of int.
|
||||||
and isinstance(in_list[index], (bool, int))
|
in_value.append(
|
||||||
):
|
{'piid': prop.iid, 'value': bool(in_list[index])})
|
||||||
# yes, no, on, off, true, false and other bool types will also
|
continue
|
||||||
# be parsed as 0 and 1 of int.
|
elif prop.format_ == 'float':
|
||||||
in_value.append(
|
if isinstance(in_list[index], (int, float)):
|
||||||
{'piid': prop.iid, 'value': bool(in_list[index])})
|
in_value.append(
|
||||||
continue
|
{'piid': prop.iid, 'value': in_list[index]})
|
||||||
if (
|
continue
|
||||||
prop.format_ == 'float'
|
elif prop.format_ == 'int':
|
||||||
and isinstance(in_list[index], (int, float))
|
if isinstance(in_list[index], int):
|
||||||
):
|
in_value.append(
|
||||||
in_value.append(
|
{'piid': prop.iid, 'value': in_list[index]})
|
||||||
{'piid': prop.iid, 'value': in_list[index]})
|
continue
|
||||||
continue
|
|
||||||
if (
|
|
||||||
prop.format_ == 'int'
|
|
||||||
and isinstance(in_list[index], int)
|
|
||||||
):
|
|
||||||
in_value.append(
|
|
||||||
{'piid': prop.iid, 'value': in_list[index]})
|
|
||||||
continue
|
|
||||||
# Invalid params type, raise error.
|
# Invalid params type, raise error.
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
'action exec failed, %s(%s), invalid params item, '
|
'action exec failed, %s(%s), invalid params item, '
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user