Skip to content

Commit

Permalink
Replace custom validator from zwave_js with from_dict funcs (#120279)
Browse files Browse the repository at this point in the history
  • Loading branch information
raman325 authored Jun 24, 2024
1 parent fdade67 commit 6a5c1fc
Showing 1 changed file with 2 additions and 61 deletions.
63 changes: 2 additions & 61 deletions homeassistant/components/zwave_js/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,65 +166,6 @@
MINIMUM_QR_STRING_LENGTH = 52


def convert_planned_provisioning_entry(info: dict) -> ProvisioningEntry:
"""Handle provisioning entry dict to ProvisioningEntry."""
return ProvisioningEntry(
dsk=info[DSK],
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, STATUS, REQUESTED_SECURITY_CLASSES)
},
)


def convert_qr_provisioning_information(info: dict) -> QRProvisioningInformation:
"""Convert QR provisioning information dict to QRProvisioningInformation."""
## Remove this when we have fix for QRProvisioningInformation.from_dict()
return QRProvisioningInformation(
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],
installer_icon_type=info[INSTALLER_ICON_TYPE],
manufacturer_id=info[MANUFACTURER_ID],
product_type=info[PRODUCT_TYPE],
product_id=info[PRODUCT_ID],
application_version=info[APPLICATION_VERSION],
max_inclusion_request_interval=info.get(MAX_INCLUSION_REQUEST_INTERVAL),
uuid=info.get(UUID),
supported_protocols=info.get(SUPPORTED_PROTOCOLS),
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 (
VERSION,
SECURITY_CLASSES,
DSK,
GENERIC_DEVICE_CLASS,
SPECIFIC_DEVICE_CLASS,
INSTALLER_ICON_TYPE,
MANUFACTURER_ID,
PRODUCT_TYPE,
PRODUCT_ID,
APPLICATION_VERSION,
MAX_INCLUSION_REQUEST_INTERVAL,
UUID,
SUPPORTED_PROTOCOLS,
STATUS,
REQUESTED_SECURITY_CLASSES,
)
},
)


# Helper schemas
PLANNED_PROVISIONING_ENTRY_SCHEMA = vol.All(
vol.Schema(
Expand All @@ -244,7 +185,7 @@ def convert_qr_provisioning_information(info: dict) -> QRProvisioningInformation
# Provisioning entries can have extra keys for SmartStart
extra=vol.ALLOW_EXTRA,
),
convert_planned_provisioning_entry,
ProvisioningEntry.from_dict,
)

QR_PROVISIONING_INFORMATION_SCHEMA = vol.All(
Expand Down Expand Up @@ -278,7 +219,7 @@ def convert_qr_provisioning_information(info: dict) -> QRProvisioningInformation
},
extra=vol.ALLOW_EXTRA,
),
convert_qr_provisioning_information,
QRProvisioningInformation.from_dict,
)

QR_CODE_STRING_SCHEMA = vol.All(str, vol.Length(min=MINIMUM_QR_STRING_LENGTH))
Expand Down

0 comments on commit 6a5c1fc

Please sign in to comment.