PHP_SMART_HOME_V3/app/api/WidgetApi.php

18 lines
483 B
PHP
Raw Normal View History

2020-05-24 17:35:19 +00:00
<?php
class WidgetApi extends ApiController{
2020-05-24 17:37:29 +00:00
public function run($subDeviceId){
2020-05-24 17:35:19 +00:00
//$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;
}
2020-05-26 19:01:03 +00:00
$this->response(['value' => $response]);
2020-05-24 17:35:19 +00:00
}
}