Skip to content
Permalink
Browse files

Minor fixes

* Simple Devices: dimmer fix
* Simple Devices: homebridge minor update
  • Loading branch information...
sergejey committed Apr 16, 2019
1 parent 49171c9 commit 6e6a095beff49699f9d420edff44408639eaf478
@@ -11,12 +11,21 @@
$maxWork=$this->getProperty('maxWork');
if ($level>0) {
$this->setProperty('status', 1);
$this->setProperty('levelSaved',$level);
if (!$this->getProperty('status')) {
$this->setProperty('status', 1, false);
}
if ($minWork!=$maxWork) {
$levelWork=$minWork+round(($maxWork-$minWork)*$level/100);
$this->setProperty('levelWork',(int)$levelWork);
DebMes("Level updated to ".$level,'dimming');
$levelWork=round($minWork+round(($maxWork-$minWork)*$level/100));
if ($this->getProperty('levelWork')!=$levelWork) {
DebMes("Setting new levelWork to ".(int)$levelWork,'dimming');
$this->setProperty('levelWork',(int)$levelWork);
}
}
} else {
$this->setProperty('status', 0);
if ($this->getProperty('status')) {
$this->setProperty('status', 0);
}
$this->setProperty('levelWork',(int)$minWork);
}
@@ -4,9 +4,11 @@
$minWork=$this->getProperty('minWork');
$maxWork=$this->getProperty('maxWork');
$levelWork=$this->getProperty('levelWork'); //
DebMes("Levelwork updated to ".$levelWork,'dimming');
if ($minWork!=$maxWork) {
$new_level=round((($levelWork-$minWork)/($maxWork-$minWork))*100);
if ($new_level!=$level) {
$this->setProperty('level',$new_level,true);
DebMes("Setting new level to ".$new_level,'dimming');
$this->setProperty('level',$new_level);
}
}
}
@@ -0,0 +1,8 @@
<?php
$status = $this->getProperty('status');
$level=$this->getProperty('level');
$levelSaved=$this->getProperty('levelSaved');
if ($status>0 && !$level && $levelSaved) {
$this->setProperty('level',$levelSaved);
}
@@ -120,11 +120,13 @@
'CLASS'=>'SDimmers',
'PROPERTIES'=>array(
'level'=>array('DESCRIPTION'=>'Current brightness level','ONCHANGE'=>'levelUpdated','DATA_KEY'=>1),
'levelSaved'=>array('DESCRIPTION'=>'Latest level saved'),
'levelWork'=>array('DESCRIPTION'=>'Brightness level (work)','ONCHANGE'=>'levelWorkUpdated'),
'minWork'=>array('DESCRIPTION'=>'Min level (work)','_CONFIG_TYPE'=>'num','_CONFIG_HELP'=>'SdDimmerMinMax'),
'maxWork'=>array('DESCRIPTION'=>'Max level (work)','_CONFIG_TYPE'=>'num','_CONFIG_HELP'=>'SdDimmerMinMax'),
),
'METHODS'=>array(
'statusUpdated'=>array('DESCRIPTION'=>'Status Updated'),
'levelUpdated'=>array('DESCRIPTION'=>'Level Updated'),
'levelWorkUpdated'=>array('DESCRIPTION'=>'Level Work Updated'),
'turnOn'=>array('DESCRIPTION'=>LANG_DEVICES_TURN_ON,'_CONFIG_SHOW'=>1),
@@ -58,23 +58,23 @@
sg('HomeBridge.to_add',json_encode($payload));
$payload['characteristic'] = 'MotionDetected';
$payload['value']=gg($devices[$i]['LINKED_OBJECT'].'.status');
$payload['value']=(int)gg($devices[$i]['LINKED_OBJECT'].'.status');
sg('HomeBridge.to_set',json_encode($payload));
break;
case 'smoke':
$payload['service']='SmokeSensor';
sg('HomeBridge.to_add',json_encode($payload));
$payload['characteristic'] = 'SmokeDetected';
$payload['value']=gg($devices[$i]['LINKED_OBJECT'].'.status');
$payload['value']=(int)gg($devices[$i]['LINKED_OBJECT'].'.status');
sg('HomeBridge.to_set',json_encode($payload));
break;
case 'leak':
$payload['service']='LeakSensor';
sg('HomeBridge.to_add',json_encode($payload));
$payload['characteristic'] = 'LeakDetected';
$payload['value']=gg($devices[$i]['LINKED_OBJECT'].'.status');
$payload['value']=(int)gg($devices[$i]['LINKED_OBJECT'].'.status');
sg('HomeBridge.to_set',json_encode($payload));
break;
case 'button':
@@ -86,15 +86,15 @@
sg('HomeBridge.to_add',json_encode($payload));
$payload['characteristic'] = 'CurrentAmbientLightLevel';
$payload['value']=gg($devices[$i]['LINKED_OBJECT'].'.value');
$payload['value']=(int)gg($devices[$i]['LINKED_OBJECT'].'.value');
sg('HomeBridge.to_set',json_encode($payload));
break;
case 'openclose':
$payload['service']='ContactSensor';
sg('HomeBridge.to_add',json_encode($payload));
$payload['characteristic'] = 'ContactSensorState';
$payload['value']=gg($devices[$i]['LINKED_OBJECT'].'.ncno') == 'nc' ? 1 - gg($devices[$i]['LINKED_OBJECT'].'.status') : gg($devices[$i]['LINKED_OBJECT'].'.status');
$payload['value']=(int)gg($devices[$i]['LINKED_OBJECT'].'.ncno') == 'nc' ? 1 - gg($devices[$i]['LINKED_OBJECT'].'.status') : gg($devices[$i]['LINKED_OBJECT'].'.status');
sg('HomeBridge.to_set',json_encode($payload));
break;
case 'dimmer':
@@ -108,7 +108,7 @@
}
sg('HomeBridge.to_set',json_encode($payload));
$payload['characteristic'] = 'Brightness';
$payload['value']=gg($devices[$i]['LINKED_OBJECT'].'.level');
$payload['value']=(int)gg($devices[$i]['LINKED_OBJECT'].'.level');
sg('HomeBridge.to_set',json_encode($payload));
break;
case 'rgb':

0 comments on commit 6e6a095

Please sign in to comment.
You can’t perform that action at this time.