예제 #1
0
function printHomeInformation(Netatmo\Objects\NAHome $home)
{
    !is_null($home->getName()) ? printMessageWithBorder($home->getName()) : printMessageWithBorder($home->getId());
    echo "id: " . $home->getId() . "\n";
    $tz = $home->getTimezone();
    $persons = $home->getPersons();
    if (!empty($persons)) {
        printMessageWithBorder("Persons");
        //print person list
        foreach ($persons as $person) {
            printPersonInformation($person, $tz);
        }
    }
    $events = $home->getEvents();
    if (!empty($events)) {
        printMessageWithBorder('Timeline of Events');
        //print event list
        foreach ($events as $event) {
            printEventInformation($event, $tz);
        }
    }
    $cameras = $home->getCameras();
    if (!empty($cameras)) {
        printMessageWithBorder("Cameras");
        foreach ($cameras as $camera) {
            printCameraInformation($camera);
        }
    }
}
        handleError("An error occured while retrieving last event of " . $person->getPseudo() . "\n");
    }
    if (!empty($eventList)) {
        printMessageWithBorder("Events until last time " . $person->getPseudo() . " was seen");
        foreach ($eventList as $event) {
            printEventInformation($event, $tz);
        }
        // let's retrieve 10 events that happens right before last event of the given person
        $lastIndex = count($eventList) - 1;
        $lastEvent = $eventList[$lastIndex];
        $event = $eventList[0];
        try {
            $response = $client->getNextEvents($home->getId(), $lastEvent->getId(), 10);
            $data = $response->getData();
        } catch (NASDKException $ex) {
            handleError("An error occured while retrieving events: " . $ex->getMessage() . "\n");
        }
        if (!empty($data)) {
            printMessageWithBorder("The 10 events that happened right before " . $person->getPseudo() . " was seen");
            foreach ($data as $event) {
                printEventInformation($event, $tz);
            }
        }
        try {
            printMessageWithBorder("Event's snapshot");
            echo $event->getSnapshot() . "\n";
        } catch (NASDKException $ex) {
            handleError("An error occured while retrieving event's snapshot: " . $ex->getMessage() . "\n");
        }
    }
}