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

Add Tuya single button switch TS004F _TZ3000_ja5osu5g #3153

Merged
merged 4 commits into from
May 28, 2024

Conversation

CRCinAU
Copy link
Contributor

@CRCinAU CRCinAU commented May 14, 2024

Existing signature before quirk:

{
  "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4742, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)",
  "endpoints": {
    "1": {
      "profile_id": "0x0104",
      "device_type": "0x0000",
      "input_clusters": [
        "0x0000",
        "0x0001",
        "0x0003",
        "0x0004",
        "0x0006",
        "0x1000",
        "0xe001"
      ],
      "output_clusters": [
        "0x0003",
        "0x0004",
        "0x0006",
        "0x0008",
        "0x000a",
        "0x0019",
        "0x1000"
      ]
    }
  },
  "manufacturer": "_TZ3000_ja5osu5g",
  "model": "TS004F",
  "class": "zigpy.device.Device"
}

Signature after quirk:

{
  "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4742, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)",
  "endpoints": {
    "1": {
      "profile_id": "0x0104",
      "device_type": "0x0820",
      "input_clusters": [
        "0x0000",
        "0x0001",
        "0x0003",
        "0x0004",
        "0x1000",
        "0xe001"
      ],
      "output_clusters": [
        "0x0003",
        "0x0004",
        "0x0006",
        "0x0008",
        "0x000a",
        "0x0019",
        "0x0300",
        "0x1000"
      ]
    }
  },
  "manufacturer": "_TZ3000_ja5osu5g",
  "model": "TS004F",
  "class": "ts004f.TuyaSmartRemote004FSK_v2"
}

Tested in HA, and HA correctly receives button presses now:
image

Fixes #2212

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

Existing signature before quirk:
{
  "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4742, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)",
  "endpoints": {
    "1": {
      "profile_id": "0x0104",
      "device_type": "0x0000",
      "input_clusters": [
        "0x0000",
        "0x0001",
        "0x0003",
        "0x0004",
        "0x0006",
        "0x1000",
        "0xe001"
      ],
      "output_clusters": [
        "0x0003",
        "0x0004",
        "0x0006",
        "0x0008",
        "0x000a",
        "0x0019",
        "0x1000"
      ]
    }
  },
  "manufacturer": "_TZ3000_ja5osu5g",
  "model": "TS004F",
  "class": "zigpy.device.Device"
}

Signature after quirk:
{
  "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.EndDevice: 2>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress: 128>, manufacturer_code=4742, maximum_buffer_size=66, maximum_incoming_transfer_size=66, server_mask=10752, maximum_outgoing_transfer_size=66, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=True, *is_full_function_device=False, *is_mains_powered=False, *is_receiver_on_when_idle=False, *is_router=False, *is_security_capable=False)",
  "endpoints": {
    "1": {
      "profile_id": "0x0104",
      "device_type": "0x0820",
      "input_clusters": [
        "0x0000",
        "0x0001",
        "0x0003",
        "0x0004",
        "0x1000",
        "0xe001"
      ],
      "output_clusters": [
        "0x0003",
        "0x0004",
        "0x0006",
        "0x0008",
        "0x000a",
        "0x0019",
        "0x0300",
        "0x1000"
      ]
    }
  },
  "manufacturer": "_TZ3000_ja5osu5g",
  "model": "TS004F",
  "class": "ts004f.TuyaSmartRemote004FSK_v2"
}
Copy link

codecov bot commented May 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.14%. Comparing base (21dd8eb) to head (50c309f).

Additional details and impacted files
@@           Coverage Diff           @@
##              dev    #3153   +/-   ##
=======================================
  Coverage   88.14%   88.14%           
=======================================
  Files         299      299           
  Lines        9389     9391    +2     
=======================================
+ Hits         8276     8278    +2     
  Misses       1113     1113           

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

@MattWestb
Copy link
Contributor

Great you was getting it working and doing on PR !!!
Interesting is if the first version is working for the same "manufacturer" was working or if tuya have doing one new firmware version with the (crazy) change.

Naming of the class naming and reusing the old class DA is up to the maintainers but for me its looks OK !!

@MattWestb
Copy link
Contributor

PS: add in the first post for linking the issue:
Fixes #2212

@TheJulianJES TheJulianJES added the Tuya Request/PR regarding a Tuya device label May 15, 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 for the PR!
There are some minor changes that could be made to clean this up slightly.

