Exemplo n.º 1
0
 private function devInfo($message)
 {
     $found = false;
     $count = tdGetNumberOfDevices();
     $deviceId = $message->bodyItem('device');
     for ($i = 0; $i < $count; ++$i) {
         if (tdGetDeviceId($i) == $deviceId) {
             $found = true;
             break;
         }
     }
     $msg = new xPLMessage(xPLMessage::xplstat);
     $msg->setMessageSchemeIdentifier('lighting.devinfo');
     $msg->addBodyItem('network', $message->bodyItem('network'));
     $msg->addBodyItem('device', $deviceId);
     $msg->setTarget('*');
     $msg->setSource($this->_thisDevice->deviceName());
     if ($msg->bodyItem('network') == '1' && $found) {
         $methods = tdMethods($deviceId, TELLDUS_TURNON | TELLDUS_TURNOFF | TELLDUS_DIM);
         $msg->addBodyItem('status', 'ok');
         $msg->addBodyItem('name', tdGetName($deviceId));
         $msg->addBodyItem('report-on-manual', 'false');
         $msg->addBodyItem('channel-count', '1');
         $msg->addBodyItem('primary-channel', '1');
         $msg->addBodyItem('channel', sprintf('1,%s,0,0', $methods & TELLDUS_DIM ? 'true' : 'false'));
         $msg->addBodyItem('scene-count', '0');
     } else {
         $msg->addBodyItem('status', 'not-found');
     }
     $this->sendMessage($msg);
     return true;
 }
Exemplo n.º 2
0
<?php

if (!extension_loaded('telldus')) {
    dl('telldus.' . PHP_SHLIB_SUFFIX);
}
$devices = tdGetNumberOfDevices();
printf("Devices: %d\n", $devices);
$allMethods = TELLDUS_TURNON | TELLDUS_TURNOFF | TELLDUS_BELL | TELLDUS_DIM;
for ($i = 0; $i < $devices; ++$i) {
    $id = tdGetDeviceId($i);
    $name = utf8_encode(tdGetName($id));
    printf("%s - %s\n", $id, $name);
    $methods = tdMethods($id, $allMethods);
    if ($methods & TELLDUS_TURNON) {
        echo " * TurnOn\n";
        tdTurnOn($id);
        sleep(1);
    }
    if ($methods & TELLDUS_TURNOFF) {
        echo " * TurnOff\n";
        tdTurnOff($id);
        sleep(1);
    }
    if ($methods & TELLDUS_BELL) {
        echo " * Bell\n";
        tdBell($id);
        sleep(1);
    }
    if ($methods & TELLDUS_TOGGLE) {
        echo " * Toggle\n";
    }