Skip to content
Draft
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
1 change: 1 addition & 0 deletions custom_components/lock_code_manager/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"schedule",
"template",
"virtual",
"zha",
"zwave_js"
],
"codeowners": [
Expand Down
2 changes: 2 additions & 0 deletions custom_components/lock_code_manager/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@

from ._base import BaseLock
from .virtual import VirtualLock
from .zha import ZHALock
from .zwave_js import ZWaveJSLock

INTEGRATIONS_CLASS_MAP: dict[str, type[BaseLock]] = {
"virtual": VirtualLock,
"zha": ZHALock,
"zwave_js": ZWaveJSLock,
}
7 changes: 7 additions & 0 deletions custom_components/lock_code_manager/providers/zha/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""ZHA (Zigbee Home Automation) lock provider package."""

from __future__ import annotations

from .provider import ZHALock

__all__ = ["ZHALock"]
31 changes: 31 additions & 0 deletions custom_components/lock_code_manager/providers/zha/const.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"""Constants for ZHA (Zigbee Home Automation) lock provider.

Custom mappings specific to this provider. ZCL types come directly from zigpy.
"""

from __future__ import annotations

from zigpy.zcl.clusters.closures import DoorLock

# Map operation events to locked state (True = locked, False = unlocked)
OPERATION_TO_LOCKED: dict[DoorLock.OperationEvent, bool] = {
DoorLock.OperationEvent.Lock: True,
DoorLock.OperationEvent.KeyLock: True,
DoorLock.OperationEvent.AutoLock: True,
DoorLock.OperationEvent.Manual_Lock: True,
DoorLock.OperationEvent.ScheduleLock: True,
DoorLock.OperationEvent.OnTouchLock: True,
DoorLock.OperationEvent.Unlock: False,
DoorLock.OperationEvent.KeyUnlock: False,
DoorLock.OperationEvent.Manual_Unlock: False,
DoorLock.OperationEvent.ScheduleUnlock: False,
}

# Map operation source to human-readable name
OPERATION_SOURCE_NAMES: dict[DoorLock.OperationEventSource, str] = {
DoorLock.OperationEventSource.Keypad: "Keypad",
DoorLock.OperationEventSource.RF: "RF",
DoorLock.OperationEventSource.Manual: "Manual",
DoorLock.OperationEventSource.RFID: "RFID",
DoorLock.OperationEventSource.Indeterminate: "Unknown",
}
22 changes: 22 additions & 0 deletions custom_components/lock_code_manager/providers/zha/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""Helper functions for ZHA lock provider."""

from __future__ import annotations

from typing import Any

from homeassistant.components.zha.helpers import (
get_zha_gateway_proxy as _get_zha_gateway_proxy,
)
from homeassistant.core import HomeAssistant


def get_zha_gateway(hass: HomeAssistant) -> Any | None:
"""Get the ZHA gateway proxy.

Returns the gateway proxy from the ZHA integration's runtime data,
or None if ZHA is not loaded or has no gateway.
"""
try:
return _get_zha_gateway_proxy(hass)
except (KeyError, ValueError):
return None

Check warning on line 22 in custom_components/lock_code_manager/providers/zha/helpers.py

View check run for this annotation

Codecov / codecov/patch

custom_components/lock_code_manager/providers/zha/helpers.py#L21-L22

Added lines #L21 - L22 were not covered by tests
Loading
Loading