Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions tests/test_units.py

This file was deleted.

6 changes: 2 additions & 4 deletions zha/application/platforms/number/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions zha/application/platforms/sensor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
UnitOfTime,
UnitOfVolume,
UnitOfVolumeFlowRate,
validate_unit,
)
from zha.zigbee.cluster_handlers import ClusterAttributeUpdatedEvent
from zha.zigbee.cluster_handlers.const import (
Expand Down Expand Up @@ -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:
Expand Down
24 changes: 1 addition & 23 deletions zha/units.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Units of measure for Zigbee Home Automation."""

from enum import Enum, StrEnum
from enum import StrEnum
from typing import Final


Expand Down Expand Up @@ -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)
Loading