35 lines
876 B
PHP
35 lines
876 B
PHP
<?php
|
|
|
|
require_once __DIR__ . '/../common/auth.php';
|
|
require_once __DIR__ . '/../common/ha.php';
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
header('Cache-Control: no-store');
|
|
|
|
custom_require_auth();
|
|
|
|
$config = custom_config();
|
|
$entity = $config['entities']['wake_switch'];
|
|
|
|
if (isset($_GET['status'])) {
|
|
$state = custom_ha_state('seoul_wol', $entity);
|
|
if (!$state || !isset($state['state'])) {
|
|
custom_json(['result' => 'error'], 502);
|
|
}
|
|
|
|
custom_json([
|
|
'result' => 'ok',
|
|
'state' => $state['state'],
|
|
]);
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
$res = custom_ha_request('seoul_wol', 'POST', '/services/switch/turn_on', [
|
|
'entity_id' => $entity,
|
|
]);
|
|
|
|
custom_json(['result' => $res === null ? 'error' : 'sent'], $res === null ? 502 : 200);
|
|
}
|
|
|
|
custom_json(['result' => 'invalid_request'], 400);
|