File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed
application/platforms/sensor Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -85,6 +85,17 @@ async def async_test_humidity(
8585 assert_state (entity , 10.0 , "%" )
8686
8787
88+ async def async_test_flow (
89+ zha_gateway : Gateway , cluster : Cluster , entity : PlatformEntity
90+ ) -> None :
91+ """Test flow sensor."""
92+ await send_attributes_report (zha_gateway , cluster , {1 : 1 , 0 : 40 })
93+ assert_state (entity , 4.0 , "m³/h" )
94+
95+ await send_attributes_report (zha_gateway , cluster , {1 : 1 , 0 : 0xFFFF })
96+ assert_state (entity , None , "m³/h" )
97+
98+
8899async def async_test_temperature (
89100 zha_gateway : Gateway , cluster : Cluster , entity : PlatformEntity
90101) -> None :
@@ -408,6 +419,13 @@ async def async_test_change_source_timestamp(
408419 None ,
409420 None ,
410421 ),
422+ (
423+ measurement .FlowMeasurement .cluster_id ,
424+ sensor .Flow ,
425+ async_test_flow ,
426+ None ,
427+ None ,
428+ ),
411429 (
412430 measurement .TemperatureMeasurement .cluster_id ,
413431 sensor .Temperature ,
Original file line number Diff line number Diff line change 6767 CLUSTER_HANDLER_DEVICE_TEMPERATURE ,
6868 CLUSTER_HANDLER_DIAGNOSTIC ,
6969 CLUSTER_HANDLER_ELECTRICAL_MEASUREMENT ,
70+ CLUSTER_HANDLER_FLOW ,
7071 CLUSTER_HANDLER_HUMIDITY ,
7172 CLUSTER_HANDLER_ILLUMINANCE ,
7273 CLUSTER_HANDLER_INOVELLI ,
@@ -1132,6 +1133,23 @@ class Pressure(Sensor):
11321133 _attr_native_unit_of_measurement = UnitOfPressure .HPA
11331134
11341135
1136+ @MULTI_MATCH (cluster_handler_names = CLUSTER_HANDLER_FLOW )
1137+ class Flow (Sensor ):
1138+ """Flow Measurement sensor."""
1139+
1140+ _attribute_name = "measured_value"
1141+ _attr_device_class : SensorDeviceClass = SensorDeviceClass .VOLUME_FLOW_RATE
1142+ _attr_state_class : SensorStateClass = SensorStateClass .MEASUREMENT
1143+ _divisor = 10
1144+ _attr_native_unit_of_measurement = UnitOfVolumeFlowRate .CUBIC_METERS_PER_HOUR
1145+
1146+ def formatter (self , value : int ) -> int | float | str | None :
1147+ """Handle unknown value state."""
1148+ if value == 0xFFFF :
1149+ return None
1150+ return super ().formatter (value )
1151+
1152+
11351153@MULTI_MATCH (cluster_handler_names = CLUSTER_HANDLER_TEMPERATURE )
11361154class Temperature (Sensor ):
11371155 """Temperature Sensor."""
Original file line number Diff line number Diff line change 5252CLUSTER_HANDLER_ELECTRICAL_MEASUREMENT : Final [str ] = "electrical_measurement"
5353CLUSTER_HANDLER_EVENT_RELAY : Final [str ] = "event_relay"
5454CLUSTER_HANDLER_FAN : Final [str ] = "fan"
55+ CLUSTER_HANDLER_FLOW : Final [str ] = "flow"
5556CLUSTER_HANDLER_HUMIDITY : Final [str ] = "humidity"
5657CLUSTER_HANDLER_HUE_OCCUPANCY : Final [str ] = "philips_occupancy"
5758CLUSTER_HANDLER_SOIL_MOISTURE : Final [str ] = "soil_moisture"
You can’t perform that action at this time.
0 commit comments