PHP_SMART_HOME_V3/app/api/WidgetApi.php
2020-05-26 21:47:36 +02:00

38 lines
882 B
PHP

<?php
class WidgetApi extends ApiController{
public function run($subDeviceId){
//$this->requireAuth();
$response = null;
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
if ($subDeviceData['type'] == 'on/off'){
$lastValue = RecordManager::getLastRecord($subDeviceData['subdevice_id'])['value'];
RecordManager::create($subDeviceData['device_id'], 'on/off', !$lastValue);
$response = !$lastValue;
}
$this->response(['value' => $response]);
}
public function check($subDeviceId){
//$this->requireAuth();
$response = null;
$lastRecord = RecordManager::getLastRecord($subDeviceId);
$response = [
'executet' => $lastRecord['execuded'],
'value' => $lastRecord['value'],
];
$this->response($response);
}
public function detail($subDeviceId){
//$this->requireAuth();
$response = null;
$this->response($response);
}
}