#👋 Is there a channel to ask about
1 messages · Page 1 of 1 (latest)
I suppose I will explain my issue and see what I get.
So I'm trying to add a quirk, and as as part of that quirk I wanted to expose one of the attributes as a sensor:
.sensor( SomeCluster.AttributeDefs.some_attr.name, SomeCluster.cluster_id, device_class=SensorDeviceClass.ENUM )
some_attr is in turn defined as:
some_attr = ZCLAttributeDef( id=0x1234, type=SomeStatus)
ANd SomeStatus is a t.enum8
In HA however, I'm not seeing the enum values, but what it looks like a float (1.0) instead of (SomeStatus.ONE)
And the id of the sensor is sensor.some_attr_none (i.e., the attr name plus _none)
Am I missing something?
The name is None because the translation key is missing in HA. Normally, it's added to HA when we bump ZHA with new quirks in HA. For now, you either have to modify your translation files or just rename the entity in HA.
For the sensor part, we support .enum for the select entity platform. Not sure that's what you want though.
If you want more advanced entities, you may need to add them directly to ZHA for now.
Ok, I can live with the _none for now
But I'm still not sure why the enum is not being used and I'm getting a float value instead
It's a number internally.
Right, I meant why is not displayed as a string in HA. Or are my expectations wrong?
Also, re translation_key, if I define that and also device_class, validation fails.
So how am I suppose to do it?
The translations need to be defined in HA: https://github.com/home-assistant/core/blob/dev/homeassistant/components/zha/strings.json
If running locally, translations also need to be generated with python3 -m script.translations develop.
By default, the translation key is the attribute name, except if you add another translation_key parameter to the .sensor method.
Regarding the enum, only the internal attribute value (a number) is passed to HA.
For now, you'd need to define an enum sensor in ZHA, like this: https://github.com/zigpy/zha/blob/57cc44be97077a79e83c8fc963289b18601837ac/zha/application/platforms/sensor/__init__.py#L1496-L1503
Is it expected that setting the translation_key when defining the sensor fails validation if device_class is also set?
Which validation are you talking about?
EntityMetadata has a _validate method that errors out if device_class and translation_key are defined
Ah, I wonder if that implementation is a bit strong. Generally, a device class in HA will already set a default name for the entity.
Giving that the zha code in some places define both without issues makes me think it shouldn't fail
Yeah, that was my follow up question
I see almost no use of quirks v2
Is it ready for prime time?
Or should I wait?
I really like the API, so much better than copying the endpoints that you want to replace
But there is no much info or RL docs to get you going
(and by RL docs I mean real uses that I can have a peek at, no just documentation)
There are a couple of v2 quirks in the zha-quirks repo: https://github.com/search?q=repo%3Azigpy%2Fzha-device-handlers QuirkBuilder&type=code
They do not add custom entites though.
Yeah, I thought those but they only add automation triggers
It still has a few limitations, but if you're able to do what you want with it, feel free to use it already.
If the issue is with custom entities being too limited, you can still use quirks v2, but directly add the entities in ZHA.
Right, I was hoping I could do everything directly in a single place but I can live with that for now
I mean, the unique_id_suffix is not available either
It's the attribute name by default, for quirks v2. It shouldn't be needed.
among other things
yeah, but in some cases you might want to have a different ones, like having 2 sensors showing different things depending on the value of the same attribute
In that case, yes, but it's not possible to parse attribute values with quirks v2 entities at the moment.
It's mostly intended to expose simple on/off configuration switches, for example. For more advanced sensors, ZHA still needs to be modified, yeah.
Ah, that's a good and valid point. I didn't consider the target to be simple configurations.
https://github.com/zigpy/zha/blob/c6edfd47997f2023427514d558da90a0ecf75688/tests/test_discover.py#L581 this should work for the enum part @arctic silo
https://github.com/zigpy/zha/blob/c6edfd47997f2023427514d558da90a0ecf75688/tests/test_discover.py#L662 you can see we assert the name as the value later in the test
The not mixing device class + translation key is intended. Existing entities do it but it was requested that we don’t do that moving forward. IIRC this was a call out from core folks
There are a lot of examples in the ZHA tests in the lib repo (linked above)
@ashen pilot the enum stuff you are mentioning is different
I want to be able to see the values for an attribute whose type is a t.enum8
Actually, I did try with enums but I might have missed something
Let me try that
Yay! That did it. Thank you!
Is there a real world use case for this?
I don't have but I know a PR that uses this: https://github.com/zigpy/zha/pull/189/files
Ok bitsets… yeah we will have a similar situation when we solve tamper sensors on the IASZone cluster as well
Feel free to drop any additional observations here for us… always looking for feedback
I wonder if there is any way to achieve the same using the Quirks v2 approach
Not directly related though
There will be… just have to build it 😄
Also, does it make sense to convert existing quirks to the v2 api?
At some point… not high up on the list atm
One more question. What's canonical way to test if a quirk matches with the quirk builder?
Is there an example I can look at? I haven't been able to find one on a rather quick search
It’ll match if the manufacturer and model are the same, there’s nothing really to test in that regard. It was more complicated with quirks v1, as it used the whole device signature.
It’s matched purely on manufacturer / model rn
You can also define filters too
There is an example using the signature matching from V1 in the zha lib tests
Ah, ok. Makes sense. Ty
Actually it’s in the Zigpy tests: https://github.com/zigpy/zigpy/blob/754b1cde78eb90dd21c11f50b4c9c39bbe936d99/tests/test_quirks_v2.py#L102
Lots of v2 quirks examples in here too