Add attribute-controlled siren entity for quirks v2#816
Draft
TheJulianJES wants to merge 1 commit into
Draft
Conversation
Add AttributeSiren, a siren entity that turns on/off by writing an enum attribute (e.g. a manufacturer-specific tone attribute) rather than issuing IAS WD start_warning commands. Its state is derived from the cached attribute value, so a device that resets the attribute on its own keeps the entity in sync. Only created from quirks v2 metadata; no default cluster match. Add the SIREN entity platform and move async_squawk from BaseSiren to BaseZclSiren, since it is specific to IAS WD sirens.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DRAFT / EXPERIMENTAL.
Companion to quirks PR zigpy/zha-device-handlers#5143 — that PR adds the
.siren()builder method + metadata + discovery wiring and applies it to four Heiman smoke/CO sensors. This PR adds the entity primitive those quirks rely on.Summary
Some devices sound a siren by writing an attribute (a tone value) rather than issuing IAS WD
start_warningcommands. Unlikestart_warning, this keeps sounding until it is turned off (or the device resets the attribute itself), and it can carry a tone selection — neither of which the existing IAS WD sirens can express.This adds
AttributeSiren, a generic siren controlled by writing an enum attribute:default_tone) to the attribute.off_value.TONESwhenavailable_tonesis provided.It is only instantiated from quirks v2 metadata (no
@register_entity, no cluster match) — the same pattern as the existingConfigurableAttributeSwitch/NumberConfigurationEntity/EnumSensor/ZCLEnumSelectEntityclasses.Changes
AttributeSiren(BaseSiren)inzha/application/platforms/siren.py— attribute-write siren described above.EntityPlatform.SIRENadded (zha/application/__init__.py) so quirks v2 metadata can target the siren platform.async_squawkmoved fromBaseSiren→BaseZclSiren. Squawk is an IAS WD command; it does not apply to an attribute siren. No callers exist outside the IAS WD sirens (checked zha + HA Core), so this is a safe refactor and letsAttributeSirensubclassBaseSirenwithout an inapplicable abstract method.test_siren.py:test_attribute_sirenbuilds a quirk device end-to-end (builder → metadata → discovery → entity) and checks: the IAS WD siren is suppressed and replaced with theAttributeSirenreusing itsunique_id;TURN_ON | TURN_OFF | TONES; tone selection writes the right value; and a device-driven report back to the off value flips the state off (the auto-reset case).Relationship to #667 / #668
This would likely replace the two earlier draft attempts at the same capability:
SwitchMetadata#667 — siren via reusingSwitchMetadata(.switch(entity_platform=EntityPlatform.SIREN)).ZCLEnumMetadata#668 — siren via reusingZCLEnumMetadata(.enum(entity_platform=EntityPlatform.SIREN); enum entry 0 = off, entry 1 = default tone, rest = tones). Motivated by the same device family (Add new features to Heiman HS1SA-E smoke alarm zha-device-handlers#4637, a smoke sensor that added a Stop/tone-A/tone-B select).Both need the same
EntityPlatform.SIRENaddition included here. The design difference: #816 introduces a dedicatedSirenMetadata+AttributeSirenand a.siren()builder method, whereas #667/#668 deliberately reuse the existing switch/enum metadata + entity plumbing. #668's write-up explicitly preferred reuse ("creating separateSirenMetadatawould confuse things more… reusing existingSwitchMetadataandZCLEnumMetadataworks well enough"), so this is a genuine design call to settle before any of the three leaves draft — the tradeoff is a purpose-built API/entity (explicit tones + off value, no unused switch "inverter" logic) vs. less new surface area. If #816 is preferred, #667 and #668 can be closed.Open question — should this live in ZHA or in quirks?
AttributeSirenis quirk-only, so an alternative is to define the entity class insidezha-device-handlers(subclassingBaseSiren) and keep onlyEntityPlatform.SIRENhere in ZHA.Argument for keeping it in ZHA (current form): it's exactly analogous to
ConfigurableAttributeSwitch,NumberConfigurationEntity,EnumSensorandZCLEnumSelectEntity— all of which areregister_entity=False/ no_cluster_match(i.e. never created by ZHA's own discovery, only by quirks metadata) yet live in ZHA. It's also generic (any "write a value to sound an alarm / pick a tone" device can use it), and the live-entity test harness only exists in ZHA's test suite. Flagging for a maintainer call before this leaves draft.Translations / strings
siren/strings.jsonand the frontendha-more-info-siren-advanced-controls.ts, which renders theavailable_tonesdict values raw). So the quirk supplies human-readable tone names ("Smoke siren"/"CO siren"), consistent with the existingAdvancedSirentones ("Burglar","Fire", …). Using a slug likeco_sirenwould render the literalco_sirenin the UI. If translated tone labels are wanted, the alternative is aselectentity (its options are slug-translated) instead of a siren — a different UX than requested here.translation_key="siren". HA'szhastrings.jsonhas noentity.sirenplatform section yet, so this would be the first siren-platform quirk key and will need adding on the next ZHA→HA strings bump (auto-added with"Siren"as the English name, per the usual process).Required HA Core change (siren tones)
HA Core's
ZHASirencurrently hardcodes the tone list to the IAS WD warning modes and ignores the entity'savailable_tones, so quirk-defined tones would not surface. The small change below makes it readavailable_tonesfrom the entity (and de-duplicates — the hardcoded list just mirroredAdvancedSiren's tones). It is not pushed yet; included here for review.HA Core diff (
homeassistant/components/zha/siren.py)Release ordering
Siren on/off + state work with just this PR + the quirks PR. Tone selection in the UI additionally needs the HA Core change above. The quirks PR depends on this one (imports
AttributeSiren/EntityPlatform.SIREN), so it can't merge/release first.