示例#1
0
 protected function SetValueBoolean($Ident, $Value)
 {
     $ID = $this->GetIDForIdent($Ident);
     if (GetValueBoolean($ID) != $Value) {
         SetValueBoolean($ID, boolval($Value));
         return true;
     }
     return false;
 }
示例#2
0
文件: orga.php 项目: Spoosie/KH_UniFi
function SetVariable($VarID, $Type, $Value)
{
    switch ($Type) {
        case 0:
            // boolean
            SetValueBoolean($VarID, $Value);
            break;
        case 1:
            // integer
            SetValueInteger($VarID, $Value);
            break;
        case 2:
            // float
            SetValueFloat($VarID, $Value);
            break;
        case 3:
            // string
            SetValueString($VarID, $Value);
            break;
    }
}
示例#3
0
 private function UpdateVariable(ISCP_API_Data $APIData)
 {
     if ($APIData->Data == "N/A") {
         return;
     }
     switch ($APIData->Mapping->VarType) {
         case IPSVarType::vtBoolean:
             $VarID = $this->GetVariable($APIData->APICommand, $APIData->Mapping->VarType, $APIData->Mapping->VarName, $APIData->Mapping->Profile, $APIData->Mapping->EnableAction);
             $Value = ISCP_API_Commands::$BoolValueMapping[$APIData->Data];
             SetValueBoolean($VarID, $Value);
             break;
         case IPSVarType::vtFloat:
             $VarID = $this->GetVariable($APIData->APICommand, $APIData->Mapping->VarType, $APIData->Mapping->VarName, $APIData->Mapping->Profile, $APIData->Mapping->EnableAction);
             $Value = $APIData / 100;
             SetValueFloat($VarID, $Value);
             //                throw new Exception("Float VarType not implemented.");
             break;
         case IPSVarType::vtInteger:
             $VarID = $this->GetVariable($APIData->APICommand, $APIData->Mapping->VarType, $APIData->Mapping->VarName, $APIData->Mapping->Profile, $APIData->Mapping->EnableAction);
             $Value = hexdec($APIData->Data);
             SetValueInteger($VarID, $Value);
             break;
         case IPSVarType::vtString:
             $VarID = $this->GetVariable($APIData->APICommand, $APIData->Mapping->VarType, $APIData->Mapping->VarName, $APIData->Mapping->Profile, $APIData->Mapping->EnableAction);
             $Value = $APIData->Data;
             SetValueString($VarID, $Value);
             break;
         case IPSVarType::vtDualInteger:
             $Prefix = substr($APIData->Data, 0, 1);
             $VarID = $this->GetVariable($APIData->APICommand . $APIData->Mapping->ValuePrefix[$Prefix], IPSVarType::vtInteger, $APIData->Mapping->VarName[$Prefix], $APIData->Mapping->Profile, $APIData->Mapping->EnableAction);
             $Value = $APIData->Mapping->ValueMapping[substr($APIData->Data, 1, 2)];
             SetValueInteger($VarID, $Value);
             if (strlen($APIData->Data) > 3) {
                 $Prefix = substr($APIData->Data, 3, 1);
                 $VarID = $this->GetVariable($APIData->APICommand . $APIData->Mapping->ValuePrefix[$Prefix], IPSVarType::vtInteger, $APIData->Mapping->VarName[$Prefix], $APIData->Mapping->Profile, $APIData->Mapping->EnableAction);
                 $Value = $APIData->Mapping->ValueMapping[substr($APIData->Data, 4, 2)];
                 SetValueInteger($VarID, $Value);
             }
     }
 }
示例#4
0
 private function SetValueBoolean($Ident, $value)
 {
     $id = $this->GetIDForIdent($Ident);
     if (GetValueBoolean($id) != $value) {
         SetValueBoolean($id, $value);
         return true;
     }
     return false;
 }
示例#5
0
 public function PowerOff()
 {
     $address = $this->ReadPropertyString("LEDAdresse");
     $command = "01";
     SetValueBoolean($this->GetIDForIdent('Status'), false);
     return $this->Send_LED($address, $command);
 }
示例#6
0
 public function SetMute($state)
 {
     SetValueBoolean($this->GetIDForIdent('MUTE'), $state);
     $state = $state ? 'On' : 'Off';
     return $this->Request("<Volume><Mute>{$state}</Mute></Volume>", 'PUT');
 }
 /**
  * parsing incoming data along capabilities
  * @param array $data
  */
 private function ParseData($data)
 {
     //
     $caps = $this->GetCaps();
     //$this->debug(__FUNCTION__,print_r($this->all_caps,true));
     foreach (array_keys($caps) as $cap) {
         $ident = $caps[$cap];
         $vid = @$this->GetIDForIdent($ident);
         if ($vid == 0) {
             $this->debug(__FUNCTION__, "Cap {$cap} Ident {$ident}: Variable missed");
             continue;
         }
         if (!isset($data[$cap])) {
             continue;
         }
         $s = $data[$cap];
         switch ($cap) {
             //Integer
             case 'Hum':
                 //hum
             //hum
             case 'RainCounter':
                 //raincounter
             //raincounter
             case 'Press':
                 //pressure
             //pressure
             case 'Forecast':
                 //willi
             //willi
             case 'UV':
                 //UVIndex
             //UVIndex
             case 'Light':
                 //Brightness
             //Brightness
             case 'Level':
                 //level
             //level
             case 'TS':
                 //TimeStamp
             //TimeStamp
             case 'Lost':
                 //lost
             //lost
             case 'Signal':
                 if (strlen($s) == 0) {
                     continue;
                 }
                 $iv = (int) $s;
                 SetValueInteger($vid, $iv);
                 break;
                 //float
             //float
             case 'Temp':
                 //temp
             //temp
             case 'Wind':
                 //wind
             //wind
             case 'WindChill':
                 //wind
             //wind
             case 'WindGust':
                 //wind
             //wind
             case 'WindDir':
                 //wind
             //wind
             case 'Rain':
                 //rain
             //rain
             case 'RainDaily':
                 //rain this day
             //rain this day
             case 'RainHourly':
                 //rain 1h
             //rain 1h
             case 'RainLastDay':
                 //rain 24h
                 if (strlen($s) == 0) {
                     continue;
                 }
                 $fv = (double) $s;
                 SetValueFloat($vid, $fv);
                 break;
                 //String
             //String
             case 'Name':
                 //
                 $st = utf8_decode($s);
                 SetValueString($vid, $st);
                 break;
                 //special
             //special
             case 'IsRaining':
                 //israining
                 if ($s == 'YES') {
                     SetValueBoolean($vid, true);
                     $s = "Its Raining";
                 } else {
                     SetValueBoolean($vid, false);
                     $s = "{$cap}({$vid}): No Rain";
                 }
                 break;
                 //special
             //special
             case 'Storm':
                 //israining
                 if ($s == 'YES') {
                     //is reversed
                     SetValueBoolean($vid, false);
                     $s = "Its Storm";
                 } else {
                     SetValueBoolean($vid, true);
                     $s = "OK";
                 }
                 break;
             case 'Battery':
                 //battery
                 $state = !preg_match("/LOW|WARN/i", $s);
                 //reversed
                 SetValueBoolean($vid, $state);
                 break;
             default:
                 $this->debug(__FUNCTION__, "{$cap} not handled");
         }
         $this->debug(__FUNCTION__, "{$cap}:({$vid})" . $s);
     }
 }
示例#8
0
 private function DecodeIOSample(TXB_API_IO_Sample $IOSample)
 {
     $ActiveDPins = unpack("n", substr($IOSample->Sample, 1, 2))[1];
     $ActiveAPins = ord($IOSample->Sample[3]);
     if ($ActiveDPins != 0) {
         $PinValue = unpack("n", substr($IOSample->Sample, 4, 2))[1];
         foreach ($this->DPin_Name as $Index => $Pin_Name) {
             if ($Pin_Name == '') {
                 continue;
             }
             $Bit = pow(2, $Index);
             if (($ActiveDPins & $Bit) == $Bit) {
                 //                        {$IFDEF DEBUG}        SendData('DPIN','I:'+floattostr(Power(2,ord(i))));{$ENDIF}
                 $VarID = @$this->GetIDForIdent($Pin_Name);
                 if ($VarID === false) {
                     $VarID = $this->RegisterVariableBoolean($Pin_Name, $Pin_Name);
                 }
                 if (($PinValue & $Bit) == $Bit) {
                     //                            {$IFDEF DEBUG}          SendData(DPin_Name[i],'true - Bit:'+inttostr(ord(i)));{$ENDIF}
                     SetValueBoolean($VarID, true);
                 } else {
                     //                            {$IFDEF DEBUG}          SendData(DPin_Name[i],'false - Bit:'+inttostr(ord(i)));{$ENDIF}
                     SetValueBoolean($VarID, false);
                 }
             }
         }
     }
     if ($ActiveAPins != 0) {
         $i = 0;
         foreach ($this->APin_Name as $Index => $Pin_Name) {
             if ($Pin_Name == "") {
                 continue;
             }
             $Bit = pow(2, $Index);
             if (($ActiveAPins & $Bit) == $Bit) {
                 //                    {$IFDEF DEBUG}        SendData('APIN','I:'+floattostr(Power(2,ord(i))));{$ENDIF}
                 $PinAValue = 0;
                 $PinAValue = unpack("n", substr($IOSample->Sample, 6 + $i * 2, 2))[1];
                 $PinAValue = $PinAValue * 1.171875;
                 if ($Pin_Name == 'VSS') {
                     $VarID = @$this->GetIDForIdent($Pin_Name);
                     if ($VarID === false) {
                         $VarID = $this->RegisterVariableFloat('VSS', 'VSS', '~Volt');
                     }
                     SetValueFloat($VarID, $PinAValue / 1000);
                 } else {
                     $VarID = @$this->GetIDForIdent($Pin_Name);
                     if ($VarID === false) {
                         $VarID = $this->RegisterVariableInteger($Pin_Name, $Pin_Name);
                     }
                     SetValueInteger($VarID, $PinAValue);
                 }
                 $i++;
             }
         }
     }
 }
示例#9
0
 private function SetValueBoolean($Ident, $value)
 {
     $id = $this->GetIDForIdent($Ident);
     if (GetValueBoolean($id) != $value) {
         SetValueBoolean($id, $value);
     }
 }
示例#10
0
 protected function ELROPowerSetState($state)
 {
     SetValueBoolean($this->GetIDForIdent('STATE'), $state);
     return $this->SetPowerState($state);
 }
示例#11
0
 public function PowerOff() {
   SetValueBoolean($this->GetIDForIdent('STATE'), false);
   return $this->SetPowerState(1);
 }
示例#12
0
  public function SetValue($key, $value) {
    $stateId = IPS_GetObjectIDByIdent('STATE', $this->InstanceID);
    $cmId = IPS_GetObjectIDByIdent('COLOR_MODE', $this->InstanceID);
    $ctId = @IPS_GetObjectIDByIdent('COLOR_TEMPERATURE', $this->InstanceID);
    $briId = IPS_GetObjectIDByIdent('BRIGHTNESS', $this->InstanceID);
    $satId = @IPS_GetObjectIDByIdent('SATURATION', $this->InstanceID);
    $hueId = @IPS_GetObjectIDByIdent('HUE', $this->InstanceID);
    $colorId = @IPS_GetObjectIDByIdent('COLOR', $this->InstanceID);

    $stateValue = GetValueBoolean($stateId);
    $cmValue = $cmId ? GetValueInteger($cmId) : 0;
    $ctValue = $ctId ? (500 - round(347 * GetValueInteger($ctId) / 100)) : 0;
    $briValue = round(GetValueInteger($briId)*2.54);
    $satValue = $satId ? round(GetValueInteger($satId)*2.54) : 0;
    $hueValue = $hueId ? GetValueInteger($hueId) : 0;
    $colorValue = $colorId ? GetValueInteger($colorId) : 0;

    switch ($key) {
      case 'STATE':
        $stateNewValue = $value;
        break;
      case 'COLOR':
        $colorNewValue = $value;
        $stateNewValue = true;
        $hex = str_pad(dechex($value), 6, 0, STR_PAD_LEFT);
        $hsv = $this->HEX2HSV($hex);
        SetValueInteger($colorId, $value);
        $hueNewValue = $hsv['h'];
        $briNewValue = $hsv['v'];
        $satNewValue = $hsv['s'];
        $cmNewValue = 0;
        break;
      case 'BRIGHTNESS':
        $briNewValue = $value;
        $stateNewValue = true;
        if (IPS_GetProperty($this->InstanceID, 'LightFeatures') != 3) {
          if ($cmValue == '0') {
            $newHex = $this->HSV2HEX($hueValue, $satValue, $briNewValue);
            SetValueInteger($colorId, hexdec($newHex));
            $hueNewValue = $hueValue;
            $satNewValue = $satValue;
          } else {
            $ctNewValue = $ctValue;
          }
        }
        break;
      case 'SATURATION':
        $cmNewValue = 0;
        $satNewValue = $value;
        $stateNewValue = true;
        $newHex = $this->HSV2HEX($hueValue, $satNewValue, $briValue);
        SetValueInteger($colorId, hexdec($newHex));
        $hueNewValue = $hueValue;
        $briNewValue = $briValue;
        break;
      case 'COLOR_TEMPERATURE':
        $cmNewValue = 1;
        $ctNewValue = $value;
        $briNewValue = $briValue;
        break;
      case 'COLOR_MODE':
        $cmNewValue = $value;
        $stateNewValue = true;
        if ($cmNewValue == 1) {
          $ctNewValue = $ctValue;
          IPS_SetHidden($colorId, true);
          IPS_SetHidden($ctId, false);
          IPS_SetHidden($satId, true);
        } else {
          $hueNewValue = $hueValue;
          $satNewValue = $satValue;
          $briNewValue = $briValue;
          $newHex = $this->HSV2HEX($hueValue, $satValue, $briValue);
          SetValueInteger($colorId, hexdec($newHex));
          IPS_SetHidden($colorId, false);
          IPS_SetHidden($ctId, true);
          IPS_SetHidden($satId, false);
        }
        break;
    }

    $changes = array();
    if (isset($stateNewValue)) {
      SetValueBoolean($stateId, $stateNewValue);
      $changes['on'] = $stateNewValue;
    }
    if (isset($hueNewValue)) {
      SetValueInteger($hueId, $hueNewValue);
      $changes['hue'] = $hueNewValue;
    }
    if (isset($satNewValue)) {
      SetValueInteger($satId, round($satNewValue * 100 / 254));
      $changes['sat'] = $satNewValue;
    }
    if (isset($briNewValue)) {
      SetValueInteger($briId, round($briNewValue * 100 / 254));
      $changes['bri'] = $briNewValue;
    }
    if (isset($ctNewValue)) {
      SetValueInteger($ctId, 100 - round(($ctNewValue - 153) * 100 / 347));
      $changes['ct'] = $ctNewValue;
    }
    if (isset($cmNewValue)) {
      SetValueInteger($cmId, $cmNewValue);
      $changes['colormode'] = $cmNewValue == 1 ? 'ct' : 'hs';
    }

    $lightId = $this->ReadPropertyInteger("LightId");
    return HUE_Request($this->GetBridge(), "/lights/$lightId/state", $changes);
  }
 /**
  * handle incoming data along capabilities
  * @param array $data
  */
 private function ParseData($data)
 {
     //
     $this->debug(__FUNCTION__, 'Parse');
     $caps = $this->GetCaps();
     foreach (array_keys($caps) as $cap) {
         $ident = $caps[$cap];
         $vid = @$this->GetIDForIdent($ident);
         if ($vid == 0) {
             $this->debug(__FUNCTION__, "Cap {$cap} Ident {$ident}: Variable missed");
             continue;
         }
         if (!isset($data[$cap])) {
             continue;
         }
         $s = $data[$cap];
         $this->debug(__FUNCTION__, "Handle {$cap} ({$vid}) = {$s}");
         switch ($cap) {
             //boolean types
             case 'Alert':
                 //Status
                 $state = $s != 'YES';
                 //reversed display
                 SetValueBoolean($vid, $state);
                 break;
                 //Counter types with factor
             //Counter types with factor
             case 'Counter':
                 $iv = (int) $s;
                 switch ($this->GetType()) {
                     case 'EMWZ':
                         $last = GetValueInteger($vid);
                         $opid = $this->GetIDForIdent('OCounter');
                         if ($opid) {
                             $offset = GetValueInteger($opid);
                             if ($last > $iv) {
                                 $offset += 65535;
                                 $this->debug(__FUNCTION__, "EMWZ:Increase Offset by 65535: {$offset}");
                                 SetValueInteger($opid, $offset);
                             }
                             $iv = $iv + $offset;
                         } else {
                             $this->debug(__FUNCTION__, "EMWZ:No vid for OCounter");
                         }
                         $pvid = $this->GetIDForIdent('TPower');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 150;
                             }
                             $val = $iv * (1 / $factor);
                             //counter%ticks pro kw
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMWZ:TPower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMWZ:No vid for TPower");
                         }
                         break;
                     case 'EMEM':
                         $last = GetValueInteger($vid);
                         $opid = $this->GetIDForIdent('OCounter');
                         if ($opid) {
                             $offset = GetValueInteger($opid);
                             if ($last > $iv) {
                                 $offset += 65535;
                                 $this->debug(__FUNCTION__, "EMEM:Increase Offset by 65535: {$offset}");
                                 SetValueInteger($opid, $offset);
                             }
                             $iv = $iv + $offset;
                         } else {
                             $this->debug(__FUNCTION__, "EMEM:No vid for OCounter");
                         }
                         $pvid = $this->GetIDForIdent('TPower');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 100;
                             }
                             $val = $iv * (1 / $factor);
                             //counter%ticks pro kw
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMEM:TPower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMEM:No vid for TPower");
                         }
                         break;
                     case 'EMGZ':
                         $pvid = $this->GetIDForIdent('TGas');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 100;
                             }
                             $val = $iv * (1 / $factor);
                             //Counter%ticks pro m3
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMGZ:TGas:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMGZ:No vid for TGas");
                         }
                         break;
                 }
                 SetValueInteger($vid, $iv);
                 break;
             case 'ACounter':
                 $iv = (int) $s;
                 switch ($this->GetType()) {
                     case 'EMWZ':
                         $pvid = $this->GetIDForIdent('APower');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 150;
                             }
                             $val = $iv * (1 / $factor) * 1000;
                             //W statt KW
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMWZ:APower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMWZ:No vid for APower");
                         }
                         break;
                     case 'EMEM':
                         $pvid = $this->GetIDForIdent('APower');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 100;
                             }
                             $val = $iv * (1 / $factor) * 1000;
                             //W statt KW
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMEM:APower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMEM:No vid for APower");
                         }
                         break;
                     case 'EMGZ':
                         $pvid = $this->GetIDForIdent('AGas');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 100;
                             }
                             $val = $iv * (1 / $factor);
                             //m3
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMGZ:AGas:({$pvid})=" . $val . " F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMGZ:No vid for AGas");
                         }
                         break;
                 }
                 SetValueInteger($vid, $iv);
                 break;
             case 'PCounter':
                 $iv = (int) $s;
                 switch ($this->GetType()) {
                     case 'EMWZ':
                         $pvid = $this->GetIDForIdent('PPower');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 150;
                             }
                             $val = $iv * (1 / $factor) * 1000;
                             //W statt KW
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMWZ:PPower:({$pvid})=" . $val . "F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMWZ:No vid for PPower");
                         }
                         break;
                     case 'EMEM':
                         $pvid = $this->GetIDForIdent('PPower');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 100;
                             }
                             $val = $iv * (1 / $factor) * 1000;
                             //W statt KW
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMEM:PPower:({$pvid})=" . $val . " F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMEM:No vid for PPower");
                         }
                         break;
                     case 'EMGZ':
                         $pvid = $this->GetIDForIdent('PGas');
                         if ($pvid) {
                             $factor = $this->GetCounterFactor();
                             if ($factor == 0) {
                                 $factor = 100;
                             }
                             $val = $iv * (1 / $factor);
                             //m3
                             SetValueFloat($pvid, $val);
                             $this->debug(__FUNCTION__, "EMGZ:PGas:({$pvid})=" . $val . " F:{$factor}(" . $this->GetCounterFactor() . ")");
                         } else {
                             $this->debug(__FUNCTION__, "EMGZ:No vid for PGas");
                         }
                         break;
                 }
                 SetValueInteger($vid, $iv);
                 break;
                 //int types
             //int types
             case 'Signal':
                 //RSSI
             //RSSI
             case 'LoadPct':
                 //Load in Pct
             //Load in Pct
             case 'Charged':
                 //Charged in Pct
             //Charged in Pct
             case 'OCounter':
                 //old counter
             //old counter
             case 'TS':
                 //Timestamp
                 $iv = (int) $s;
                 SetValueInteger($vid, $iv);
                 break;
                 //float types with factor
             //float types with factor
             case 'AGas':
                 //Actual
             //Actual
             case 'TGas':
                 //Total
             //Total
             case 'PGas':
                 //Peak
             //Peak
             case 'APower':
                 //Actual
             //Actual
             case 'PPower':
                 //Peak
             //Peak
             case 'TPower':
                 //Total
             //Total
             case 'AWater':
                 //Actual
             //Actual
             case 'TWater':
                 //Total
             //Total
             case 'PWater':
                 //Peak
                 $fv = (double) $s;
                 $factor = $this->GetCounterFactor();
                 $val = $fv * $factor;
                 SetValueFloat($vid, $val);
                 break;
                 //float types
             //float types
             case 'VoltIn':
                 //InputVolt
             //InputVolt
             case 'VoltOut':
                 //Output Volt
             //Output Volt
             case 'Nominal':
                 //Nominal Power
             //Nominal Power
             case 'Watt':
                 //Absolute Load
             //Absolute Load
             case 'Freq':
                 //Frequency
             //Frequency
             case 'TimeLeft':
                 //TimeLeft
                 $fv = (double) $s;
                 SetValueFloat($vid, $fv);
                 break;
                 //string types
             //string types
             case 'Name':
             case 'Status':
                 $st = utf8_decode($s);
                 SetValueString($vid, $st);
                 break;
             default:
                 $this->debug(__FUNCTION__, "{$cap} not handled");
         }
         //switch
         $this->debug(__FUNCTION__, "{$cap}:({$vid})=" . $s);
     }
     //for
 }
示例#14
0
 protected function SetPowerState($state)
 {
     if ($state === true) {
         $adress = $this->ReadPropertyString("LEDAdresse");
         $command = "0C0";
         SetValueBoolean($this->GetIDForIdent('Status'), $state);
         return $this->Send_LED($adress, $command);
     } else {
         $adress = $this->ReadPropertyString("LEDAdresse");
         $command = "0C0";
         SetValueBoolean($this->GetIDForIdent('Status'), $state);
         return $this->Send_LED($adress, $command);
     }
 }
示例#15
0
	protected function SetValueBoolean($Ident, $value)
	{
		$id = $this->GetIDForIdent($Ident);
		SetValueBoolean($id, $value);
	}
 /**
  * handle incoming data along capabilities
  * @param array $data
  */
 private function ParseData($data)
 {
     //
     $caps = $this->GetCaps();
     //$this->debug(__FUNCTION__,print_r($this->all_caps,true));
     foreach (array_keys($caps) as $cap) {
         $ident = $caps[$cap];
         $vid = @$this->GetIDForIdent($ident);
         if ($vid == 0) {
             $this->debug(__FUNCTION__, "Cap {$cap} Ident {$ident}: Variable missed");
             continue;
         }
         if (!isset($data[$cap])) {
             continue;
         }
         $s = $data[$cap];
         switch ($cap) {
             //integer
             case 'TS':
                 //Timestamp
             //Timestamp
             case 'Signal':
                 //RSSI
             //RSSI
             case 'Timer':
                 //Duration code
             //Duration code
             case 'Dimmer':
                 //intensity 100%
             //intensity 100%
             case 'Shutter':
                 //intensity 100%
                 $iv = (int) $s;
                 SetValueInteger($vid, $iv);
                 break;
                 //String
             //String
             case 'Name':
                 //Duration code
                 $st = utf8_decode($s);
                 SetValueString($vid, $st);
                 break;
                 //special
             //special
             case 'Switch':
                 //Status
                 $state = $this->SwitchStatus($s);
                 SetValueBoolean($vid, $state);
                 break;
             case 'Lock':
                 //Status
                 $state = preg_match("/YES|CLOSE|OK/i", $s);
                 //reversed
                 SetValueBoolean($vid, $state);
                 break;
             case 'Alert':
                 //Status
                 $state = !preg_match("/YES|ALERT/i", $s);
                 //reversed
                 SetValueBoolean($vid, $state);
                 break;
             case 'Battery':
                 //battery
                 $state = !preg_match("/LOW|WARN/i", $s);
                 //reversed
                 SetValueBoolean($vid, $state);
                 break;
             case 'FS20':
                 //fs20 mode decoding
                 $state = false;
                 $intensity = 0;
                 $timer = 0;
                 $acode = '';
                 $actioncode = '';
                 $code = utf8_decode($s);
                 $this->debug(__FUNCTION__, "FS20 Code " . strToHex($code));
                 $action = $code[0];
                 $ext = ord($code[1]);
                 $tvid = @$this->GetIDForIdent($caps['Timer']);
                 $dvid = @$this->GetIDForIdent($caps['Dimmer']);
                 $swid = @$this->GetIDForIdent($caps['Switch']);
                 $avid = @$this->GetIDForIdent($caps['TimerActionCode']);
                 $this->debug(__FUNCTION__, "FS20 Vars S:{$swid},D:{$dvid},T:{$tvid},A:{$avid}");
                 if ($dvid) {
                     $intensity = GetValueInteger($dvid);
                 }
                 if ($swid) {
                     $state = GetValueBoolean($swid);
                 }
                 if ($tvid) {
                     $timer = GetValueInteger($tvid);
                 }
                 if ($avid) {
                     $acode = GetValueString($avid);
                 }
                 $ac = ord($action) & 0x1f;
                 $timed = ($action & 0x20) > 0;
                 $this->debug(__FUNCTION__, "FS20 AC:" . $ac . "PrevD:{$intensity}, PrevS:" . ($state ? "On" : "Off"));
                 switch ($ac) {
                     case 0:
                         //off
                         if ($timed) {
                             $actioncode = 'Switch:Off';
                         } else {
                             $state = false;
                         }
                         break;
                     case $ac < 0xf:
                         //Dim to value
                         $intensity = FHZ_helper::fs20_intensity_percent($action & 0xf);
                         $state = true;
                         if ($timed) {
                             $actioncode = 'Switch:Off';
                         }
                         break;
                     case 0x10:
                         //on full
                         $state = true;
                         $intensity = 100;
                         if ($timed) {
                             $actioncode = 'Switch:Off';
                         }
                         break;
                     case 0x11:
                         //on with old value
                         $state = true;
                         if ($intensity == 0) {
                             $intensity = 100;
                         }
                         if ($timed) {
                             $actioncode = 'Switch:Off';
                         }
                         break;
                     case 0x12:
                         $state = !GetValueBoolean($swid);
                         //toggle
                         break;
                     case 0x13:
                         //dimup
                         $steps = FHZ_helper::fs20_intensity_steps($intensity);
                         $intensity = FHZ_helper::fs20_intensity_percent($steps + 1);
                         $state = true;
                         break;
                     case 0x14:
                         //dimdown
                         if ($intensity == 0) {
                             $intensity = 100;
                         }
                         $steps = FHZ_helper::fs20_intensity_steps($intensity);
                         $intensity = FHZ_helper::fs20_intensity_percent($steps - 1);
                         if ($intensity == 0) {
                             $state = false;
                         }
                         break;
                     case 0x18:
                         //off-for-timer
                         $state = 'Off';
                         $actioncode = 'Switch:On';
                         break;
                     case 0x19:
                         //on-for-timer than out
                         $state = true;
                         $actioncode = 'Switch:Off';
                         break;
                     case 0x1a:
                         //on-old-for-timer than out
                         $state = true;
                         $actioncode = 'Switch:Off';
                         break;
                     case 0x1c:
                         //ramp-on-time (time to reach the desired dim value on dimmers)
                         $state = true;
                         $actioncode = "Dimmer:{$intensity}";
                         break;
                     case 0x1d:
                         //ramp-off-time (time to reach the off state on dimmers)
                         $actioncode = 'Switch:Off;Dimmer:0';
                         break;
                     case 0x1e:
                         //on-old-for-timer-prev", // old val for timer, then go to prev. state
                         $actioncode = "Switch:" . ($state ? 'On' : 'Off');
                         $state = true;
                         break;
                     case 0x1f:
                         //on-100-for-timer-prev", // 100% for timer, then go to previous state
                         //new intensity will be the old one
                         $action = "Switch:" . ($state ? 'On' : 'Off') . ";Dimmer:{$intensity}";
                         $intensity = 100;
                         $state = true;
                         break;
                     case 0x15:
                         //dimupdown, no value changes
                     //dimupdown, no value changes
                     case 0x16:
                         //Set Timer
                     //Set Timer
                     case 0x17:
                         //nop
                     //nop
                     case 0x1b:
                         //rese
                         break;
                 }
                 $new_timer = FHZ_helper::fs20_times($ext);
                 $this->debug(__FUNCTION__, "State:" . ($state ? "ON" : "OFF") . ", Dimmer:{$intensity}%,Timer: {$new_timer},ActionCode: '{$actioncode}'");
                 //state
                 if ($swid) {
                     SetValueBoolean($swid, $state);
                 }
                 //dimmer
                 if ($dvid) {
                     SetValueInteger($dvid, $intensity);
                 }
                 //timer
                 if ($tvid) {
                     $this->SetTimerInterval('DeviceTimer', $new_timer * 1000);
                     SetValueInteger($tvid, $new_timer);
                 }
                 //action
                 if ($avid && $acode != $actioncode) {
                     SetValueString($avid, $actioncode);
                 }
                 //log
                 $actiontext = FHZ_helper::$fs20_codes[strToHex($action)];
                 if ($ext > 0) {
                     $actiontext .= ', Timer:' . $timer;
                 }
                 $text = sprintf('%s (%s)', $actiontext, strToHex($code));
                 if ($vid) {
                     SetValueString($vid, $text);
                 }
                 $this->debug(__FUNCTION__, "Action:" . $text);
                 break;
             default:
                 $this->debug(__FUNCTION__, "{$cap} not handled");
         }
         $this->debug(__FUNCTION__, "{$cap}:({$vid})" . $s);
     }
 }
