36
36
from zha .application .gateway import Gateway
37
37
from zha .application .platforms import PlatformEntity , sensor
38
38
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
40
40
from zha .units import PERCENTAGE , UnitOfEnergy , UnitOfPressure , UnitOfVolume
41
41
from zha .zigbee .device import Device
42
42
@@ -623,8 +623,7 @@ async def test_sensor(
623
623
entity = get_entity (
624
624
zha_device , platform = Platform .SENSOR , exact_entity_type = entity_type
625
625
)
626
-
627
- await zha_gateway .async_block_till_done ()
626
+ assert entity .available is True
628
627
# test sensor associated logic
629
628
await test_func (zha_gateway , cluster , entity )
630
629
@@ -933,91 +932,119 @@ async def test_unsupported_attributes_sensor(
933
932
934
933
935
934
@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 " ,
937
936
(
938
937
(
939
938
1 ,
940
939
12320 ,
941
940
1.23 ,
942
941
UnitOfVolume .CUBIC_METERS ,
942
+ SensorDeviceClass .VOLUME ,
943
+ SensorStateClass .TOTAL_INCREASING ,
943
944
),
944
945
(
945
946
1 ,
946
947
1232000 ,
947
948
123.2 ,
948
949
UnitOfVolume .CUBIC_METERS ,
950
+ SensorDeviceClass .VOLUME ,
951
+ SensorStateClass .TOTAL_INCREASING ,
949
952
),
950
953
(
951
954
3 ,
952
955
2340 ,
953
956
0.23 ,
954
957
UnitOfVolume .CUBIC_FEET ,
958
+ SensorDeviceClass .VOLUME ,
959
+ SensorStateClass .TOTAL_INCREASING ,
955
960
),
956
961
(
957
962
3 ,
958
963
2360 ,
959
964
0.24 ,
960
965
UnitOfVolume .CUBIC_FEET ,
966
+ SensorDeviceClass .VOLUME ,
967
+ SensorStateClass .TOTAL_INCREASING ,
961
968
),
962
969
(
963
970
8 ,
964
971
23660 ,
965
972
2.37 ,
966
973
UnitOfPressure .KPA ,
974
+ SensorDeviceClass .PRESSURE ,
975
+ SensorStateClass .MEASUREMENT ,
967
976
),
968
977
(
969
978
0 ,
970
979
9366 ,
971
980
0.937 ,
972
981
UnitOfEnergy .KILO_WATT_HOUR ,
982
+ SensorDeviceClass .ENERGY ,
983
+ SensorStateClass .TOTAL_INCREASING ,
973
984
),
974
985
(
975
986
0 ,
976
987
999 ,
977
988
0.1 ,
978
989
UnitOfEnergy .KILO_WATT_HOUR ,
990
+ SensorDeviceClass .ENERGY ,
991
+ SensorStateClass .TOTAL_INCREASING ,
979
992
),
980
993
(
981
994
0 ,
982
995
10091 ,
983
996
1.009 ,
984
997
UnitOfEnergy .KILO_WATT_HOUR ,
998
+ SensorDeviceClass .ENERGY ,
999
+ SensorStateClass .TOTAL_INCREASING ,
985
1000
),
986
1001
(
987
1002
0 ,
988
1003
10099 ,
989
1004
1.01 ,
990
1005
UnitOfEnergy .KILO_WATT_HOUR ,
1006
+ SensorDeviceClass .ENERGY ,
1007
+ SensorStateClass .TOTAL_INCREASING ,
991
1008
),
992
1009
(
993
1010
0 ,
994
1011
100999 ,
995
1012
10.1 ,
996
1013
UnitOfEnergy .KILO_WATT_HOUR ,
1014
+ SensorDeviceClass .ENERGY ,
1015
+ SensorStateClass .TOTAL_INCREASING ,
997
1016
),
998
1017
(
999
1018
0 ,
1000
1019
100023 ,
1001
1020
10.002 ,
1002
1021
UnitOfEnergy .KILO_WATT_HOUR ,
1022
+ SensorDeviceClass .ENERGY ,
1023
+ SensorStateClass .TOTAL_INCREASING ,
1003
1024
),
1004
1025
(
1005
1026
0 ,
1006
1027
102456 ,
1007
1028
10.246 ,
1008
1029
UnitOfEnergy .KILO_WATT_HOUR ,
1030
+ SensorDeviceClass .ENERGY ,
1031
+ SensorStateClass .TOTAL_INCREASING ,
1009
1032
),
1010
1033
(
1011
1034
5 ,
1012
1035
102456 ,
1013
1036
10.25 ,
1014
1037
"IMP gal" ,
1038
+ None ,
1039
+ SensorStateClass .TOTAL_INCREASING ,
1015
1040
),
1016
1041
(
1017
1042
7 ,
1018
1043
50124 ,
1019
1044
5.01 ,
1020
1045
UnitOfVolume .LITERS ,
1046
+ SensorDeviceClass .VOLUME ,
1047
+ SensorStateClass .TOTAL_INCREASING ,
1021
1048
),
1022
1049
),
1023
1050
)
@@ -1035,6 +1062,8 @@ async def test_se_summation_uom(
1035
1062
raw_value : int ,
1036
1063
expected_state : str ,
1037
1064
expected_uom : str ,
1065
+ expected_device_class : SensorDeviceClass ,
1066
+ expected_state_class : SensorStateClass ,
1038
1067
) -> None :
1039
1068
"""Test zha smart energy summation."""
1040
1069
@@ -1073,6 +1102,15 @@ async def test_se_summation_uom(
1073
1102
zha_device , platform = Platform .SENSOR , qualifier = "summation_delivered"
1074
1103
)
1075
1104
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
+
1076
1114
assert_state (entity , expected_state , expected_uom )
1077
1115
1078
1116
0 commit comments