Handle sending ZCL commands with empty bitmap options (#81051)

Handle sending commands with empty bitmaps
This commit is contained in:
puddly 2022-10-26 21:29:48 -04:00 committed by GitHub
parent ce1b56e345
commit b8edc86500
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 20 deletions

View File

@ -14,7 +14,6 @@ import enum
import functools import functools
import itertools import itertools
import logging import logging
import operator
from random import uniform from random import uniform
import re import re
from typing import TYPE_CHECKING, Any, TypeVar from typing import TYPE_CHECKING, Any, TypeVar
@ -163,25 +162,16 @@ def convert_to_zcl_values(
if field.name not in fields: if field.name not in fields:
continue continue
value = fields[field.name] value = fields[field.name]
if issubclass(field.type, enum.Flag): if issubclass(field.type, enum.Flag) and isinstance(value, list):
if isinstance(value, list): new_value = 0
value = field.type(
functools.reduce( for flag in value:
operator.ior, if isinstance(flag, str):
[ new_value |= field.type[flag.replace(" ", "_")]
field.type[flag.replace(" ", "_")] else:
if isinstance(flag, str) new_value |= flag
else field.type(flag)
for flag in value value = field.type(new_value)
],
)
)
else:
value = (
field.type[value.replace(" ", "_")]
if isinstance(value, str)
else field.type(value)
)
elif issubclass(field.type, enum.Enum): elif issubclass(field.type, enum.Enum):
value = ( value = (
field.type[value.replace(" ", "_")] field.type[value.replace(" ", "_")]

View File

@ -195,3 +195,17 @@ async def test_zcl_schema_conversions(hass, device_light):
assert isinstance(converted_data["start_hue"], uint16_t) assert isinstance(converted_data["start_hue"], uint16_t)
assert converted_data["start_hue"] == 196 assert converted_data["start_hue"] == 196
# This time, the update flags bitmap is empty
raw_data = {
"update_flags": [],
"action": 0x02,
"direction": 0x01,
"time": 20,
"start_hue": 196,
}
converted_data = convert_to_zcl_values(raw_data, command_schema)
# No flags are passed through
assert converted_data["update_flags"] == 0