function __construct($deviceKey) { $this->deviceDS = getDeviceDS($deviceKey); $this->type = $this->deviceDS['d_type']; $this->bus = $this->deviceDS['d_bus']; $this->address = $this->deviceDS['d_id']; $this->config = json_decode($this->deviceDS['d_config'], true); $this->deviceHandlerClass = $this->bus . cfg('hal/' . $this->type); $this->deviceHandlerFile = strtolower('hal/' . $this->bus . '-' . cfg('hal/' . $this->type) . '.php'); if (!class_exists($this->deviceHandlerClass)) { if (file_exists($this->deviceHandlerFile)) { $dh = $this->deviceHandlerClass; include $this->deviceHandlerFile; $this->handler = new $dh($this); $this->handler->deviceDS =& $this->deviceDS; $this->handler->config =& $this->config; $this->states = $this->handler->listStates(); } else { logError('Device HAL class not found: ' . $this->deviceHandlerClass . ', looking for file: ' . $this->deviceHandlerFile); } } }
<form action="?" method="post"> <input type="hidden" name="controller" value="<?php echo $_REQUEST['controller']; ?> "/> <input type="hidden" name="action" value="<?php echo $_REQUEST['action']; ?> "/> <input type="hidden" name="key" value="<?php echo $_REQUEST['key']; ?> "/> <?php $doSave = isset($_POST['controller']); $ds = getDeviceDS($_REQUEST['key']); $dev = HMRPC('getDeviceDescription', array($ds['d_id'])); $_REQUEST['actionEvents'] = array(); ?> <table style="margin-top: -8px; margin-bottom: 12px; max-width: 800px; width: 100%;"> <tr> <td style="text-align:right"> <span class="faint">HomeMatic</span> </td> <td width="*"> <b><a href="<?php echo actionUrl('edit', 'devices', array('key' => $_REQUEST['key'])); ?> "><?php echo first($ds['d_name']); ?>
function deviceCommand($deviceKey, $commandType, $value, $by = 'API', $fireEvent = false) { $device = getDeviceDS($deviceKey); if (!approveAction(array('type' => 'deviceCommand', 'device' => $deviceKey, 'deviceType' => $device['d_type'], 'ds' => $device, 'command' => $commandType, 'value' => $value, 'by' => $by))) { return; } if ($device['d_auto'] != 'A' && $GLOBALS['command-mode'] == 'trigger') { return; } $GLOBALS['log'][$device['d_key']] = array('type' => 'deviceCommand', 'device' => $deviceKey, 'param' => $commandType, 'value' => $value); $config = json_decode($device['d_config'], true); if (sizeof($device) > 0 && $device['d_state'] != $value) { if ($device['d_bus'] == 'HE') { $pv = $value + 0; $pv = reviewParams($device, $commandType, $pv); $reqUrl = 'http://localhost:1080/?cmd=update&bus=' . $device['d_bus'] . '¶m=' . $commandType . '&key=' . $device['d_key'] . '&stxt=' . urlencode(first($GLOBALS['command-source'], $by)) . '&id=' . $device['d_id'] . '&value=' . $pv; cqrequest(array(array('url' => $reqUrl))); } else { if ($device['d_bus'] == 'HM') { sendHMCommand($device, $commandType, $value, first($GLOBALS['command-source'], $by), $config, $fireEvent); return; } } $sds = array('si_bus' => $device['d_bus'], 'si_name' => $device['d_id'], 'si_param' => $commandType, 'si_value' => $pv, 'si_time' => time(), 'si_devicekey' => $device['d_key'], 'si_by' => $by, 'si_event' => $GLOBALS['command-source'], 'si_mode' => 'TX', 'si_uid' => $_SESSION['uid'] + 0, 'si_ip' => first($_SERVER['HTTP_X_FORWARDED_FOR'], $_SERVER['REMOTE_ADDR'])); o(db)->commit('stateinfo', $sds); /*WriteToFile('log/stats.'.gmdate('Y-m').'.log', json_encode(array( 'type' => 'dp', 'key' => $device['d_key'], 'id' => $device['d_id'], 'bus' => $device['d_bus'], 'param' => $commandType, 'value' => $pv, 'tr' => 'tx')). chr(10) );*/ $device['d_state'] = $value; $device['d_statustext'] = first($GLOBALS['command-source'], $by); $device['d_statuschanged'] = time(); o(db)->commit('devices', $device); } }
<?php WriteToFile('log/switch.log', 'timer came back: ' . $_POST['data'] . chr(10)); $timerConfig = json_decode($_POST['data'], true); $device = getDeviceDS($timerConfig['key']); if (sizeof($device) > 0) { $dcfg = json_decode($device['d_config'], true); $tmr = $dcfg[$timerConfig['trigger']]; if ($tmr) { $GLOBALS['command-mode'] = 'trigger'; deviceCommand($timerConfig['key'], $timerConfig['param'], $tmr['value'], first($tmr['stxt'], 'API')); } else { WriteToFile('log/error.log', 'timer trigger not found: ' . $timerConfig['trigger'] . chr(10)); } }
function callHandlers($handlers, $data) { foreach (array('', '_rev') as $addressType) { $reverseAction = $addressType == '_rev'; $where = array(); foreach ($handlers as $h) { $where[] = 'e_address' . $addressType . ' = ?'; } foreach (o(db)->get('SELECT * FROM events WHERE (' . implode(' OR ', $where) . ') ORDER BY e_order ASC', $handlers) as $eds) { $GLOBALS['log'][] = 'event handler called: ' . $eds['e_address' . $addressType]; broadcast(array('type' => 'eventHandled', 'address' => $eds['e_address' . $addressType])); $this->ignoreExecution = false; $emitterRoot = $data['device']; $emitterRoot = CutSegment(':', $emitterRoot); if ($emitterRoot != $data['device']) { $emitterRootDS = getDeviceDS($emitterRoot); } else { $emitterRootDS = $data['ds']; } $this->executeScript($eds['e_code'], array('emitter_id' => $data['device'], 'emitter_param' => $data['param'], 'emitter_value' => $data['value'], 'emitter_alias' => $emitterRootDS['d_alias'], 'emitter_root' => $emitterRoot, 'emitter_name' => first($emitterRootDS['d_name'], $emitterRootDS['d_id']), 'emitter' => $data['ds'], 'call' => $data, 'eventDS' => &$eds, 'reverseAction' => $reverseAction, 'event' => $eds['e_address' . $addressType])); if (!$this->ignoreExecution) { o(db)->query('UPDATE events SET e_lastcalled = ' . time() . ' WHERE e_key = ' . $eds['e_key']); } } } return $this; }