feat(sunricher): add quirk for SR-ZG9032A-PIR#4878
feat(sunricher): add quirk for SR-ZG9032A-PIR#4878
Conversation
Add ZHA V2 quirk for Sunricher SR-ZG9032A-PIR (HK-DIM-PIR) motion sensor with custom Basic cluster exposing manufacturer-specific attributes that require manufacturer code 0x1224 for read/write operations. Exposed attributes: - motion_sensor_lux_threshold (0x8903) - motion_sensor_sensitivity (0x8905) - pwm_output_percentage (0x8909) - linearity_error_ratio_lux (0x890D)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #4878 +/- ##
==========================================
+ Coverage 93.04% 93.08% +0.03%
==========================================
Files 397 402 +5
Lines 13248 13321 +73
==========================================
+ Hits 12327 12400 +73
Misses 921 921 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a new ZHA quirk for the Sunricher SR-ZG9032A-PIR (HK-DIM-PIR) device by exposing several manufacturer-specific configuration attributes (under genBasic) as Home Assistant config number entities.
Changes:
- Introduces a custom
Basiccluster subclass defining 4 manufacturer-specific attributes using manufacturer code0x1224. - Registers a v2
QuirkBuilderfor("Sunricher", "HK-DIM-PIR")and exposes those attributes as configurablenumberentities.
| max_value=254, | ||
| unit="%", | ||
| entity_type=EntityType.CONFIG, |
There was a problem hiding this comment.
unit should use the shared PERCENTAGE constant (from zigpy.quirks.v2.homeassistant) rather than a raw string. This is the convention used elsewhere in the codebase and avoids unit inconsistencies across HA entities.
| unit="%", | ||
| entity_type=EntityType.CONFIG, | ||
| translation_key="pwm_output_percentage", | ||
| fallback_name="PWM output percentage", |
There was a problem hiding this comment.
This entity is labeled as a percentage but uses a 0..254 range (Zigbee level-style). Either scale the exposed value to 0..100 (using the builder’s scaling options) or rename the entity/translation key to reflect that it’s a raw level value so the HA UI doesn’t present values >100% as “percent”.
| unit="%", | |
| entity_type=EntityType.CONFIG, | |
| translation_key="pwm_output_percentage", | |
| fallback_name="PWM output percentage", | |
| entity_type=EntityType.CONFIG, | |
| translation_key="pwm_output_level", | |
| fallback_name="PWM output level", |
| linearity_error_ratio_lux: Final = ZCLAttributeDef( | ||
| id=0x890D, | ||
| type=t.uint16_t, | ||
| manufacturer_code=SUNRICHER_MANUFACTURER_CODE, | ||
| ) |
There was a problem hiding this comment.
The attribute name linearity_error_ratio_lux (and later translation_key) suggests this value is in lux, but the entity fallback name describes it as a coefficient. Align the attribute/translation key naming with what the value actually represents to avoid confusing entity naming and future maintenance mistakes.
- Rename pwm_output_percentage → pwm_output_level and drop "%" unit. Per device documentation, value is raw 0-254 (where 254 = 100%); the manufacturer's BLE app exposes this attribute as a raw level too. - Rename linearity_error_ratio_lux → linearity_error_ratio. Value is a dimensionless coefficient (per-mille, default 1000 = 100%) applied to lux measurement; the _lux suffix misled toward a unit.
Proposed change
Add quirk for Sunricher SR-ZG9032A-PIR (
HK-DIM-PIR).Exposes 4 manufacturer-specific config attributes on
genBasicthat require manufacturer code0x1224:0x8903)0x8905)0x8909)0x890D)Additional information
Z2M converter reference: Koenkk/zigbee-herdsman-converters#11723
Device diagnostics
sr_zg9032a_pir_diagnostics.json
Checklist
pre-commitchecks pass / the code has been formatted using Black