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

Sensor init fails if unit of measurement is a string #326

Open
tr4nt0r opened this issue Dec 11, 2024 · 0 comments
Open

Sensor init fails if unit of measurement is a string #326

tr4nt0r opened this issue Dec 11, 2024 · 0 comments

Comments

@tr4nt0r
Copy link

tr4nt0r commented Dec 11, 2024

When providing a unit in the tuya V2 quirk builder that is a string (instead of an Enum) the sensor init fails.
I used the unit lx, which is defined in the const LIGHT_LUX

    .tuya_sensor(
        dp_id=101,
        attribute_name="measured_value",
        type=t.uint16_t,
        fallback_name="Illuminance",
        device_class=SensorDeviceClass.ILLUMINANCE,
        state_class=SensorStateClass.MEASUREMENT,
        unit=LIGHT_LUX,
    )

Traceback (most recent call last):
  File "/usr/local/lib/python3.13/site-packages/zha/application/gateway.py", line 335, in create_platform_entities
    platform_entity = platform_entity_class.create_platform_entity(
        *args, **kw_args
    )
  File "/usr/local/lib/python3.13/site-packages/zha/application/platforms/sensor/__init__.py", line 186, in create_platform_entity
    return cls(unique_id, cluster_handlers, endpoint, device, **kwargs)
  File "/usr/local/lib/python3.13/site-packages/zha/application/platforms/sensor/__init__.py", line 198, in __init__
    super().__init__(unique_id, cluster_handlers, endpoint, device, **kwargs)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/zha/application/platforms/__init__.py", line 297, in __init__
    self._init_from_quirks_metadata(entity_metadata)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/zha/application/platforms/sensor/__init__.py", line 220, in _init_from_quirks_metadata
    self._attr_native_unit_of_measurement = validate_unit(
                                            ~~~~~~~~~~~~~^
        entity_metadata.unit
        ^^^^^^^^^^^^^^^^^^^^
    ).value
    ^
  File "/usr/local/lib/python3.13/site-packages/zha/units.py", line 181, in validate_unit
    return UNITS_OF_MEASURE[type(external_unit).__name__](external_unit.value)
           ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 'str'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant