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

HA 2024.9 Compatibility #274

Merged
merged 9 commits into from
Dec 21, 2024
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
10 changes: 7 additions & 3 deletions custom_components/zha_toolkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,15 +806,19 @@ async def toolkit_service(service):
LOGGER.debug(
"Fire %s -> %s", params[p.EVT_SUCCESS], event_data
)
u.get_hass(zha_gw).bus.fire(params[p.EVT_SUCCESS], event_data)
u.get_hass(zha_gw_hass).bus.fire(
params[p.EVT_SUCCESS], event_data
)
else:
if params[p.EVT_FAIL] is not None:
LOGGER.debug("Fire %s -> %s", params[p.EVT_FAIL], event_data)
u.get_hass(zha_gw).bus.fire(params[p.EVT_FAIL], event_data)
u.get_hass(zha_gw_hass).bus.fire(
params[p.EVT_FAIL], event_data
)

if params[p.EVT_DONE] is not None:
LOGGER.debug("Fire %s -> %s", params[p.EVT_DONE], event_data)
u.get_hass(zha_gw).bus.fire(params[p.EVT_DONE], event_data)
u.get_hass(zha_gw_hass).bus.fire(params[p.EVT_DONE], event_data)

if handler_exception is not None:
LOGGER.error(
Expand Down
4 changes: 3 additions & 1 deletion custom_components/zha_toolkit/binds.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
LOGGER = logging.getLogger(__name__)

BINDABLE_OUT_CLUSTERS = [
0x0005, # Scenes
0x0006, # OnOff
0x0008, # Level
0x0102, # Window Covering
0x0300, # Color Control
]
BINDABLE_IN_CLUSTERS = [
Expand Down Expand Up @@ -612,7 +614,7 @@ async def binds_get(
if binding.DstAddress.addrmode == 1:
dst_info = {
"addrmode": binding.DstAddress.addrmode,
"group": f"0x{binding.DstAddress.nwk}",
"group": f"0x{binding.DstAddress.nwk:04X}",
}
elif binding.DstAddress.addrmode == 3:
dst_info = {
Expand Down
9 changes: 6 additions & 3 deletions custom_components/zha_toolkit/scan_device.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ async def discover_attributes_extended(cluster, manufacturer=None, tries=3):
attr_name = attr_def.name
else:
attr_name = attr_def[0]
attr_type = foundation.DATA_TYPES.get(attr_rec.datatype)
try:
attr_type = foundation.DataType.from_type_id(attr_rec.datatype)
except KeyError:
attr_type = None
access_acl = t.uint8_t(attr_rec.acl)

# Note: reading back Array type was fixed in zigpy 0.58.1 .
Expand All @@ -229,8 +232,8 @@ async def discover_attributes_extended(cluster, manufacturer=None, tries=3):
if attr_type:
attr_type = [
attr_type_hex,
attr_type[1].__name__,
attr_type[2].__name__,
attr_type.python_type.__name__,
attr_type.type_class.name,
]
else:
attr_type = attr_type_hex
Expand Down
10 changes: 5 additions & 5 deletions custom_components/zha_toolkit/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@
},
"force_update": {
"name": "Force Update",
"description": "Force an update event when the state is written When not set or false, if the state value is unchanged, the update may not trigger an automation.\n"
"description": "Force an update event when the state is written When not set or false, if the state value is unchanged, the update may not trigger an automation."
},
"use_cache": {
"name": "Use Cache",
"description": "Use zigpy attribute cache to get the value of an attribute. (Does not send a zigbee packet to read the attribute)\n"
"description": "Use zigpy attribute cache to get the value of an attribute. (Does not send a zigbee packet to read the attribute)"
},
"event_success": {
"name": "Success Event Name",
Expand Down Expand Up @@ -278,11 +278,11 @@
},
"force_update": {
"name": "Force Update",
"description": "Force an update event when the state is written When not set or false, if the state value is unchanged, the update may not trigger an automation.\n"
"description": "Force an update event when the state is written When not set or false, if the state value is unchanged, the update may not trigger an automation."
},
"use_cache": {
"name": "Use Cache",
"description": "Use zigpy attribute cache to get the value of an attribute. (Does not send a zigbee packet to read the attribute)\n"
"description": "Use zigpy attribute cache to get the value of an attribute. (Does not send a zigbee packet to read the attribute)"
},
"event_success": {
"name": "Success Event Name",
Expand Down Expand Up @@ -352,7 +352,7 @@
},
"use_cache": {
"name": "Use Cache",
"description": "Use zigpy attribute cache to get the value of an attribute. (Does not send a zigbee packet to read the attribute)\n"
"description": "Use zigpy attribute cache to get the value of an attribute. (Does not send a zigbee packet to read the attribute)"
},
"tries": {
"name": "Tries",
Expand Down
6 changes: 3 additions & 3 deletions custom_components/zha_toolkit/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ def record_read_data(
attr_name = params[p.CSV_LABEL]
else:
python_type = type(read_resp[0][attr_id])
attr_type = f.DATA_TYPES.pytype_to_datatype_id(python_type)
attr_type = f.DataType.from_python_type(python_type).type_id

try:
attr_def = cluster.attributes.get(
Expand Down Expand Up @@ -690,7 +690,7 @@ def get_attr_type(cluster, attr_id):
else:
attr_type = attr_def[1]

return f.DATA_TYPES.pytype_to_datatype_id(attr_type)
return f.DataType.from_python_type(attr_type).type_id
except Exception: # nosec
LOGGER.debug("Could not find type for %s in %r", attr_id, cluster)

Expand Down Expand Up @@ -800,7 +800,7 @@ def attr_encode(attr_val_in, attr_type): # noqa C901
else:
# Try to apply conversion using foundation DATA_TYPES table
# Note: this is not perfect and specific conversions may be needed.
data_type = f.DATA_TYPES[attr_type][1]
data_type = f.DataType.from_type_id(attr_type).python_type
LOGGER.debug(f"Data type '{data_type}' for attr type {attr_type}")
if isinstance(attr_val_in, list):
# Without length byte after serialisation:
Expand Down
4 changes: 2 additions & 2 deletions custom_components/zha_toolkit/zcl_attr.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,9 @@ async def attr_write( # noqa: C901
# Try to get attribute type
if success and (attr_id in result_read[0]):
python_type = type(result_read[0][attr_id])
found_attr_type = f.DATA_TYPES.pytype_to_datatype_id(
found_attr_type = f.DataType.from_python_type(
python_type
)
).type_id
LOGGER.debug(
"Type determined from read: 0x%02x", found_attr_type
)
Expand Down
2 changes: 1 addition & 1 deletion hacs.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"filename": "zha-toolkit.zip",
"render_readme": true,
"persistent_directory": "local",
"homeassistant": "2024.8.0"
"homeassistant": "2024.9.0"
}
Loading