Page 1 of 1

Device types - PHP example

Posted: Thu Aug 08, 2019 4:04 am
by atchoo
Hello,

In the API's Documentation, the "Defined Constants" section is a bit lacking with regards to practical use, and the "general" section is not very helpful at all, since everything is so out of context. Jumping right into an advanced lecture regarding how to convert a UUID with suffixes and prefixes and multiple leading zeros to and from JSON (!) makes NO sense at all without a real context, even for experienced developers. It's like trying to explain advanced rocket science to someone who doesn't know what a rocket is, and why on earth you would need one.

The "Defined Constants" page show a lot of icons, but you don't mention how to make use of them. Is people suppose to just guess that there is such a thing as a Telldus web font?

Well, there is (look in my PHP example for the URLs), and the syntax is as follows:

Code: Select all


<i class="telldus-icons">XYZ</i> //where XYZ is a keyword for each icon, that you can find if you "inspect" the page source of that mentioned URL.

But since I did all that dirty work anyway, here's the icon keywords:

Code: Select all


device-alt, alarm, group, location, doorclosed, dooropen, bulb, lock, music, gauge, monitoring, sensor, user, remotecontrol, speaker, outlet, thermotstat, buttonon, buttonoff, curtain

You're most welcome <3

Edit: There is a similar set for the "rooms" on http://api.telldus.com/documentation/constRoomIcon. However, there is no documentation on where, when and how to use those either. Time will tell, I suppose.

Anyway, I wrote a PHP example as some kind of supplement for http://api.telldus.com/documentation/constDeviceType, just to demonstrate how to use this rather sparse information table.

Code: Select all


<!-- ©2019 Andreas Lorentsen -->
<html>
<head>
<style>
@font-face {
 font-family: 'telldusicons';
 src:  url('https://cdn.live.telldus.com/fonts/telldusicons.eot');
 src:  url('https://cdn.live.telldus.com/fonts/telldusicons.eot#iefix') format('embedded-opentype'),
   url('https://cdn.live.telldus.com/fonts/telldusicons.ttf') format('truetype'),
   url('https://cdn.live.telldus.com/fonts/telldusicons.woff') format('woff'),
   url('https://cdn.live.telldus.com/fonts/telldusicons.svg#telldusicons') format('svg');
 font-weight: normal;
 font-style: normal;
}
      
.telldus-icons {
 font-family: 'telldusicons' !important;
 speak: none;
 font-style: normal;
 font-weight: normal;
 font-variant: normal;
 text-transform: none;
 line-height: 1;
 font-size: 200%; /* Setting the super tiny web font to 2x size, for the occation */
 letter-spacing: 0;
 -webkit-font-feature-settings: "liga";
 -moz-font-feature-settings: "liga=1";
 -moz-font-feature-settings: "liga";
 -ms-font-feature-settings: "liga" 1;
 font-feature-settings: "liga";
 -webkit-font-variant-ligatures: discretionary-ligatures;
 font-variant-ligatures: discretionary-ligatures;
 -webkit-font-smoothing: antialiased;
 -moz-osx-font-smoothing: grayscale;
}
</style>
</head>
<body>    
<?php
$deviceInfo = array
(
array("name" => "Unknown/Other","code" => "0000000-0001-1000-2005-ACCA54000000","icon" => "device-alt"),
array("name" => "Alarm Sensor","code" => "0000001-0001-1000-2005-ACCA54000000","icon" => "alarm"),
array("name" => "Container","code" => "0000002-0001-1000-2005-ACCA54000000","icon" => "group"),
array("name" => "Controller","code" => "0000003-0001-1000-2005-ACCA54000000","icon" => "location"),
array("name" => "Door/Window","code" => "0000004-0001-1000-2005-ACCA54000000","icon" => "doorclosed"),
array("name" => "Light","code" => "0000005-0001-1000-2005-ACCA54000000","icon" => "bulb"),
array("name" => "Lock","code" => "0000006-0001-1000-2005-ACCA54000000","icon" => "lock"),
array("name" => "Media","code" => "0000007-0001-1000-2005-ACCA54000000","icon" => "music"),
array("name" => "Meter","code" => "0000008-0001-1000-2005-ACCA54000000","icon" => "gauge"),
array("name" => "Motion","code" => "0000009-0001-1000-2005-ACCA54000000","icon" => "monitoring"),
array("name" => "On/Off sensor","code" => "000000A-0001-1000-2005-ACCA54000000","icon" => "sensor"),
array("name" => "Person","code" => "000000B-0001-1000-2005-ACCA54000000","icon" => "user"),
array("name" => "Remote Control","code" => "000000C-0001-1000-2005-ACCA54000000","icon" => "remotecontrol"),
array("name" => "Sensor","code" => "000000D-0001-1000-2005-ACCA54000000","icon" => "sensor"),
array("name" => "Smoke Sensor","code" => "000000E-0001-1000-2005-ACCA54000000","icon" => "alarm"),
array("name" => "Speaker","code" => "000000F-0001-1000-2005-ACCA54000000","icon" => "speaker"),
array("name" => "Switch/Outlet","code" => "0000010-0001-1000-2005-ACCA54000000","icon" => "outlet"),
array("name" => "Thermostat","code" => "0000011-0001-1000-2005-ACCA54000000","icon" => "thermostat"),
array("name" => "Virtual","code" => "0000012-0001-1000-2005-ACCA54000000","icon" => "buttonoff"),
array("name" => "Window Cover","code" => "0000013-0001-1000-2005-ACCA54000000","icon" => "curtain"),
array("name" => "Projector Screen","code" => "0000014-0001-1000-2005-ACCA54000000","icon" => "curtain")
);

// let's say we made a query to the API at "/devices/list" or "device/info", and assigned the variable $deviceType to whatever the API returned as "deviceType".
// then we could do this:
    
$deviceType = "0000001-0001-1000-2005-ACCA54000000"; // This line is here only to provide an example value, since we haven't queried the API
    
$i = "-1";
foreach($deviceInfo as $key=>$somedevice) {
$i++;
    if(in_array($deviceType, $deviceInfo[$i])) {
        $deviceIcon = $deviceInfo[$i]["icon"];      //setting variables for icon and name of device type, so it is easier to use
        $deviceCategory = $deviceInfo[$i]["name"];
    }
}
?>
    <h2><i class="telldus-icons"><?php echo $deviceIcon?></i></h2> <!-- The "i" class is a direct reference to the Telldus web font in the "Style" tag in the head section -->
    <p>This is most certainly a <a href="https://telldus.com/?s=<?php echo $deviceCategory?>" target="_blank"><?php echo $deviceCategory?></a> device.</p> 
</body>
</html>

I hope that was a bit easier to grasp.

Best regards,

Andreas