zhaquirks/tuya/ts004f.py Outdated Show resolved Hide resolved
zhaquirks/tuya/ts004f.py Outdated Show resolved Hide resolved
zhaquirks/tuya/ts004f.py Outdated Show resolved Hide resolved
zhaquirks/tuya/ts004f.py Outdated Show resolved Hide resolved
@TheJulianJES TheJulianJES changed the title Add support for a Tuya based single button switch: _TZ3000_ja5osu5g Add Tuya single button switch TS004F _TZ3000_ja5osu5g May 24, 2024
@CRCinAU
Copy link
Contributor Author

CRCinAU commented May 25, 2024

Thanks for the PR! There are some minor changes that could be made to clean this up slightly.

Thanks - I had no idea exactly what I was doing with this, just what I managed to get working... I was hoping that someone with more of a clue could optimise it :)

I think I've done what you've asked properly - if you could please give it your eyeballs again and confirm.

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.

Looks good to me. Thanks!

@TheJulianJES TheJulianJES added the smash This PR is close to be merged soon label May 27, 2024
@TheJulianJES TheJulianJES merged commit 6f5a939 into zigpy:dev May 28, 2024
6 checks passed
@AnalogThinker
Copy link

Not sure if it's a quirk implementation issue, but the TS004F by _TZ3000_ja5osu5g (Single Button) seems to have issues interpreting data.
Behaviour : Button keeps switching back to "on" by itself after a while.

Although the commands are pretty straight forward for toggle, on and off:

[zigpy.zcl] [0xA502:1:0x0006] Decoded ZCL frame: OnOff:toggle()
[zigpy.zcl] [0xA502:1:0x0006] Received command 0x02 (TSN 90): toggle()

[zigpy.zcl] [0x5CAF:1:0x0006] Received ZCL frame: b'\x11\xcd\x01'
[zigpy.zcl] [0x5CAF:1:0x0006] Decoded ZCL frame: OnOff:on()
[zigpy.zcl] [0x5CAF:1:0x0006] Received command 0x01 (TSN 205): on()

[zigpy.zcl] [0xF0EA:1:0x0006] Received ZCL frame: b'\x11\x1f\x00'
[zigpy.zcl] [0xF0EA:1:0x0006] Decoded ZCL frame: OnOff:off()
[zigpy.zcl] [0xF0EA:1:0x0006] Received command 0x00 (TSN 31): off()

the switch would trigger back on by itself upon receiving this one (note Bool.true:1) with no user interaction:

[zigpy.zcl] [0x4D62:1:0x0006] Received ZCL frame: b'\x18!\n\x00\x00\x10\x01'
[zigpy.zcl] [0x4D62:1:0x0006] Decoded ZCL frame header: ZCLHeader(frame_control=FrameControl<0x18>(frame_type=<FrameType.GLOBAL_COMMAND: 0>, is_manufacturer_specific=0, direction=<Direction.Server_to_Client: 1>, disable_default_response=1, reserved=0, *is_cluster=False, *is_general=True), tsn=33, command_id=10, *direction=<Direction.Server_to_Client: 1>)
[zigpy.zcl] [0x4D62:1:0x0006] Decoded ZCL frame: OnOff:Report_Attributes(attribute_reports=[Attribute(attrid=0x0000, value=TypeValue(type=Bool, value=<Bool.true: 1>))])
[zigpy.zcl] [0x4D62:1:0x0006] Received command 0x0A (TSN 33): Report_Attributes(attribute_reports=[Attribute(attrid=0x0000, value=TypeValue(type=Bool, value=<Bool.true: 1>))])
[zigpy.zcl] [0x4D62:1:0x0006] Attribute report received: on_off=<Bool.true: 1>

@CRCinAU
Copy link
Contributor Author

CRCinAU commented Jun 4, 2024

Not sure if it's a quirk implementation issue, but the TS004F by _TZ3000_ja5osu5g (Single Button) seems to have issues interpreting data. Behaviour : Button keeps switching back to "on" by itself after a while.

Although the commands are pretty straight forward for toggle, on and off:

If you hold the button down for ~3-4 seconds, it should change modes and work properly.

@MattWestb
Copy link
Contributor

@AnalogThinker Pleas post the diagnostic from the device card so can see with quirk (if) its using.

@AnalogThinker
Copy link

AnalogThinker commented Jun 4, 2024

Sure thing.
I have pulled 2 diags :

@MattWestb
Copy link
Contributor

MattWestb commented Jun 4, 2024

The second one shall working "normal" then its have loading the the quirk for one switch.
The first one have: "quirk_class": "zigpy.device.Device", so light commands shall working but "tuya scene" commands not util you is getting one working quirk loaded for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
smash This PR is close to be merged soon Tuya Request/PR regarding a Tuya device
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants