diff --git a/server/ControlScripts/OfficeRoomScope.php b/server/ControlScripts/OfficeRoomScope.php new file mode 100644 index 0000000..f86b4bd --- /dev/null +++ b/server/ControlScripts/OfficeRoomScope.php @@ -0,0 +1,54 @@ + add_action_script([ + "alias" => "computer_table_lamp_on", + "name" => "ВКЛ комп. лампу", + "icon" => '', + "description" => "Включить настольную компьютерную лампу", + "author" => "Eugene Sukhodolskiy" + ], function($params) { + return $this -> lamp_switch("computer_table_lamp", true); + }); + + $this -> add_action_script([ + "alias" => "computer_table_lamp_off", + "name" => "ВЫКЛ комп. лампу", + "icon" => '', + "description" => "Выключить настольную компьютерную лампу", + "author" => "Eugene Sukhodolskiy" + ], function($params) { + return $this -> lamp_switch("computer_table_lamp", false); + }); + } + + public function register_regular_scripts(): void { + } + + // ACTIONS + + protected function lamp_switch(String $device_alias, Bool $state = false): Array { + $relay_api = $this -> devices() -> by_alias($device_alias) -> device_api(); + if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay) { + $status = $relay_api -> get_status(); + + if(isset($status["channels"][0]["state"]) and $status["channels"][0]["state"] != ($state ? "on" : "off")) { + return [ + "device" => $relay_api -> set_state($state) + ]; + } + } + + return [ + "result" => false + ]; + } +} \ No newline at end of file