示例#17
0
 public function PowerOff()
 {
     if ($this->ReadPropertyString('ITType') == "Dimmer") {
         SetValueInteger($this->GetIDForIdent('Dimmer'), 0);
     }
     SetValueBoolean($this->GetIDForIdent('STATE'), false);
     $action = "6";
     return $this->SendCommand($action);
 }
示例#18
0
 public function SetPowerState(boolean $state)
 {
     if ($state === true) {
         SetValueBoolean($this->GetIDForIdent('Status'), $state);
         //PowerOn abfragen
         $PowerOnCode = $this->ReadPropertyInteger("PowerOnCode");
         return $this->SendIRCode($PowerOnCode);
     } else {
         SetValueBoolean($this->GetIDForIdent('Status'), $state);
         //PowerOff abfragen
         $PowerOffCode = $this->ReadPropertyInteger("PowerOffCode");
         return $this->SendIRCode($PowerOffCode);
     }
 }
 /**
  * Set status variable isPolling
  * @param bool $val
  */
 private function SetPolling($val)
 {
     $id = $this->GetIDForIdent('isPolling');
     SetValueBoolean($id, $val);
 }
示例#20
0
 protected function SendCommand($command)
 {
     $FS20 = $this->Calculate();
     $ip_aiogateway = $this->GetIPGateway();
     IPS_LogMessage("FS20 Adresse:", $FS20);
     IPS_LogMessage("FS20 Command:", $command);
     $GatewayPassword = $this->GetPassword();
     switch ($command) {
         case "1000":
             //An
             SetValueBoolean($this->GetIDForIdent('Status'), true);
             if (IPS_StatusVariableExists($this->InstanceID, "Dimmer")) {
                 SetValueInteger($this->GetIDForIdent('Dimmer'), 10);
             }
             break;
         case "0000":
             //Aus
             SetValueBoolean($this->GetIDForIdent('Status'), false);
             if (IPS_StatusVariableExists($this->InstanceID, "Dimmer")) {
                 SetValueInteger($this->GetIDForIdent('Dimmer'), 0);
             }
             break;
         case "DIM0":
             //0
             SetValueBoolean($this->GetIDForIdent('Status'), false);
             SetValueInteger($this->GetIDForIdent('Dimmer'), 0);
             $command = "0000";
             break;
         case "0200":
             //10
             SetValueInteger($this->GetIDForIdent('Dimmer'), 1);
             break;
         case "0300":
             //20
             SetValueInteger($this->GetIDForIdent('Dimmer'), 2);
             break;
         case "0500":
             //30
             SetValueInteger($this->GetIDForIdent('Dimmer'), 3);
             break;
         case "0600":
             //40
             SetValueInteger($this->GetIDForIdent('Dimmer'), 4);
             break;
         case "0800":
             //50
             SetValueInteger($this->GetIDForIdent('Dimmer'), 5);
             break;
         case "0900":
             //60
             SetValueInteger($this->GetIDForIdent('Dimmer'), 6);
             break;
         case "0B00":
             //70
             SetValueInteger($this->GetIDForIdent('Dimmer'), 7);
             break;
         case "0D00":
             //80
             SetValueInteger($this->GetIDForIdent('Dimmer'), 8);
             break;
         case "0E00":
             //90
             SetValueInteger($this->GetIDForIdent('Dimmer'), 9);
             break;
         case "DIM100":
             //100
             SetValueBoolean($this->GetIDForIdent('Status'), true);
             SetValueInteger($this->GetIDForIdent('Dimmer'), 10);
             $command = "1000";
             break;
     }
     if ($GatewayPassword !== "") {
         $gwcheck = file_get_contents("http://" . $this->GetIPGateway() . "/command?XC_USER=user&XC_PASS="******"&XC_FNC=SendSC&type=FS20&data=" . $FS20 . $command);
         IPS_LogMessage("AIOGateway:", "Senden an Gateway mit Passwort");
     } else {
         $gwcheck = file_get_contents("http://" . $this->GetIPGateway() . "/command?XC_FNC=SendSC&type=FS20&data=" . $FS20 . $command);
     }
     if ($gwcheck == "{XC_SUC}") {
         $this->response = true;
     } elseif ($gwcheck == "{XC_AUTH}") {
         $this->response = false;
         echo "Keine Authentifizierung möglich. Das Passwort für das Gateway ist falsch.";
     }
     return $this->response;
 }
