-
Notifications
You must be signed in to change notification settings - Fork 31
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
validate_unit
doesn't allow valid values
#327
Comments
I'll have to double check, but I don't think ESPHome validates the provided In the worst case, HA logs a warning if the unit doesn't match the state class. The state class and the unit playing together is the important part. If there's no state class, all units should be valid. So, we really should just drop this validation for units IMO. There's nothing positive we get from it. |
Concur, I don't see a reason to validate the value in ZHA, it just adds complexity. |
First,
validate_unit
typing isEnum
, although it's typed asstr
everywhere else, so in quirks v2 metadata, and so on.In ZHA and HA,
_attr_native_unit_of_measurement
is also typed asstr | None
.It should be changed to accept and return a
str
IMO.The mapping is also not ideal, as we have units replicated in both zigpy and ZHA now. We should change this in the future, e.g. by just having it in zigpy (and maybe renaming the
quirks/v2
where it is currently to something else). Or a separate lib?We also need to fix not accepting the units strings that are defined, like
PERCENTAGE
. We need to allow those.Actually, I don't think we really need the validation for a string anyways. Quirks v2 entities are still reviewed and obviously need to use the constants defined here before they can be merged.
HA might also already validate the units used?
Link to method (and units file):
zha/zha/units.py
Lines 179 to 181 in c013c5b
cc @prairiesnpr
The text was updated successfully, but these errors were encountered: