Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate opening sensor for _TZE200_pay2byax #3605

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

tr4nt0r
Copy link
Contributor

@tr4nt0r tr4nt0r commented Dec 12, 2024

Proposed change

image

This should fix the issue with duplicate opening sensor for Tuya _TZE200_pay2byax.

Tested only as a custom quirk, not the end result as only my production machine has a zigbee radio.

Additional information

"""Tuya temp and humidity sensors."""
from zigpy.quirks import DEVICE_REGISTRY
from zigpy.quirks.v2 import QuirkBuilder
from zigpy.quirks.v2.homeassistant.sensor import SensorDeviceClass, SensorStateClass
import zigpy.types as t
from zigpy.zcl.clusters.security import IasZone, ZoneType

from zhaquirks.tuya import TuyaLocalCluster
from zhaquirks.tuya.builder import TuyaQuirkBuilder

del DEVICE_REGISTRY._registry_v2[("_TZE200_pay2byax", "TS0601")]
del DEVICE_REGISTRY._registry_v2[("_TZE200_n8dljorx",  "TS0601")]

class TuyaIASContact(TuyaLocalCluster, IasZone):
    """Custom IasZone cluster that represents the Open/Closed sensor."""

    _CONSTANT_ATTRIBUTES = {
        IasZone.AttributeDefs.zone_type.id: ZoneType.Contact_Switch,
    }

class CustomTuyaQuirkBuilder(TuyaQuirkBuilder):
        
    def tuya_contact(
        self,
        dp_id: int,
        ias_cfg:  TuyaLocalCluster = TuyaIASContact,
    ) -> QuirkBuilder:
        """Add a Tuya contact switch configuration."""
        self.tuya_dp(
            dp_id,
            ias_cfg.ep_attribute,
            IasZone.AttributeDefs.zone_status.name,
        )
        self.adds(ias_cfg)
        return self

(
    CustomTuyaQuirkBuilder("_TZE200_pay2byax", "TS0601")
    .applies_to("_TZE200_n8dljorx",  "TS0601")
    .tuya_sensor(
        dp_id=101,
        attribute_name="measured_value",
        type=t.uint16_t,
        fallback_name="Illuminance",
        device_class=SensorDeviceClass.ILLUMINANCE,
        state_class=SensorStateClass.MEASUREMENT,
    )
    .tuya_contact(dp_id=1)
    .tuya_battery(dp_id=2)
    .skip_configuration()
    .add_to_registry()
)

Fixes: home-assistant/core#132669

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

Copy link

codecov bot commented Dec 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.85%. Comparing base (979551d) to head (0215b0f).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #3605      +/-   ##
==========================================
- Coverage   89.85%   89.85%   -0.01%     
==========================================
  Files         321      321              
  Lines       10374    10372       -2     
==========================================
- Hits         9322     9320       -2     
  Misses       1052     1052              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@tr4nt0r tr4nt0r changed the title Fix diplicate opening sensor in _TZE200_pay2byax Fix duplicate opening sensor in _TZE200_pay2byax Dec 12, 2024
@TheJulianJES TheJulianJES added Tuya Request/PR regarding a Tuya device bugfix This PR fixes a bug needs review This PR should be reviewed soon, as it generally looks good. labels Dec 12, 2024
@TheJulianJES
Copy link
Collaborator

We've split out the tuya_ias method into tuya_smoke and tuya_contact in #3608. Mind rebasing this PR?
I think you should just need to replace the v2 contact entity with tuya_contact now.

@tr4nt0r tr4nt0r force-pushed the fix_duplicate_sensors branch from b4a009e to 0215b0f Compare December 13, 2024 11:41
@tr4nt0r
Copy link
Contributor Author

tr4nt0r commented Dec 13, 2024

@TheJulianJES done 👍🏼

@TheJulianJES TheJulianJES changed the title Fix duplicate opening sensor in _TZE200_pay2byax Fix duplicate opening sensor for _TZE200_pay2byax Dec 13, 2024
@TheJulianJES TheJulianJES removed the needs review This PR should be reviewed soon, as it generally looks good. label Dec 13, 2024
Copy link
Collaborator

@TheJulianJES TheJulianJES left a comment

Choose a reason for hiding this comment

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

Thanks!

@TheJulianJES TheJulianJES added the ready PR should be ready to merge label Dec 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This PR fixes a bug ready PR should be ready to merge Tuya Request/PR regarding a Tuya device
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ZHA: After upgrade to 2412.1 (skipped .0) some ZHA entities duplicates and some not working
2 participants