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

Removed ZHA units and unit validation #332

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
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
7 changes: 3 additions & 4 deletions tests/test_discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
QuirkBuilder,
ZCLSensorMetadata,
)
from zigpy.quirks.v2.homeassistant import UnitOfTime
import zigpy.types
from zigpy.zcl import ClusterType
import zigpy.zcl.clusters.closures
Expand Down Expand Up @@ -317,7 +316,7 @@ async def test_quirks_v2_entity_discovery(
min_value=1,
max_value=100,
step=1,
unit=UnitOfTime.SECONDS,
unit="s",
multiplier=1,
translation_key="off_wait_time",
fallback_name="Off wait time",
Expand Down Expand Up @@ -518,7 +517,7 @@ def _get_test_device(
min_value=1,
max_value=100,
step=1,
unit=UnitOfTime.SECONDS,
unit="s",
multiplier=1,
translation_key="on_off_transition_time",
fallback_name="On off transition time",
Expand All @@ -529,7 +528,7 @@ def _get_test_device(
min_value=1,
max_value=100,
step=1,
unit=UnitOfTime.SECONDS,
unit="s",
multiplier=1,
translation_key="on_off_transition_time",
fallback_name="On off transition time",
Expand Down
43 changes: 21 additions & 22 deletions tests/test_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@
from zha.application.const import ZHA_CLUSTER_HANDLER_READS_PER_REQ
from zha.application.gateway import Gateway
from zha.application.platforms import PlatformEntity, sensor
from zha.application.platforms.sensor import DanfossSoftwareErrorCode, UnitOfMass
from zha.application.platforms.sensor import DanfossSoftwareErrorCode
from zha.application.platforms.sensor.const import SensorDeviceClass
from zha.units import PERCENTAGE, UnitOfEnergy, UnitOfPressure, UnitOfVolume
from zha.zigbee.device import Device

EMAttrs = homeautomation.ElectricalMeasurement.AttributeDefs
Expand Down Expand Up @@ -193,7 +192,7 @@ async def async_test_smart_energy_summation_delivered(
await send_attributes_report(
zha_gateway, cluster, {1025: 1, "current_summ_delivered": 12321, 1026: 100}
)
assert_state(entity, 12.321, UnitOfEnergy.KILO_WATT_HOUR)
assert_state(entity, 12.321, "kWh")
assert entity.state["status"] == "NO_ALARMS"
assert entity.state["device_type"] == "Electric Metering"
assert entity.info_object.device_class == SensorDeviceClass.ENERGY
Expand All @@ -207,7 +206,7 @@ async def async_test_smart_energy_summation_received(
await send_attributes_report(
zha_gateway, cluster, {1025: 1, "current_summ_received": 12321, 1026: 100}
)
assert_state(entity, 12.321, UnitOfEnergy.KILO_WATT_HOUR)
assert_state(entity, 12.321, "kWh")
assert entity.state["status"] == "NO_ALARMS"
assert entity.state["device_type"] == "Electric Metering"
assert entity.info_object.device_class == SensorDeviceClass.ENERGY
Expand Down Expand Up @@ -284,17 +283,17 @@ async def async_test_em_power_factor(
# update divisor cached value
await send_attributes_report(zha_gateway, cluster, {"ac_power_divisor": 1})
await send_attributes_report(zha_gateway, cluster, {0: 1, 0x0510: 100, 10: 1000})
assert_state(entity, 100, PERCENTAGE)
assert_state(entity, 100, "%")

await send_attributes_report(zha_gateway, cluster, {0: 1, 0x0510: 99, 10: 1000})
assert_state(entity, 99, PERCENTAGE)
assert_state(entity, 99, "%")

await send_attributes_report(zha_gateway, cluster, {"ac_power_divisor": 10})
await send_attributes_report(zha_gateway, cluster, {0: 1, 0x0510: 100, 10: 5000})
assert_state(entity, 100, PERCENTAGE)
assert_state(entity, 100, "%")

await send_attributes_report(zha_gateway, cluster, {0: 1, 0x0510: 99, 10: 5000})
assert_state(entity, 99, PERCENTAGE)
assert_state(entity, 99, "%")


async def async_test_em_rms_current(
Expand Down Expand Up @@ -884,73 +883,73 @@ async def test_unsupported_attributes_sensor(
1,
12320,
1.23,
UnitOfVolume.CUBIC_METERS,
"m³",
),
(
1,
1232000,
123.2,
UnitOfVolume.CUBIC_METERS,
"m³",
),
(
3,
2340,
0.23,
UnitOfVolume.CUBIC_FEET,
"ft³",
),
(
3,
2360,
0.24,
UnitOfVolume.CUBIC_FEET,
"ft³",
),
(
8,
23660,
2.37,
UnitOfPressure.KPA,
"kPa",
),
(
0,
9366,
0.937,
UnitOfEnergy.KILO_WATT_HOUR,
"kWh",
),
(
0,
999,
0.1,
UnitOfEnergy.KILO_WATT_HOUR,
"kWh",
),
(
0,
10091,
1.009,
UnitOfEnergy.KILO_WATT_HOUR,
"kWh",
),
(
0,
10099,
1.01,
UnitOfEnergy.KILO_WATT_HOUR,
"kWh",
),
(
0,
100999,
10.1,
UnitOfEnergy.KILO_WATT_HOUR,
"kWh",
),
(
0,
100023,
10.002,
UnitOfEnergy.KILO_WATT_HOUR,
"kWh",
),
(
0,
102456,
10.246,
UnitOfEnergy.KILO_WATT_HOUR,
"kWh",
),
(
5,
Expand All @@ -962,7 +961,7 @@ async def test_unsupported_attributes_sensor(
7,
50124,
5.01,
UnitOfVolume.LITERS,
"L",
),
),
)
Expand Down Expand Up @@ -1241,7 +1240,7 @@ def __init__(self, *args, **kwargs) -> None:
OppleCluster.cluster_id,
divisor=1,
multiplier=1,
unit=UnitOfMass.GRAMS,
unit="g",
translation_key="last_feeding_size",
fallback_name="Last feeding size",
)
Expand Down
30 changes: 0 additions & 30 deletions tests/test_units.py

This file was deleted.

3 changes: 1 addition & 2 deletions zha/application/platforms/climate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
)
from zha.application.registries import PLATFORM_ENTITIES
from zha.decorators import periodic
from zha.units import UnitOfTemperature
from zha.zigbee.cluster_handlers import ClusterAttributeUpdatedEvent
from zha.zigbee.cluster_handlers.const import (
CLUSTER_HANDLER_ATTRIBUTE_UPDATED,
Expand Down Expand Up @@ -81,7 +80,7 @@ class Thermostat(PlatformEntity):
DEFAULT_MIN_TEMP = 7

_attr_precision = PRECISION_TENTHS
_attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_temperature_unit = "°C"
_attr_translation_key: str = "thermostat"
_enable_turn_on_off_backwards_compatibility = False
_attr_extra_state_attribute_names: set[str] = {
Expand Down
17 changes: 7 additions & 10 deletions zha/application/platforms/number/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
NumberMode,
)
from zha.application.registries import PLATFORM_ENTITIES
from zha.units import UnitOfMass, UnitOfTemperature, UnitOfTime, validate_unit
from zha.zigbee.cluster_handlers import ClusterAttributeUpdatedEvent
from zha.zigbee.cluster_handlers.const import (
CLUSTER_HANDLER_ANALOG_OUTPUT,
Expand Down Expand Up @@ -266,9 +265,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 Expand Up @@ -814,7 +811,7 @@ class AqaraPetFeederPortionWeight(NumberConfigurationEntity):
_attr_translation_key: str = "portion_weight"

_attr_mode: NumberMode = NumberMode.BOX
_attr_native_unit_of_measurement: str = UnitOfMass.GRAMS
_attr_native_unit_of_measurement: str = "g"


@CONFIG_DIAGNOSTIC_MATCH(
Expand All @@ -832,7 +829,7 @@ class AqaraThermostatAwayTemp(NumberConfigurationEntity):
_attr_translation_key: str = "away_preset_temperature"

_attr_mode: NumberMode = NumberMode.SLIDER
_attr_native_unit_of_measurement: str = UnitOfTemperature.CELSIUS
_attr_native_unit_of_measurement: str = "°C"


@CONFIG_DIAGNOSTIC_MATCH(
Expand All @@ -851,7 +848,7 @@ class ThermostatLocalTempCalibration(NumberConfigurationEntity):
_attr_translation_key: str = "local_temperature_calibration"

_attr_mode: NumberMode = NumberMode.BOX
_attr_native_unit_of_measurement: str = UnitOfTemperature.CELSIUS
_attr_native_unit_of_measurement: str = "°C"


@CONFIG_DIAGNOSTIC_MATCH(
Expand Down Expand Up @@ -886,7 +883,7 @@ class SonoffPresenceSenorTimeout(NumberConfigurationEntity):
class ZCLTemperatureEntity(NumberConfigurationEntity):
"""Common entity class for ZCL temperature input."""

_attr_native_unit_of_measurement: str = UnitOfTemperature.CELSIUS
_attr_native_unit_of_measurement: str = "°C"
_attr_mode: NumberMode = NumberMode.BOX
_attr_native_step: float = 0.01
_attr_multiplier: float = 0.01
Expand Down Expand Up @@ -957,7 +954,7 @@ class DanfossExerciseTriggerTime(NumberConfigurationEntity):
_attr_native_min_value: int = 0
_attr_native_max_value: int = 1439
_attr_mode: NumberMode = NumberMode.BOX
_attr_native_unit_of_measurement: str = UnitOfTime.MINUTES
_attr_native_unit_of_measurement: str = "min"


@CONFIG_DIAGNOSTIC_MATCH(
Expand Down Expand Up @@ -1000,7 +997,7 @@ class DanfossRegulationSetpointOffset(NumberConfigurationEntity):
_attribute_name: str = "regulation_setpoint_offset"
_attr_translation_key: str = "regulation_setpoint_offset"
_attr_mode: NumberMode = NumberMode.BOX
_attr_native_unit_of_measurement: str = UnitOfTemperature.CELSIUS
_attr_native_unit_of_measurement: str = "°C"
_attr_native_min_value: float = -2.5
_attr_native_max_value: float = 2.5
_attr_native_step: float = 0.1
Expand Down
Loading