@@ -33,7 +33,7 @@ const HomeMaticPowerMeterAccessory = require(path.join(__dirname, 'HomeMaticPowe
3333
3434class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
3535 initAccessoryService ( Service ) {
36- this . log . debug ( '[PMSWITCH] initAccessoryService')
36+ this . debugLog ( ' initAccessoryService')
3737 this . service = this . getService ( new Service . Outlet ( this . _name ) )
3838 this . service . addOptionalCharacteristic ( this . eve . Characteristic . TotalConsumption )
3939 this . service . addOptionalCharacteristic ( this . eve . Characteristic . ElectricCurrent )
@@ -48,22 +48,28 @@ class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
4848 super . publishServices ( Service , Characteristic )
4949 let self = this
5050 let readOnly = this . isReadOnly ( )
51+ let onTime = this . getDeviceSettings ( ) . OnTime
5152
5253 if ( this . getDataPointNameFromSettings ( 'switch' , null ) ) {
53- this . log . debug ( '[PMSWITCH] adding isOn isOnCharacteristic')
54+ this . debugLog ( ' adding isOn isOnCharacteristic')
5455 this . isOnCharacteristic = this . service . getCharacteristic ( Characteristic . On )
5556 this . isOnCharacteristic . on ( 'get' , async ( callback ) => {
56- self . log . debug ( '[PMSWITCH] get state fetch CCU State')
57+ self . debugLog ( ' get state fetch CCU State')
5758
5859 let state = await self . getValueForDataPointNameWithSettingsKey ( 'switch' , null , true )
59- self . log . debug ( '[PMSWITCH] get state %s', state )
60+ self . debugLog ( ' get state %s', state )
6061 self . currentStatus = self . isTrue ( state )
6162 callback ( null , self . currentStatus )
6263 } )
6364
64- this . isOnCharacteristic . on ( 'set' , ( value , callback ) => {
65- self . log . debug ( '[PMSWITCH] set %s', value )
65+ this . isOnCharacteristic . on ( 'set' , async ( value , callback ) => {
66+ self . debugLog ( ' set %s', value )
6667 if ( ! readOnly ) {
68+ if ( ( self . isTrue ( value ) ) && ( onTime ) && ( parseInt ( onTime ) > 0 ) ) {
69+ self . debugLog ( 'set onTime %s seconds' , onTime )
70+ await self . setValueForDataPointNameWithSettingsKey ( 'ontime' , null , onTime )
71+ }
72+
6773 self . setValueForDataPointNameWithSettingsKey ( 'switch' , null , value )
6874 } else {
6975 // check the state 1 sec later to reset the homekit state
@@ -81,7 +87,7 @@ class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
8187 // }
8288
8389 this . registerAddressWithSettingsKeyForEventProcessingAtAccessory ( 'switch' , null , ( newValue ) => {
84- self . log . debug ( '[PMSWITCH] event state %s', newValue )
90+ self . debugLog ( ' event state %s', newValue )
8591 self . currentStatus = self . isTrue ( newValue )
8692 if ( self . isTrue ( newValue ) ) {
8793 self . updateLastActivation ( )
@@ -115,6 +121,7 @@ class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
115121 '*' : {
116122 roChannel : 1 ,
117123 switch : '1.STATE' ,
124+ ontime : '1.ON_TIME' ,
118125 power : 'POWER' ,
119126 current : 'CURRENT' ,
120127 voltage : 'VOLTAGE' ,
@@ -132,6 +139,12 @@ class HomeMaticPowerMeterSwitchAccessory extends HomeMaticPowerMeterAccessory {
132139 default : 'Power' ,
133140 label : 'Logging for' ,
134141 hint : 'Eve is only able to log on option.'
142+ } ,
143+ 'OnTime' : {
144+ type : 'number' ,
145+ default : 0 ,
146+ label : 'On Time' ,
147+ hint : 'HAP will switch off this device automatically after the given seconds. Set this to 0 to turn off this feature.'
135148 }
136149 }
137150 }
0 commit comments