andrew-codechimp / HA-Battery-Notes

A Home Assistant integration to provide battery notes of devices
MIT License
529 stars 92 forks source link

Add wildcard for _TZ manufacturers #190

Closed andrew-codechimp closed 8 months ago

andrew-codechimp commented 10 months ago

Checklist

Is your feature request related to a problem? Please describe.

It appears Tuya devices generate unique manufacturer ID's for the same model as demonstrated below.

_TZ3000_dowj6gyi | TS0201 _TZ3000_fllyghyj | TS0201

_TZE200_b6wax7g0 | TS0601 _TZE200_c88teujp | TS0601 _TZE200_locansqn | TS0601

Describe the solution you'd like

Modify the library to support a manufacturer of _TZxxx_* to allow matching all models

Describe alternatives you've considered

Do not allow submissions of _TZ devices as they won't be any use to anyone but the submitter

Additional context

I personally don't have any of these devices so if anyone who has a few of them can give additional context that would be helpful.

bmos commented 10 months ago

Unfortunately this may not work. Tuya seems to offer multiple devices with the same model number that have different batteries. https://github.com/andrew-codechimp/HA-Battery-Notes/blob/8d29c668facb36ea1b7b1e034d0cce1aea1ea264/custom_components/battery_notes/data/library.json#L15C10-L25

andrew-codechimp commented 9 months ago

If there are multiple devices with the same model we can change those to MANUAL to stop discovery, I'm also not ruling out bad data either. I will still wait for more examples to know if the trailing random characters are something like a mac address to wildcard.

andrew-codechimp commented 9 months ago

There may also be another format of manufacturer, will have to keep an eye on ones in the format of TUYATEC-xrvzm3yI

uvjim commented 9 months ago

This might be awkward to manage for submissions but you could adjust the JSON schema to something like this...

{
    "devices": [
        {
            "manufacturer": [
                "_TZ3000_fllyghyj",
                "_TZ3000_xr3htd96"
            ],
            "model": "TS0201",
            "battery_type": "AAA",
            "battery_quantity": 2
        },
        {
            "manufacturer": [
                "_TZ3000_dowj6gyi"
            ],
            "model": "TS0201",
            "battery_type": "CR2450"
        }
    ]
}

This would allow you to maintain multiple manufacturers for the same model with different battery types as well. If you can't wildcard then you'll have to look them up somehow.

andrew-codechimp commented 9 months ago

Changing the schema will be of last resort, the library is only growing because the schema is approachable and now automated. I've not got enough so far to determine what exceptions there are and to fact check the battery details.

bmos commented 9 months ago

I just opened another of the Tuya door sensors I bought last month. The first one I opened was TS0203 by _TZ3000_yxqnffam. The second one is also the same, so it's not unique per-device. My hunch is that the unique-looking string is related to what firmware the device is running.

andrew-codechimp commented 9 months ago

Interesting, thanks for investigating. It may still warrant a wildcard but at least it's not per device so does have some re-use as it is currently.

uvjim commented 9 months ago

IIRC Zigbee2Mqtt uses these to identify manufacturers and models when the device joins the mesh. These ideas are used to differentiate between those that are the same.

As an example, I recently had some ClickSmart+ sockets that were identified as a Tuya device. Supplying the _TZ string, icons and details of the manufacturer and model Allowed the UI to show the correct icon when these devices are on the ZigBee network.

I would hazard a guess that these strings are unique per manufacturer as part of some kind of OEM agreement. I would also assume that a single manufacturer can have multiple of these strings associated with them and potentially for the same model.

andrew-codechimp commented 8 months ago

Since the manufacturers are alternative branding/revisions and there is some discrepancy in battery types between the revisions I'm closing this issue. Not getting a lot of these come through so far anyway.