示例#21
0
 /**
  * ReceiveData
  * @param string $JSONString
  */
 public function ReceiveData($JSONString)
 {
     // Empfangene Daten
     $Data = json_decode($JSONString);
     //IPS_LogMessage("ReceiveData", utf8_decode($JSONString));
     if ($Data->DataID === "{449015FB-6717-4BB6-9F95-F69945CE1272}") {
         $Data = json_decode($Data->Buffer, true);
         if ($this->ReadPropertyInteger("DataType") === 0) {
             if ($this->ReadPropertyBoolean("ReadOnly")) {
                 $Value = @$Data["FC2"][$this->ReadPropertyInteger("Address")];
             } else {
                 $Value = @$Data["FC1"][$this->ReadPropertyInteger("Address")];
             }
             if (isset($Value)) {
                 if (GetValue($this->GetIDForIdent("Value")) != $Value) {
                     SetValueBoolean($this->GetIDForIdent("Value"), $Value);
                 }
             }
         } else {
             if ($this->ReadPropertyBoolean("ReadOnly")) {
                 $Bytes = @$Data["FC4"][$this->ReadPropertyInteger("Address")];
             } else {
                 $Bytes = @$Data["FC3"][$this->ReadPropertyInteger("Address")];
             }
             if (isset($Bytes)) {
                 switch ($this->ReadPropertyInteger("DataType")) {
                     case 1:
                     case 2:
                     case 3:
                         $Value = PhpType::bytes2unsignedInt($Bytes);
                         break;
                     case 4:
                     case 5:
                     case 6:
                     case 8:
                         $Value = PhpType::bytes2signedInt($Bytes);
                         break;
                     case 7:
                     case 9:
                         $Value = PhpType::bytes2float($Bytes);
                         break;
                 }
                 if (GetValue($this->GetIDForIdent("Value")) != $Value) {
                     SetValue($this->GetIDForIdent("Value"), $Value);
                 }
                 if ($this->ReadPropertyString("Math") != "" and $this->ReadPropertyBoolean("ReadOnly")) {
                     $Value = $this->Math($Value . $this->ReadPropertyString("Math"));
                     if (GetValue($this->GetIDForIdent("ValueMath")) != $Value) {
                         SetValue($this->GetIDForIdent("ValueMath"), $Value);
                     }
                 }
             }
         }
     }
 }
