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

Handle sending commands with empty bitmaps
pull/81058/head
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 itertools
import logging
import operator
from random import uniform
import re
from typing import TYPE_CHECKING, Any, TypeVar
@ -163,25 +162,16 @@ def convert_to_zcl_values(
if field.name not in fields:
continue
value = fields[field.name]
if issubclass(field.type, enum.Flag):
if isinstance(value, list):
value = field.type(
functools.reduce(
operator.ior,
[
field.type[flag.replace(" ", "_")]
if isinstance(flag, str)
else field.type(flag)
for flag in value
],
)
)
else:
value = (
field.type[value.replace(" ", "_")]
if isinstance(value, str)
else field.type(value)
)
if issubclass(field.type, enum.Flag) and isinstance(value, list):
new_value = 0
for flag in value:
if isinstance(flag, str):
new_value |= field.type[flag.replace(" ", "_")]
else:
new_value |= flag
value = field.type(new_value)
elif issubclass(field.type, enum.Enum):
value = (
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 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