static function getEmittableEventsByDevice($deviceDS) { $paramSet = array(); if ($deviceDS['d_bus'] == 'HM') { foreach (HMRPC('getParamsetDescription', array($deviceDS['d_id'], 'VALUES')) as $dk => $dp) { $isEvent = $dp['OPERATIONS'] & 4; if ($isEvent) { $dp['EXTTYPE'] = $dp['TYPE']; if ($dp['TYPE'] == 'ENUM') { $exp = array(); foreach ($dp['VALUE_LIST'] as $ek => $ev) { if ($ev) { $exp[] = $ek . '=' . $ev; } } $dp['EXTTYPE'] = implode(', ', $exp); } $paramSet[$dk] = $dp; if ($dk == 'PRESS_SHORT') { $paramSet['PRESSED'] = $dp; } if ($dk == 'SET_TEMPERATURE') { $paramSet['THERMOSTAT'] = $dp; } } } } return $paramSet; }
function ajax_cli() { $cmd = explode(' ', trim($_REQUEST['q'])); $method = array_shift($cmd); if (substr($method, 0, 3) == 'hm.') { print_r(HMRPC(substr($method, 3), $cmd)); if ($method == 'hm.setInstallMode') { print 'You have 60 seconds to pair your device. After completing the pairing, click here to create an entry for it: <a href="' . actionUrl('pair', 'devices') . '">Pairing Complete</a>.'; } } else { profile_point('starting command'); eval(trim($_REQUEST['q'])); profile_point('command executed'); print chr(10); print_r($GLOBALS['profiler_log']); } }
?> ) </td> <td width="*"> <?php echo getOps($ps['OPERATIONS']); ?> </td> </tr><?php } } ?> </table><?php if (sizeof($saveP) > 0) { print '<pre>New parameters have been saved: '; print json_encode($saveP); print_r(HMRPC('putParamset', array($ds['d_id'], $psetType, $saveP))); //print_r($_POST); print '</pre>'; } /*?><pre><? print_r($pdes); ?></pre><?*/ } /* ?><pre><? print_r($dev); ?></pre><? */ ?> <input type="submit" value="Save"/></form>
<?php echo $this->_getSubmenu2(); $this->devices = array(); foreach (o(db)->get('SELECT * FROM devices ORDER BY d_type, d_key DESC') as $dds) { $this->devices[$dds['d_bus'] . ':' . $dds['d_id']] = $dds; } $this->hmDevices = HMRPC('listDevices', array()); foreach ($this->hmDevices as $h) { switch ($h['TYPE']) { case 'KEY': if (!isset($this->devices['HM:' . $h['ADDRESS']])) { // unknown device, make new dataset $dds = array('d_bus' => 'HM', 'd_type' => 'Key', 'd_room' => 'unknown', 'd_name' => 'New Key ' . date('Y-m-d H:i:s'), 'd_id' => $h['ADDRESS']); $dds['d_key'] = o(db)->commit('devices', $dds); $this->devices['HM:' . $h['ADDRESS']] = $dds; } $this->devices['HM:' . $h['ADDRESS']]['info'] = $h; break; case 'BLIND': case 'SWITCH': if (!isset($this->devices['HM:' . $h['ADDRESS']])) { // unknown device, make new dataset $dds = array('d_bus' => 'HM', 'd_type' => $h['TYPE'] == 'BLIND' ? 'Blinds' : 'Light', 'd_room' => 'unknown', 'd_name' => 'New ' . ($h['TYPE'] == 'BLIND' ? 'Blinds' : 'Switch') . ' ' . date('Y-m-d H:i:s'), 'd_id' => $h['ADDRESS']); $dds['d_key'] = o(db)->commit('devices', $dds); $this->devices['HM:' . $h['ADDRESS']] = $dds; } $this->devices['HM:' . $h['ADDRESS']]['info'] = $h; break; default:
<?php $editable = array('d_bus' => 'Bus System', 'd_id' => 'Identifier', 'd_type' => 'Type', 'd_icon' => 'Icon', 'd_room' => 'Room', 'd_name' => 'Name', 'd_alias' => 'Alias'); $doSave = isset($_POST['controller']); $ds = getDeviceDS($_REQUEST['key']); $dev = HMRPC('getDeviceDescription', array($ds['d_id'])); $paramSet = H2EventManager::getEmittableEventsByDevice($ds); $_REQUEST['actionEvents'] = array(); $related = array(); $idnr = $ds['d_id']; $idroot = CutSegment(':', $idnr); foreach (o(db)->get('SELECT d_key,d_id,d_alias,d_type FROM devices WHERE d_id LIKE "' . $idroot . '%" ORDER BY d_id') as $dds) { $related[] = '<a href="' . actionUrl('edit', 'devices', array('key' => $dds['d_key'])) . '" style="' . ($dds['d_key'] == $ds['d_key'] ? 'font-weight:bold;' : '') . '">' . htmlspecialchars(first($dds['d_alias'], $dds['d_type'])) . ' ' . $dds['d_id'] . '</a>'; } if ($_POST['key']) { foreach ($editable as $fn => $fncap) { $ds[$fn] = $_POST[$fn]; } o(db)->commit('devices', $ds); header('location: ' . actionUrl('show')); die; } $eventList = H2EventManager::getEventsByDevice($ds); $eventTargetList = H2EventManager::getEventsByTarget($ds); $groupList = H2GroupManager::getGroupsByDevice($ds);
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) . '¶m=' . urlencode($commandType) . '&key=' . $device['d_key'] . '&id=' . $device['d_id'] . '&trigger=' . ('timer_' . $commandType . '_' . $pv)))); } } return $result; }