-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorder.php
186 lines (165 loc) · 5.07 KB
/
order.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
require_once 'config.php';
require_once 'classes/Calendar.class.php';
require_once 'classes/Domoticz.class.php';
require_once 'classes/Heating.class.php';
require_once 'classes/SpeechRecognize.class.php';
require_once 'classes/SpeechRecognize.' . SPEAK_LANGUAGE . '.class.php';
require_once 'classes/PhilipsTv.class.php';
require_once 'classes/TvPrograms.class.php';
$isJson = array_key_exists('json', $_GET);
if ($isJson)
{
header('Content-Type: application/json; charset=UTF-8');
echo '{';
}
else
{
header('Content-Type: text/xml; charset=UTF-8');
echo '<?xml version="1.0" encoding="UTF-8" ?><responses>';
}
if (array_key_exists('msg', $_GET))
{
$SR_SENTENCES = array();
$SR_SENTENCES[] = array('text' => '^EAGGER_1$', 'action' => 'cbEagger');
$SR_SENTENCES[] = array('text' => '^TO_LEAVE$', 'action' => 'cbLeaveHouse');
$SR_SENTENCES[] = array('text' => '^TO_LEAVE HOUSE$', 'action' => 'cbLeaveHouse');
$SR_SENTENCES[] = array('text' => '^TO_LEAVE ([0-9]+) DURATION_DAY$', 'action' => 'cbLeaveHouseDay');
$SR_SENTENCES[] = array('text' => '^TO_LEAVE ([0-9]+) DURATION_WEEK$', 'action' => 'cbLeaveHouseWeek');
$SR_SENTENCES[] = array('text' => '^TO_LEAVE ([0-9]+) DURATION_MONTH$', 'action' => 'cbLeaveHouseMonth');
$SR_SENTENCES[] = array('text' => '^TO_WATCH .*MOVIE ([0-9]+)$', 'action' => 'cbWatchMovie');
$SR_SENTENCES[] = array('text' => '^TO_WATCH ([0-9]+)$', 'action' => 'cbWatchTV');
$SR_SENTENCES[] = array('text' => '^TO_DO HEATING ([0-9]+)$', 'action' => 'cbHeatingAt');
$SR_SENTENCES[] = array('text' => '^COLD$', 'action' => 'cbHeatingMore');
$SR_SENTENCES[] = array('text' => '^HEAT$', 'action' => 'cbHeatingLess');
$SR_SENTENCES[] = array('text' => '^HOW HOUSE$', 'action' => 'cbHowHouse');
$SR_SENTENCES[] = array('text' => '^WHAT NIGHT', 'action' => 'cbTvProgramTonight');
$SR_SENTENCES[] = array('text' => '^GOOD NIGHT$', 'action' => 'cbGoodNight');
$sp = new SpeechRecognize($SR_SENTENCES, $SR_WORDS);
if (!$sp->parseAndExecute($_GET['msg']))
tell('Je n\'ai pas compris votre demande...');
}
else
tell('At your command, my master.');
if ($isJson)
echo '}';
else
echo '</responses>';
exit (0);
function tell($msg)
{
global $isJson;
if ($isJson)
print '"tell": "' . $msg . '"';
else
print '<tell>' . $msg . '</tell>';
}
function cbEagger()
{
tell('Coucou les amis !');
}
function cbLeaveHouseDay($matches)
{
cbLeaveHouseHeat($matches[1] * 1);
}
function cbLeaveHouseWeek($matches)
{
cbLeaveHouseHeat($matches[1] * 7);
}
function cbLeaveHouseMonth($matches)
{
cbLeaveHouseHeat($matches[1] * 30);
}
function cbLeaveHouseHeat($days)
{
$heating = new Heating(true);
$calendar = new Calendar();
$dates = $calendar->getDatesFromNow($days);
$temp = $heating->setBestTempratureForDates($dates);
tell("Température réglée à $temp degré pour une durée de $days jours.");
}
function cbLeaveHouse($matches)
{
$sent = '';
if (PhilipsTv::stopTv(PHILIPS_TV))
$sent .= 'J\'ai éteins la télévision. ';
$sent .= 'Au revoir.';
tell($sent);
}
function cbGoodNight($matches)
{
$sent = '';
if (PhilipsTv::watch(PHILIPS_TV, '2', 20, false) && PhilipsTv::stopTv(PHILIPS_TV))
$sent .= 'J\'ai éteins la télévision. ';
$sent .= 'Bonne nuit.';
tell($sent);
}
function cbWatchMovie($matches)
{
$channel = PhilipsTv::watch(PHILIPS_TV, $matches[1], 30, true);
if ($channel)
tell("Passage à la chaine $channel.");
else
tell("La télé n'est pas allumée.");
}
function cbWatchTV($matches)
{
$channel = PhilipsTv::watch(PHILIPS_TV, $matches[1], 25, false);
if ($channel)
tell("Passage à la chaine $channel.");
else
tell("La télé n'est pas allumée.");
}
function cbHeatingAt($matches)
{
$heating = new Heating(true);
$newTemp = $matches[1];
if ($heating->setCurrentTemperature($newTemp))
tell("Le chauffage est régle à $newTemp degré.");
else
tell("Le chauffage reste réglé à " . $heating->getCurrentTemperature() . " degré car la température demandée n'est pas connue.");
}
function cbHeatingMore($matches)
{
cbHeating(1);
}
function cbHeatingLess($matches)
{
cbHeating(-1);
}
function cbHeating($offset)
{
$heating = new Heating(true);
$newTemp = $heating->addToCurrentTemperature($offset);
if (is_numeric($newTemp))
tell("Le chauffage est réglé à $newTemp degré.");
else if ($offset > 0)
tell("Le chauffage est déjà au maximum !");
else if ($offset < 0)
tell("Le chauffage est déjà au minimum !");
}
function cbHowHouse($matches)
{
$temp = Domoticz::getHomeTemperature();
$locale = localeconv();
if ($locale)
$temp = number_format($temp, (is_float($temp) ? 1 : 0), $locale['decimal_point'], $locale['thousands_sep']);
if ($temp)
tell("La température ambiante est de $temp degré.");
else
tell("Impossible de récupérer la température...");
}
function cbTvProgramTonight($matches)
{
$programs = TvPrograms::whatTonight();
if ($programs)
{
$tellMe = '';
foreach ($programs as $programChannel => $program)
$tellMe .= "Sur $programChannel, il y a " . $program['title'] . ". ";
tell("Voici le programme télé: $tellMe");
}
else
tell("Impossible d'avoir le programme télé...");
}
?>