-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpenHabRESTAction.class.php
76 lines (56 loc) · 2.19 KB
/
OpenHabRESTAction.class.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
class OpenHabRESTAction extends HttpPostAction {
private $eventName;
private $key;
private $VARIABLENAME_OPENHAB_ITEM_NAME = "%itemName%";
private $VARIABLENAME_OPENHAB_COMMAND = "%command%";
private $UNFORMATTED_OPENHAB_URL = "http://192.168.1.37:8080/rest/items/%s";
public function __construct($id, $name, $itemName = null, $command = ""){
parent::__construct($id, $name, sprintf($this->UNFORMATTED_OPENHAB_URL,
$this->VARIABLENAME_OPENHAB_ITEM_NAME), array(), $this->VARIABLENAME_OPENHAB_COMMAND);
$this->setItemName($itemName);
$this->setCommand($command);
}
protected function before() {
$this->addHttpHeader("Content-Type: text/plain");
parent::before();
}
static public function createActionCreationFormBuilder($clazz, $action = null){
$builder = CreationFormBuilder::createForAction($clazz, $action);
$builder->addClass("openHabREST");
$builder->addLabel("actionName", "Name");
$builder->addInput("actionName", "text", is_null($action) ? null : $action->getName());
$builder->addLabel("itemName", "Item Name");
$builder->addInput("itemName", "text", is_null($action) ? null : $action->getItemName());
$builder->addLabel("command", "Command");
$builder->addInput("command", "text", is_null($action) ? null : $action->getCommand());
$builder->addSubmit(is_null($action) || is_null($action->getId()) ? "Erzeugen" : "Änderung speichern");
return $builder;
}
static public function createByFormResponse($response) {
$actionId = -1;
if (isset($response["actionId"]) && is_numeric($response["actionId"])) {
$actionId = $response["actionId"];
}
$name = $response["actionName"];
$itemName = $response["itemName"];
$command = $response["command"];
$action = new OpenHabRESTAction($actionId, $name, $itemName, $command);
return $action;
}
public function setCommand($command) {
$this->command = $command;
$this->setVariable($this->VARIABLENAME_OPENHAB_COMMAND, $command);
}
public function getCommand() {
return $this->command;
}
public function setItemName($itemName) {
$this->itemName = $itemName;
$this->setVariable($this->VARIABLENAME_OPENHAB_ITEM_NAME, $itemName);
}
public function getItemName() {
return $this->itemName;
}
}
?>