Skip to content

Commit 3aaf797

Browse files
authored
Remove unnecessary unit validation (#352)
1 parent a833f43 commit 3aaf797

File tree

4 files changed

+4
-61
lines changed

4 files changed

+4
-61
lines changed

tests/test_units.py

Lines changed: 0 additions & 30 deletions
This file was deleted.

zha/application/platforms/number/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
NumberMode,
2323
)
2424
from zha.application.registries import PLATFORM_ENTITIES
25-
from zha.units import UnitOfMass, UnitOfTemperature, UnitOfTime, validate_unit
25+
from zha.units import UnitOfMass, UnitOfTemperature, UnitOfTime
2626
from zha.zigbee.cluster_handlers import ClusterAttributeUpdatedEvent
2727
from zha.zigbee.cluster_handlers.const import (
2828
CLUSTER_HANDLER_ANALOG_OUTPUT,
@@ -266,9 +266,7 @@ def _init_from_quirks_metadata(self, entity_metadata: NumberMetadata) -> None:
266266
_LOGGER,
267267
)
268268
if entity_metadata.unit is not None:
269-
self._attr_native_unit_of_measurement = validate_unit(
270-
entity_metadata.unit
271-
).value
269+
self._attr_native_unit_of_measurement = entity_metadata.unit
272270

273271
@functools.cached_property
274272
def info_object(self) -> NumberConfigurationEntityInfo:

zha/application/platforms/sensor/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
UnitOfTime,
5757
UnitOfVolume,
5858
UnitOfVolumeFlowRate,
59-
validate_unit,
6059
)
6160
from zha.zigbee.cluster_handlers import ClusterAttributeUpdatedEvent
6261
from zha.zigbee.cluster_handlers.const import (
@@ -243,9 +242,7 @@ def _init_from_quirks_metadata(self, entity_metadata: ZCLSensorMetadata) -> None
243242
entity_metadata.state_class
244243
)
245244
if entity_metadata.unit is not None:
246-
self._attr_native_unit_of_measurement = validate_unit(
247-
entity_metadata.unit
248-
).value
245+
self._attr_native_unit_of_measurement = entity_metadata.unit
249246

250247
@functools.cached_property
251248
def info_object(self) -> SensorEntityInfo:

zha/units.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Units of measure for Zigbee Home Automation."""
22

3-
from enum import Enum, StrEnum
3+
from enum import StrEnum
44
from typing import Final
55

66

@@ -157,25 +157,3 @@ class UnitOfEnergy(StrEnum):
157157

158158
# Percentage units
159159
PERCENTAGE: Final[str] = "%"
160-
161-
162-
UNITS_OF_MEASURE = {
163-
UnitOfApparentPower.__name__: UnitOfApparentPower,
164-
UnitOfPower.__name__: UnitOfPower,
165-
UnitOfEnergy.__name__: UnitOfEnergy,
166-
UnitOfElectricCurrent.__name__: UnitOfElectricCurrent,
167-
UnitOfElectricPotential.__name__: UnitOfElectricPotential,
168-
UnitOfTemperature.__name__: UnitOfTemperature,
169-
UnitOfTime.__name__: UnitOfTime,
170-
UnitOfFrequency.__name__: UnitOfFrequency,
171-
UnitOfPressure.__name__: UnitOfPressure,
172-
UnitOfVolume.__name__: UnitOfVolume,
173-
UnitOfVolumeFlowRate.__name__: UnitOfVolumeFlowRate,
174-
UnitOfLength.__name__: UnitOfLength,
175-
UnitOfMass.__name__: UnitOfMass,
176-
}
177-
178-
179-
def validate_unit(external_unit: Enum) -> Enum:
180-
"""Validate and return a unit of measure."""
181-
return UNITS_OF_MEASURE[type(external_unit).__name__](external_unit.value)

0 commit comments

Comments
 (0)