diff --git a/tests/test_units.py b/tests/test_units.py deleted file mode 100644 index 45e7a77f4..000000000 --- a/tests/test_units.py +++ /dev/null @@ -1,30 +0,0 @@ -"""Tests for units.""" - -import enum - -import pytest -from zigpy.quirks.v2.homeassistant import UnitOfPower as QuirksUnitOfPower - -from zha.units import UnitOfPower, validate_unit - - -def test_unit_validation() -> None: - """Test unit validation.""" - - assert validate_unit(QuirksUnitOfPower.WATT) == UnitOfPower.WATT - - class FooUnit(enum.Enum): - """Foo unit.""" - - BAR = "bar" - - class UnitOfMass(enum.Enum): - """UnitOfMass.""" - - BAR = "bar" - - with pytest.raises(KeyError): - validate_unit(FooUnit.BAR) - - with pytest.raises(ValueError): - validate_unit(UnitOfMass.BAR) diff --git a/zha/application/platforms/number/__init__.py b/zha/application/platforms/number/__init__.py index de2bd3b92..5abe5ae54 100644 --- a/zha/application/platforms/number/__init__.py +++ b/zha/application/platforms/number/__init__.py @@ -22,7 +22,7 @@ NumberMode, ) from zha.application.registries import PLATFORM_ENTITIES -from zha.units import UnitOfMass, UnitOfTemperature, UnitOfTime, validate_unit +from zha.units import UnitOfMass, UnitOfTemperature, UnitOfTime from zha.zigbee.cluster_handlers import ClusterAttributeUpdatedEvent from zha.zigbee.cluster_handlers.const import ( CLUSTER_HANDLER_ANALOG_OUTPUT, @@ -266,9 +266,7 @@ def _init_from_quirks_metadata(self, entity_metadata: NumberMetadata) -> None: _LOGGER, ) if entity_metadata.unit is not None: - self._attr_native_unit_of_measurement = validate_unit( - entity_metadata.unit - ).value + self._attr_native_unit_of_measurement = entity_metadata.unit @functools.cached_property def info_object(self) -> NumberConfigurationEntityInfo: diff --git a/zha/application/platforms/sensor/__init__.py b/zha/application/platforms/sensor/__init__.py index 11e9c8769..e212a6f17 100644 --- a/zha/application/platforms/sensor/__init__.py +++ b/zha/application/platforms/sensor/__init__.py @@ -56,7 +56,6 @@ UnitOfTime, UnitOfVolume, UnitOfVolumeFlowRate, - validate_unit, ) from zha.zigbee.cluster_handlers import ClusterAttributeUpdatedEvent from zha.zigbee.cluster_handlers.const import ( @@ -243,9 +242,7 @@ def _init_from_quirks_metadata(self, entity_metadata: ZCLSensorMetadata) -> None entity_metadata.state_class ) if entity_metadata.unit is not None: - self._attr_native_unit_of_measurement = validate_unit( - entity_metadata.unit - ).value + self._attr_native_unit_of_measurement = entity_metadata.unit @functools.cached_property def info_object(self) -> SensorEntityInfo: diff --git a/zha/units.py b/zha/units.py index 47c4b8d6b..8817ee178 100644 --- a/zha/units.py +++ b/zha/units.py @@ -1,6 +1,6 @@ """Units of measure for Zigbee Home Automation.""" -from enum import Enum, StrEnum +from enum import StrEnum from typing import Final @@ -157,25 +157,3 @@ class UnitOfEnergy(StrEnum): # Percentage units PERCENTAGE: Final[str] = "%" - - -UNITS_OF_MEASURE = { - UnitOfApparentPower.__name__: UnitOfApparentPower, - UnitOfPower.__name__: UnitOfPower, - UnitOfEnergy.__name__: UnitOfEnergy, - UnitOfElectricCurrent.__name__: UnitOfElectricCurrent, - UnitOfElectricPotential.__name__: UnitOfElectricPotential, - UnitOfTemperature.__name__: UnitOfTemperature, - UnitOfTime.__name__: UnitOfTime, - UnitOfFrequency.__name__: UnitOfFrequency, - UnitOfPressure.__name__: UnitOfPressure, - UnitOfVolume.__name__: UnitOfVolume, - UnitOfVolumeFlowRate.__name__: UnitOfVolumeFlowRate, - UnitOfLength.__name__: UnitOfLength, - UnitOfMass.__name__: UnitOfMass, -} - - -def validate_unit(external_unit: Enum) -> Enum: - """Validate and return a unit of measure.""" - return UNITS_OF_MEASURE[type(external_unit).__name__](external_unit.value)