Fix zwave_js add node schemas (#73343)
* Fix zwave_js add node schemas * Code cleanup * Add test
This commit is contained in:
parent
b1f2e5f897
commit
63b51f566d
2 changed files with 90 additions and 12 deletions
|
@ -14,6 +14,7 @@ from zwave_js_server.const import (
|
|||
InclusionStrategy,
|
||||
LogLevel,
|
||||
Protocols,
|
||||
ProvisioningEntryStatus,
|
||||
QRCodeVersion,
|
||||
SecurityClass,
|
||||
ZwaveFeature,
|
||||
|
@ -148,6 +149,8 @@ MAX_INCLUSION_REQUEST_INTERVAL = "max_inclusion_request_interval"
|
|||
UUID = "uuid"
|
||||
SUPPORTED_PROTOCOLS = "supported_protocols"
|
||||
ADDITIONAL_PROPERTIES = "additional_properties"
|
||||
STATUS = "status"
|
||||
REQUESTED_SECURITY_CLASSES = "requested_security_classes"
|
||||
|
||||
FEATURE = "feature"
|
||||
UNPROVISION = "unprovision"
|
||||
|
@ -160,19 +163,22 @@ def convert_planned_provisioning_entry(info: dict) -> ProvisioningEntry:
|
|||
"""Handle provisioning entry dict to ProvisioningEntry."""
|
||||
return ProvisioningEntry(
|
||||
dsk=info[DSK],
|
||||
security_classes=[SecurityClass(sec_cls) for sec_cls in info[SECURITY_CLASSES]],
|
||||
security_classes=info[SECURITY_CLASSES],
|
||||
status=info[STATUS],
|
||||
requested_security_classes=info.get(REQUESTED_SECURITY_CLASSES),
|
||||
additional_properties={
|
||||
k: v for k, v in info.items() if k not in (DSK, SECURITY_CLASSES)
|
||||
k: v
|
||||
for k, v in info.items()
|
||||
if k not in (DSK, SECURITY_CLASSES, STATUS, REQUESTED_SECURITY_CLASSES)
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
def convert_qr_provisioning_information(info: dict) -> QRProvisioningInformation:
|
||||
"""Convert QR provisioning information dict to QRProvisioningInformation."""
|
||||
protocols = [Protocols(proto) for proto in info.get(SUPPORTED_PROTOCOLS, [])]
|
||||
return QRProvisioningInformation(
|
||||
version=QRCodeVersion(info[VERSION]),
|
||||
security_classes=[SecurityClass(sec_cls) for sec_cls in info[SECURITY_CLASSES]],
|
||||
version=info[VERSION],
|
||||
security_classes=info[SECURITY_CLASSES],
|
||||
dsk=info[DSK],
|
||||
generic_device_class=info[GENERIC_DEVICE_CLASS],
|
||||
specific_device_class=info[SPECIFIC_DEVICE_CLASS],
|
||||
|
@ -183,7 +189,9 @@ def convert_qr_provisioning_information(info: dict) -> QRProvisioningInformation
|
|||
application_version=info[APPLICATION_VERSION],
|
||||
max_inclusion_request_interval=info.get(MAX_INCLUSION_REQUEST_INTERVAL),
|
||||
uuid=info.get(UUID),
|
||||
supported_protocols=protocols if protocols else None,
|
||||
supported_protocols=info.get(SUPPORTED_PROTOCOLS),
|
||||
status=info[STATUS],
|
||||
requested_security_classes=info.get(REQUESTED_SECURITY_CLASSES),
|
||||
additional_properties=info.get(ADDITIONAL_PROPERTIES, {}),
|
||||
)
|
||||
|
||||
|
@ -197,6 +205,12 @@ PLANNED_PROVISIONING_ENTRY_SCHEMA = vol.All(
|
|||
cv.ensure_list,
|
||||
[vol.Coerce(SecurityClass)],
|
||||
),
|
||||
vol.Optional(STATUS, default=ProvisioningEntryStatus.ACTIVE): vol.Coerce(
|
||||
ProvisioningEntryStatus
|
||||
),
|
||||
vol.Optional(REQUESTED_SECURITY_CLASSES): vol.All(
|
||||
cv.ensure_list, [vol.Coerce(SecurityClass)]
|
||||
),
|
||||
},
|
||||
# Provisioning entries can have extra keys for SmartStart
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
|
@ -226,6 +240,12 @@ QR_PROVISIONING_INFORMATION_SCHEMA = vol.All(
|
|||
cv.ensure_list,
|
||||
[vol.Coerce(Protocols)],
|
||||
),
|
||||
vol.Optional(STATUS, default=ProvisioningEntryStatus.ACTIVE): vol.Coerce(
|
||||
ProvisioningEntryStatus
|
||||
),
|
||||
vol.Optional(REQUESTED_SECURITY_CLASSES): vol.All(
|
||||
cv.ensure_list, [vol.Coerce(SecurityClass)]
|
||||
),
|
||||
vol.Optional(ADDITIONAL_PROPERTIES): dict,
|
||||
}
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue