Skip to content

Commit e2311d0

Browse files
committed
sensor property coverage
1 parent 2bb8f19 commit e2311d0

File tree

1 file changed

+42
-4
lines changed

1 file changed

+42
-4
lines changed

tests/test_sensor.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from zha.application.gateway import Gateway
3737
from zha.application.platforms import PlatformEntity, sensor
3838
from zha.application.platforms.sensor import DanfossSoftwareErrorCode, UnitOfMass
39-
from zha.application.platforms.sensor.const import SensorDeviceClass
39+
from zha.application.platforms.sensor.const import SensorDeviceClass, SensorStateClass
4040
from zha.units import PERCENTAGE, UnitOfEnergy, UnitOfPressure, UnitOfVolume
4141
from zha.zigbee.device import Device
4242

@@ -623,8 +623,7 @@ async def test_sensor(
623623
entity = get_entity(
624624
zha_device, platform=Platform.SENSOR, exact_entity_type=entity_type
625625
)
626-
627-
await zha_gateway.async_block_till_done()
626+
assert entity.available is True
628627
# test sensor associated logic
629628
await test_func(zha_gateway, cluster, entity)
630629

@@ -933,91 +932,119 @@ async def test_unsupported_attributes_sensor(
933932

934933

935934
@pytest.mark.parametrize(
936-
"raw_uom, raw_value, expected_state, expected_uom",
935+
"raw_uom, raw_value, expected_state, expected_uom, expected_device_class, expected_state_class",
937936
(
938937
(
939938
1,
940939
12320,
941940
1.23,
942941
UnitOfVolume.CUBIC_METERS,
942+
SensorDeviceClass.VOLUME,
943+
SensorStateClass.TOTAL_INCREASING,
943944
),
944945
(
945946
1,
946947
1232000,
947948
123.2,
948949
UnitOfVolume.CUBIC_METERS,
950+
SensorDeviceClass.VOLUME,
951+
SensorStateClass.TOTAL_INCREASING,
949952
),
950953
(
951954
3,
952955
2340,
953956
0.23,
954957
UnitOfVolume.CUBIC_FEET,
958+
SensorDeviceClass.VOLUME,
959+
SensorStateClass.TOTAL_INCREASING,
955960
),
956961
(
957962
3,
958963
2360,
959964
0.24,
960965
UnitOfVolume.CUBIC_FEET,
966+
SensorDeviceClass.VOLUME,
967+
SensorStateClass.TOTAL_INCREASING,
961968
),
962969
(
963970
8,
964971
23660,
965972
2.37,
966973
UnitOfPressure.KPA,
974+
SensorDeviceClass.PRESSURE,
975+
SensorStateClass.MEASUREMENT,
967976
),
968977
(
969978
0,
970979
9366,
971980
0.937,
972981
UnitOfEnergy.KILO_WATT_HOUR,
982+
SensorDeviceClass.ENERGY,
983+
SensorStateClass.TOTAL_INCREASING,
973984
),
974985
(
975986
0,
976987
999,
977988
0.1,
978989
UnitOfEnergy.KILO_WATT_HOUR,
990+
SensorDeviceClass.ENERGY,
991+
SensorStateClass.TOTAL_INCREASING,
979992
),
980993
(
981994
0,
982995
10091,
983996
1.009,
984997
UnitOfEnergy.KILO_WATT_HOUR,
998+
SensorDeviceClass.ENERGY,
999+
SensorStateClass.TOTAL_INCREASING,
9851000
),
9861001
(
9871002
0,
9881003
10099,
9891004
1.01,
9901005
UnitOfEnergy.KILO_WATT_HOUR,
1006+
SensorDeviceClass.ENERGY,
1007+
SensorStateClass.TOTAL_INCREASING,
9911008
),
9921009
(
9931010
0,
9941011
100999,
9951012
10.1,
9961013
UnitOfEnergy.KILO_WATT_HOUR,
1014+
SensorDeviceClass.ENERGY,
1015+
SensorStateClass.TOTAL_INCREASING,
9971016
),
9981017
(
9991018
0,
10001019
100023,
10011020
10.002,
10021021
UnitOfEnergy.KILO_WATT_HOUR,
1022+
SensorDeviceClass.ENERGY,
1023+
SensorStateClass.TOTAL_INCREASING,
10031024
),
10041025
(
10051026
0,
10061027
102456,
10071028
10.246,
10081029
UnitOfEnergy.KILO_WATT_HOUR,
1030+
SensorDeviceClass.ENERGY,
1031+
SensorStateClass.TOTAL_INCREASING,
10091032
),
10101033
(
10111034
5,
10121035
102456,
10131036
10.25,
10141037
"IMP gal",
1038+
None,
1039+
SensorStateClass.TOTAL_INCREASING,
10151040
),
10161041
(
10171042
7,
10181043
50124,
10191044
5.01,
10201045
UnitOfVolume.LITERS,
1046+
SensorDeviceClass.VOLUME,
1047+
SensorStateClass.TOTAL_INCREASING,
10211048
),
10221049
),
10231050
)
@@ -1035,6 +1062,8 @@ async def test_se_summation_uom(
10351062
raw_value: int,
10361063
expected_state: str,
10371064
expected_uom: str,
1065+
expected_device_class: SensorDeviceClass,
1066+
expected_state_class: SensorStateClass,
10381067
) -> None:
10391068
"""Test zha smart energy summation."""
10401069

@@ -1073,6 +1102,15 @@ async def test_se_summation_uom(
10731102
zha_device, platform=Platform.SENSOR, qualifier="summation_delivered"
10741103
)
10751104

1105+
assert entity.device_class == expected_device_class
1106+
assert entity.state_class == expected_state_class
1107+
assert entity.extra_state_attribute_names == {
1108+
"device_type",
1109+
"status",
1110+
"zcl_unit_of_measurement",
1111+
}
1112+
assert entity.native_value == expected_state
1113+
10761114
assert_state(entity, expected_state, expected_uom)
10771115

10781116

0 commit comments

Comments
 (0)