Tweaking a ZHA quirk

I have two zigbee smart plugs, the second arrived today and is slightly different to the first.
The first worked immediately without need for a local quirk, but did have a quirk listed:-

zhaquirks.tuya.ts011f_plug.Plug

The second plug, although physically different, is reported in HA as a ts011f but has no quirk listed, and some of the controls are not showing up such as the power on restart state. (The first plug does show this), and the power metering does not work correctly.

I found this quirk which seems to have my device listed:-

(See line 585)

But it seems to think its a 2AC plug (mine is a single), and I think whilst the input clusters are correct, they are in the wrong order, and mine has no output clusters at all, according to the device debug:-

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2022.12.0",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.10.7",
    "docker": true,
    "arch": "x86_64",
    "timezone": "Europe/London",
    "os_name": "Linux",
    "os_version": "5.15.74",
    "supervisor": "2022.11.2",
    "host_os": "Home Assistant OS 9.3",
    "docker_version": "20.10.18",
    "chassis": "vm",
    "run_as_root": true
  },
  "custom_components": {
    "hildebrandglow_dcc": {
      "version": "0.6.0",
      "requirements": []
    },
    "average": {
      "version": "2.3.0",
      "requirements": []
    },
    "whatspie": {
      "version": "1.0.0",
      "requirements": []
    },
    "dwains_dashboard": {
      "version": "3.3.0",
      "requirements": []
    },
    "hacs": {
      "version": "1.28.3",
      "requirements": [
        "aiogithubapi>=22.2.4"
      ]
    },
    "edf": {
      "version": "1.0.0",
      "requirements": [
        "edf-api>=1.0.0",
        "python-dateutil"
      ]
    }
  },
  "integration_manifest": {
    "domain": "zha",
    "name": "Zigbee Home Automation",
    "config_flow": true,
    "documentation": "https://www.home-assistant.io/integrations/zha",
    "requirements": [
      "bellows==0.34.5",
      "pyserial==3.5",
      "pyserial-asyncio==0.6",
      "zha-quirks==0.0.88",
      "zigpy-deconz==0.19.2",
      "zigpy==0.52.3",
      "zigpy-xbee==0.16.2",
      "zigpy-zigate==0.10.3",
      "zigpy-znp==0.9.2"
    ],
    "usb": [
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*2652*",
        "known_devices": [
          "slae.sh cc2652rb stick"
        ]
      },
      {
        "vid": "1A86",
        "pid": "55D4",
        "description": "*sonoff*plus*",
        "known_devices": [
          "sonoff zigbee dongle plus v2"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*sonoff*plus*",
        "known_devices": [
          "sonoff zigbee dongle plus"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*tubeszb*",
        "known_devices": [
          "TubesZB Coordinator"
        ]
      },
      {
        "vid": "1A86",
        "pid": "7523",
        "description": "*tubeszb*",
        "known_devices": [
          "TubesZB Coordinator"
        ]
      },
      {
        "vid": "1A86",
        "pid": "7523",
        "description": "*zigstar*",
        "known_devices": [
          "ZigStar Coordinators"
        ]
      },
      {
        "vid": "1CF1",
        "pid": "0030",
        "description": "*conbee*",
        "known_devices": [
          "Conbee II"
        ]
      },
      {
        "vid": "10C4",
        "pid": "8A2A",
        "description": "*zigbee*",
        "known_devices": [
          "Nortek HUSBZB-1"
        ]
      },
      {
        "vid": "0403",
        "pid": "6015",
        "description": "*zigate*",
        "known_devices": [
          "ZiGate+"
        ]
      },
      {
        "vid": "10C4",
        "pid": "EA60",
        "description": "*zigate*",
        "known_devices": [
          "ZiGate"
        ]
      },
      {
        "vid": "10C4",
        "pid": "8B34",
        "description": "*bv 2010/10*",
        "known_devices": [
          "Bitron Video AV2010/10"
        ]
      }
    ],
    "codeowners": [
      "@dmulcahey",
      "@adminiuga",
      "@puddly"
    ],
    "zeroconf": [
      {
        "type": "_esphomelib._tcp.local.",
        "name": "tube*"
      },
      {
        "type": "_zigate-zigbee-gateway._tcp.local.",
        "name": "*zigate*"
      },
      {
        "type": "_zigstar_gw._tcp.local.",
        "name": "*zigstar*"
      }
    ],
    "dependencies": [
      "file_upload"
    ],
    "after_dependencies": [
      "onboarding",
      "usb",
      "zeroconf"
    ],
    "iot_class": "local_polling",
    "loggers": [
      "aiosqlite",
      "bellows",
      "crccheck",
      "pure_pcapy3",
      "zhaquirks",
      "zigpy",
      "zigpy_deconz",
      "zigpy_xbee",
      "zigpy_zigate",
      "zigpy_znp"
    ],
    "is_built_in": true
  },
  "data": {
    "ieee": "**REDACTED**",
    "nwk": 63803,
    "manufacturer": "_TZ3000_okaz9tjs",
    "model": "TS011F",
    "name": "_TZ3000_okaz9tjs TS011F",
    "quirk_applied": false,
    "quirk_class": "zigpy.device.Device",
    "manufacturer_code": 4660,
    "power_source": "Mains",
    "lqi": 204,
    "rssi": -49,
    "last_seen": "2022-12-08T20:07:54",
    "available": true,
    "device_type": "Router",
    "signature": {
      "node_descriptor": "NodeDescriptor(logical_type=<LogicalType.Router: 1>, complex_descriptor_available=0, user_descriptor_available=0, reserved=0, aps_flags=0, frequency_band=<FrequencyBand.Freq2400MHz: 8>, mac_capability_flags=<MACCapabilityFlags.AllocateAddress|RxOnWhenIdle|MainsPowered|FullFunctionDevice: 142>, manufacturer_code=4660, maximum_buffer_size=108, maximum_incoming_transfer_size=0, server_mask=11264, maximum_outgoing_transfer_size=0, descriptor_capability_field=<DescriptorCapability.NONE: 0>, *allocate_address=True, *is_alternate_pan_coordinator=False, *is_coordinator=False, *is_end_device=False, *is_full_function_device=True, *is_mains_powered=True, *is_receiver_on_when_idle=True, *is_router=True, *is_security_capable=False)",
      "endpoints": {
        "1": {
          "profile_id": 260,
          "device_type": "0x0051",
          "in_clusters": [
            "0x0000",
            "0x0003",
            "0x0004",
            "0x0005",
            "0x0006",
            "0x0702",
            "0x0b04",
            "0xe001"
          ],
          "out_clusters": []
        }
      }
    },
    "active_coordinator": false,
    "entities": [
      {
        "entity_id": "button.tz3000_okaz9tjs_ts011f_identify",
        "name": "_TZ3000_okaz9tjs TS011F"
      },
      {
        "entity_id": "sensor.tz3000_okaz9tjs_ts011f_active_power",
        "name": "_TZ3000_okaz9tjs TS011F"
      },
      {
        "entity_id": "sensor.tz3000_okaz9tjs_ts011f_rms_current",
        "name": "_TZ3000_okaz9tjs TS011F"
      },
      {
        "entity_id": "sensor.tz3000_okaz9tjs_ts011f_rms_voltage",
        "name": "_TZ3000_okaz9tjs TS011F"
      },
      {
        "entity_id": "sensor.tz3000_okaz9tjs_ts011f_power_factor",
        "name": "_TZ3000_okaz9tjs TS011F"
      },
      {
        "entity_id": "sensor.tz3000_okaz9tjs_ts011f_summation_delivered",
        "name": "_TZ3000_okaz9tjs TS011F"
      },
      {
        "entity_id": "switch.tz3000_okaz9tjs_ts011f_switch",
        "name": "_TZ3000_okaz9tjs TS011F"
      }
    ],
    "neighbors": [],
    "routes": [],
    "endpoint_names": [
      {
        "name": "SMART_PLUG"
      }
    ],
    "user_given_name": "Ajax Plug TV",
    "device_reg_id": "81d7c42a428f504254674954c2d12dd4",
    "area_id": null,
    "cluster_details": {
      "1": {
        "device_type": {
          "name": "SMART_PLUG",
          "id": 81
        },
        "profile_id": 260,
        "in_clusters": {
          "0x0000": {
            "endpoint_attribute": "basic",
            "attributes": {
              "0x0001": {
                "attribute_name": "app_version",
                "value": 160
              },
              "0x0004": {
                "attribute_name": "manufacturer",
                "value": "_TZ3000_okaz9tjs"
              },
              "0x0005": {
                "attribute_name": "model",
                "value": "TS011F"
              }
            },
            "unsupported_attributes": {}
          },
          "0x0006": {
            "endpoint_attribute": "on_off",
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0x0003": {
            "endpoint_attribute": "identify",
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0x0004": {
            "endpoint_attribute": "groups",
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0x0005": {
            "endpoint_attribute": "scenes",
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0xe001": {
            "endpoint_attribute": null,
            "attributes": {},
            "unsupported_attributes": {}
          },
          "0x0b04": {
            "endpoint_attribute": "electrical_measurement",
            "attributes": {
              "0x0505": {
                "attribute_name": "rms_voltage",
                "value": 235
              },
              "0x0508": {
                "attribute_name": "rms_current",
                "value": 0
              },
              "0x050b": {
                "attribute_name": "active_power",
                "value": 0
              }
            },
            "unsupported_attributes": {
              "0x0300": {
                "attribute_name": "ac_frequency"
              },
              "0x0601": {
                "attribute_name": "ac_voltage_divisor"
              },
              "0x0302": {
                "attribute_name": "ac_frequency_max"
              },
              "0x0603": {
                "attribute_name": "ac_current_divisor"
              },
              "0x0602": {
                "attribute_name": "ac_current_multiplier"
              },
              "0x0605": {
                "attribute_name": "ac_power_divisor"
              },
              "0x0604": {
                "attribute_name": "ac_power_multiplier"
              },
              "0x0507": {
                "attribute_name": "rms_voltage_max"
              },
              "0x0600": {
                "attribute_name": "ac_voltage_multiplier"
              },
              "0x0401": {
                "attribute_name": "ac_frequency_divisor"
              },
              "0x050a": {
                "attribute_name": "rms_current_max"
              },
              "0x0000": {
                "attribute_name": "measurement_type"
              },
              "0x0403": {
                "attribute_name": "power_divisor"
              },
              "0x050d": {
                "attribute_name": "active_power_max"
              },
              "0x050f": {
                "attribute_name": "apparent_power"
              },
              "0x0400": {
                "attribute_name": "ac_frequency_multiplier"
              },
              "0x0402": {
                "attribute_name": "power_multiplier"
              }
            }
          },
          "0x0702": {
            "endpoint_attribute": "smartenergy_metering",
            "attributes": {
              "0x0000": {
                "attribute_name": "current_summ_delivered",
                "value": 4294967306
              }
            },
            "unsupported_attributes": {
              "0x0400": {
                "attribute_name": "instantaneous_demand"
              },
              "0x0200": {
                "attribute_name": "status"
              },
              "0x0302": {
                "attribute_name": "divisor"
              },
              "0x0306": {
                "attribute_name": "metering_device_type"
              },
              "0x0304": {
                "attribute_name": "demand_formatting"
              },
              "0x0301": {
                "attribute_name": "multiplier"
              },
              "0x0303": {
                "attribute_name": "summation_formatting"
              },
              "0x0300": {
                "attribute_name": "unit_of_measure"
              }
            }
          }
        },
        "out_clusters": {}
      }
    }
  }
}

If I install the quirk, the original plug (which doesn’t need a local quirk), picks the file up immediately, but the new plug which is the one that actually needs it, does not.

I don’t quite have enough knowledge at this point to take whats in the device debug and add it to the quirk file to make the new plug pick up the quirk, and hopefully start working properly.

Any help would be appreciated.

For those who find this post, I mostly fixed my issues via this thread:-

I’m still struggling to get some of the power metering values to be correct, but its now displaying the missing controls.