Skip to content

feat(sunricher): add quirk for SR-ZG9032A-PIR#4878

Open
niracler wants to merge 2 commits intozigpy:devfrom
niracler:feat/sunricher-sr-zg9032a-pir
Open

feat(sunricher): add quirk for SR-ZG9032A-PIR#4878
niracler wants to merge 2 commits intozigpy:devfrom
niracler:feat/sunricher-sr-zg9032a-pir

Conversation

@niracler
Copy link
Copy Markdown

Proposed change

Add quirk for Sunricher SR-ZG9032A-PIR (HK-DIM-PIR).

Exposes 4 manufacturer-specific config attributes on genBasic that require manufacturer code 0x1224:

  • Daylight sensor lux threshold (0x8903)
  • Motion sensor sensitivity (0x8905)
  • PWM output percentage (0x8909)
  • Linearity error ratio coefficient (0x890D)

Additional information

Z2M converter reference: Koenkk/zigbee-herdsman-converters#11723

Device diagnostics

sr_zg9032a_pir_diagnostics.json

Checklist

  • The changes are tested and work correctly
  • pre-commit checks pass / the code has been formatted using Black
  • Tests have been added to verify that the new code works
  • Device diagnostics data has been attached

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
Copy link
Copy Markdown

codecov Bot commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.08%. Comparing base (380135d) to head (7e0e3f1).
⚠️ Report is 21 commits behind head on dev.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Basic cluster subclass defining 4 manufacturer-specific attributes using manufacturer code 0x1224.
  • Registers a v2 QuirkBuilder for ("Sunricher", "HK-DIM-PIR") and exposes those attributes as configurable number entities.

Comment on lines +72 to +74
max_value=254,
unit="%",
entity_type=EntityType.CONFIG,
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 7e0e3f1.

Comment thread zhaquirks/sunricher/sr_zg9032a_pir.py Outdated
Comment on lines +73 to +76
unit="%",
entity_type=EntityType.CONFIG,
translation_key="pwm_output_percentage",
fallback_name="PWM output percentage",
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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”.

Suggested change
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",

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 7e0e3f1.

Comment thread zhaquirks/sunricher/sr_zg9032a_pir.py Outdated
Comment on lines +36 to +40
linearity_error_ratio_lux: Final = ZCLAttributeDef(
id=0x890D,
type=t.uint16_t,
manufacturer_code=SUNRICHER_MANUFACTURER_CODE,
)
Copy link

Copilot AI Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 7e0e3f1.

- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants