From 83f48c281e5d1da52e9cee8b848a11fd7f286211 Mon Sep 17 00:00:00 2001 From: Jeff Culverhouse Date: Tue, 27 Jan 2026 12:43:56 -0500 Subject: [PATCH] fix: use pattern matching for camera model validation Accept any suffix variant (B/W/E/EB/EW etc.) for supported camera models instead of requiring exact model strings. This allows cameras like IP4M-1041W (white) to match the IP4M-1041 base model pattern. Co-Authored-By: Claude Opus 4.5 --- src/amcrest2mqtt/mixins/amcrest.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/amcrest2mqtt/mixins/amcrest.py b/src/amcrest2mqtt/mixins/amcrest.py index ac7896e..a2e3a91 100644 --- a/src/amcrest2mqtt/mixins/amcrest.py +++ b/src/amcrest2mqtt/mixins/amcrest.py @@ -57,7 +57,8 @@ class AmcrestMixin: return "" def classify_device(self: Amcrest2Mqtt, device: dict) -> str: - if device["device_type"].upper() in [ + # Base model patterns - suffix variants (B/W/E/EB/EW etc.) are accepted + supported_base_models = [ "IPM-721", "IPM-HX1", "IP2M-841", @@ -65,19 +66,20 @@ class AmcrestMixin: "IP3M-941", "IP3M-943", "IP3M-956", - "IP3M-956E", "IP3M-HX2", - "IP4M-1026B", - "IP4M-1041B", - "IP4M-1051B", - "IP5M-1176EB", - "IP8M-2496EB", - "IP8M-T2499EW-28M", + "IP4M-1026", + "IP4M-1041", + "IP4M-1051", + "IP5M-1176", + "IP8M-2496", + "IP8M-T2499", "XVR DAHUA 5104S", - ]: + ] + device_type = device["device_type"].upper() + if any(device_type.startswith(model) for model in supported_base_models): return "camera" else: - self.logger.error(f"device you specified is not a supported model: {device["device_type"]}") + self.logger.error(f"device you specified is not a supported model: {device_type}") return "" async def build_camera(self: Amcrest2Mqtt, camera: dict) -> str: