Skip to content

Commit

Permalink
Add Smappee
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenmoors committed Nov 10, 2018
1 parent 20dcc8d commit 9345707
Show file tree
Hide file tree
Showing 114 changed files with 18,901 additions and 16 deletions.
252 changes: 252 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added composer.phar
Binary file not shown.
49 changes: 49 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
define('PATH_DATA', __DIR__.'/../../data');

$auth = $_GET['auth'];
if ($auth != 'dldqz33dZZaqww.lenme2zWWzv') {
die();
}

require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/src/SmappeeLocal.php';

// Smappee username and password.
define('SMAPPEE_HOST', '192.168.0.164');
define('SMAPPEE_PASSWORD', 'admin');


use Coogle\SmappeeLocal;

$smappee = new SmappeeLocal(SMAPPEE_HOST, SMAPPEE_PASSWORD);

// Logon
$smappee->login();

$plug = $_GET['plug'];
$toggleFile = PATH_DATA.'/smappee-plug-'.$plug.'.state';
if ($_GET['state'] == '-1') {
// Toggle
if (file_exists($toggleFile)) {
$state = 0;
} else {
$state = 1;
}
} else {
// On or off depending on the request
$state = $_GET['state'];
}

// Set $plug to $state
$smappee->setComfortPlug($plug, $state);

if ($state == 1) {
touch($toggleFile);
} else {
if (file_exists($toggleFile)) {
unlink($toggleFile);
}
}

print "<pre>Set $plug to $state kept state in $toggleFile</pre>";
30 changes: 14 additions & 16 deletions src/SmappeeLocal.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ protected function _postCall($uri, $body)

public function login()
{
$password = $this->getPassword();
$password = $this->getPassword();

if(empty($password)) {
throw new \Exception("You must set the Smappee password to login");
}
$result = $this->_postCall('/gateway/apipublic/logon', $password);
if(empty($password)) {
throw new \Exception("You must set the Smappee password to login");
}
$result = $this->_postCall('/gateway/apipublic/logon', $password);
}

public function getInstantaneous()
Expand Down Expand Up @@ -116,18 +116,16 @@ public function listComfortPlugs()

public function setComfortPlug($plug_id, $plug_status)
{
if ($plug_status) {
$plug_action = 'ON';
} else {
$plug_action = 'OFF';
}
$body = 'control,{"controllableNodeId":"'.$plug_id.'","action":"'.$plug_action.'"}';
$result = $this->_postCall('/gateway/apipublic/commandControlPublic', $body);
if ($plug_status) {
$plug_action = 'ON';
} else {
$plug_action = 'OFF';
}
$body = 'control,{"controllableNodeId":"'.$plug_id.'","action":"'.$plug_action.'"}';
$result = $this->_postCall('/gateway/apipublic/commandControlPublic', $body);

$data = json_decode($result->getBody(), true);

var_dump($data);


$retval = [];

foreach($data as $item) {
Expand Down
3 changes: 3 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
curl -H "Content-Type: application/json" -X POST -d "admin" http://192.168.0.163/gateway/apipublic/logon
curl -H "Content-Type: application/json" -X POST -d "control,controlId=0|1" http://192.168.0.163/gateway/apipublic/commandControlPublic
7 changes: 7 additions & 0 deletions vendor/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer' . '/autoload_real.php';

return ComposerAutoloaderInit33d9ac2f289708d132212cc50c8ed709::getLoader();
Loading

0 comments on commit 9345707

Please sign in to comment.