Skip to content

Commit 4306727

Browse files
authored
Merge pull request #2 from strfl89/testing
Move from Constants to parameters in constructor for Trådfri Gateway Config
2 parents e98282e + 80c6576 commit 4306727

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.cfg
2+
*config*.php

general.php

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
<?php
22

3-
//require_once('ikea-smart-home.config.php');
4-
require_once('define.php');
3+
require_once('defines.php');
54

65
class tradfri
76
{
87

9-
//IP Address of Trådfri Gateway
10-
const TRADFRIIP = '<IP-Address>';
11-
//API User Trådfri Gateway
12-
const USER = '<User>';
13-
//API Key for User
14-
const SECRETKEY = '<Key>';
8+
private $gateway;
9+
10+
function __construct($user, $secret, $gwip){
11+
12+
$this->gateway['user'] = $user;
13+
$this->gateway['secretkey'] = $secret;
14+
$this->gateway['ip'] = $gwip;
15+
16+
}
1517

1618
function query($path){
1719

18-
$cmd = "coap-client -m get -u '".self::USER."' -k '".self::SECRETKEY."' 'coaps://".self::TRADFRIIP.":5684/$path'";
20+
$cmd = "coap-client -m get -u '{$this->gateway['user']}' -k '{$this->gateway['secretkey']}' 'coaps://{$this->gateway['ip']}:5684/{$path}'";
1921
$process = proc_open($cmd, [STDOUT => ['pipe', 'w'], STDERR => ['pipe', 'w']], $output);
2022

2123
//read the outputs
@@ -36,7 +38,7 @@ function query($path){
3638
}
3739

3840
function action($method, $payload, $path){
39-
$cmd = "coap-client -m {$method} -u '".self::USER."' -k '".self::SECRETKEY."' -e '{$payload}' 'coaps://".self::TRADFRIIP.":5684/$path'";
41+
$cmd = "coap-client -m {$method} -u '{$this->gateway['user']}' -k '{$this->gateway['secretkey']}' -e '{$payload}' 'coaps://{$this->gateway['ip']}:5684/{$path}'";
4042
exec($cmd);
4143

4244
}

0 commit comments

Comments
 (0)