Example #1
0
 function setState($value, $reason)
 {
     // pins have to be specified in order UP:STOP:DOWN
     $this->pins = explode(':', $this->deviceDS['d_id']);
     if ($value == 'closed') {
         $pinIdx = 2;
     } else {
         $pinIdx = 0;
     }
     SendGPIOCommand($this->deviceDS, $this->pins[$pinIdx], 1, $reason);
     recordDeviceStatus($this->deviceDS, $this->pins[$pinIdx], $value, $reason);
     return $value;
 }
Example #2
0
function sendHMCommand($device, $commandType, $value, $reason = 'unknown', $config = array(), $fireEvent = false)
{
    if (sizeof($device) > 0 && $device['d_state'] != $value) {
        $pv = reviewParams($device, $commandType, $value);
        if ($commandType == 'STATE') {
            $hpv = $pv == 0 ? 'false' : 'true';
        } else {
            $hpv = $pv;
        }
        // send HM commands directly, to save time
        $result = HMRPC('setValue', array($device['d_id'], $commandType, $hpv));
        queryCommandServer(array('cmd' => 'busmessage', 'fireevent' => $fireEvent ? 'Y' : 'N', 'data' => json_encode(array('key' => $device['d_key'], 'type' => $device['d_bus'], 'device' => $device['d_id'], 'param' => $commandType, 'value' => $pv, 'stxt' => $reason))));
        recordDeviceStatus($device, $commandType, $pv, $reason);
        $tmr = $config['timer_' . $commandType . '_' . $pv];
        if ($tmr) {
            cqrequest(array(array('url' => 'http://localhost:1080/?cmd=timer' . '&name=' . $device['d_key'] . '&countDown=' . $tmr['seconds'] . '&stxt=' . urlencode($reason) . '&param=' . urlencode($commandType) . '&key=' . $device['d_key'] . '&id=' . $device['d_id'] . '&trigger=' . ('timer_' . $commandType . '_' . $pv))));
        }
    }
    return $result;
}