示例#22
0
 private function WriteResponse($Command, $Value)
 {
     if (is_array($Command)) {
         $Command = implode(' ', $Command);
     }
     if (is_array($Value)) {
         $Value = implode(' ', $Value);
     }
     $EventID = $this->GetIDForIdent('WaitForResponse');
     if (!GetValueBoolean($EventID)) {
         return false;
     }
     $BufferID = $this->GetIDForIdent('BufferOUT');
     if ($Command == GetValueString($BufferID)) {
         if ($this->lock('BufferOut')) {
             SetValueString($BufferID, trim($Value));
             SetValueBoolean($EventID, false);
             $this->unlock('BufferOut');
             return true;
         }
         return 'Error on write ResponseBuffer';
     }
     return false;
 }
示例#23
0
 /**
  * Setzt die Status-Variable.
  *
  * @access protected
  * @param bool $NewState Der neue Wert der Statusvariable
  */
 protected function SetStateVar(boole $NewState)
 {
     if ($this->ReadPropertyBoolean('HasState')) {
         if (!IPS_VariableExists(@$this->GetIDForIdent('STATE'))) {
             $this->MaintainVariable('STATE', 'STATE', vtBoolean, '~Alert', 0, true);
         }
         SetValueBoolean($this->GetIDForIdent('STATE'), $NewState);
     }
 }