@@ -5,10 +5,63 @@ import * as tz from "../converters/toZigbee";
55import * as exposes from "../lib/exposes" ;
66import * as m from "../lib/modernExtend" ;
77import * as reporting from "../lib/reporting" ;
8- import type { DefinitionWithExtend , Fz , KeyValue } from "../lib/types" ;
8+ import type {
9+ Configure ,
10+ Definition ,
11+ DefinitionExposesFunction ,
12+ DefinitionWithExtend ,
13+ DummyDevice ,
14+ Expose ,
15+ Fz ,
16+ KeyValue ,
17+ ModernExtend ,
18+ Zh ,
19+ } from "../lib/types" ;
20+ import * as utils from "../lib/utils" ;
921
1022const e = exposes . presets ;
1123
24+ function conditionalPressure ( ) : ModernExtend {
25+ const base = m . pressure ( ) ;
26+
27+ // Check whether any endpoint on the device has the msPressureMeasurement input cluster
28+ function deviceHasPressureCluster ( device : Zh . Device | DummyDevice ) : boolean {
29+ if ( utils . isDummyDevice ( device ) ) return true ; // docs generation: show it
30+ return device . endpoints ?. some ( ( ep : Zh . Endpoint ) => ep . supportsInputCluster ( "msPressureMeasurement" ) ) ;
31+ }
32+
33+ const exposeFn : DefinitionExposesFunction = ( device : Zh . Device | DummyDevice , options : KeyValue ) : Expose [ ] => {
34+ if ( deviceHasPressureCluster ( device ) ) {
35+ // Resolve the original exposes from m.pressure()
36+ const result : Expose [ ] = [ ] ;
37+ for ( const item of base . exposes ?? [ ] ) {
38+ if ( typeof item === "function" ) {
39+ result . push ( ...item ( device , options ) ) ;
40+ } else {
41+ result . push ( item ) ;
42+ }
43+ }
44+ return result ;
45+ }
46+ return [ ] ;
47+ } ;
48+
49+ return {
50+ ...base ,
51+ // Replace static exposes with a dynamic function that checks the cluster
52+ exposes : [ exposeFn ] ,
53+ // Wrap each configure so it only runs when the cluster is present
54+ configure : ( base . configure ?? [ ] ) . map ( ( configureFn ) : Configure => {
55+ return async ( device : Zh . Device , coordinatorEndpoint : Zh . Endpoint , definition : Definition ) => {
56+ if ( deviceHasPressureCluster ( device ) ) {
57+ await configureFn ( device , coordinatorEndpoint , definition ) ;
58+ }
59+ } ;
60+ } ) ,
61+ isModernExtend : true ,
62+ } ;
63+ }
64+
1265interface ThirdAcceleration {
1366 attributes : {
1467 coolDownTime : number ;
@@ -1405,7 +1458,7 @@ export const definitions: DefinitionWithExtend[] = [
14051458 zigbeeModel : [ "3RAP0149BZ" ] ,
14061459 model : "3RAP0149BZ" ,
14071460 vendor : "Third Reality" ,
1408- description : "Smart air pressure sensor " ,
1461+ description : "Smart Filter Sensor " ,
14091462 extend : [
14101463 m . battery ( ) ,
14111464 m . numeric ( {
@@ -1416,7 +1469,7 @@ export const definitions: DefinitionWithExtend[] = [
14161469 description : "Measure dirty level" ,
14171470 access : "STATE_GET" ,
14181471 } ) ,
1419- m . pressure ( ) ,
1472+ conditionalPressure ( ) ,
14201473 ] ,
14211474 ota : true ,
14221475 } ,
0 commit comments