diff --git a/server/ControlScripts/SpotlightsScope.php b/server/ControlScripts/SpotlightsScope.php index 5c38778..ec5d421 100644 --- a/server/ControlScripts/SpotlightsScope.php +++ b/server/ControlScripts/SpotlightsScope.php @@ -6,7 +6,7 @@ class SpotlightsScope extends \SHServ\Middleware\ControlScripts implements \SHServ\Implements\ControlScriptsInterface { public function register_events_handlers(): void { - $this -> stand_btn_pressed_to_stand_relay(); + } public function register_actions_scripts(): void { @@ -63,7 +63,11 @@ $result = false; if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay) { - $result = $relay_api -> set_state($state); + $status = $relay_api -> get_status(); + + if(isset($status["channels"][0]["state"]) and $status["channels"][0]["state"] != ($state ? "on" : "off")) { + $result = $relay_api -> set_state($state); + } } $results[$alias] = $result; @@ -76,7 +80,5 @@ // EVENTS HANDLERS - protected function stand_btn_pressed_to_stand_relay() { - - } + } \ No newline at end of file diff --git a/server/ControlScripts/TestScriptsScope.php b/server/ControlScripts/TestScriptsScope.php index 889b8b4..a792b5a 100644 --- a/server/ControlScripts/TestScriptsScope.php +++ b/server/ControlScripts/TestScriptsScope.php @@ -6,7 +6,7 @@ class TestScriptsScope extends \SHServ\Middleware\ControlScripts implements \SHServ\Implements\ControlScriptsInterface { public function register_events_handlers(): void { - $this -> stand_btn_pressed_to_stand_relay(); + // $this -> stand_btn_pressed_to_stand_relay(); } public function register_actions_scripts(): void { @@ -21,44 +21,44 @@ } public function register_regular_scripts(): void { - $this -> add_regular_script([ - "alias" => "regular_script_alias2", - "name" => "regular script name 2", - "description" => "regular script description 2", - "author" => "Eugene Sukhodolskiy" - ], function() { - try { - $button = $this -> devices() -> by_alias("backdoor_buttons"); - $btn_api = $button -> device_api(); + // $this -> add_regular_script([ + // "alias" => "regular_script_alias2", + // "name" => "regular script name 2", + // "description" => "regular script description 2", + // "author" => "Eugene Sukhodolskiy" + // ], function() { + // try { + // $button = $this -> devices() -> by_alias("backdoor_buttons"); + // $btn_api = $button -> device_api(); - if($btn_api instanceof \SHServ\Tools\DeviceAPI\Button) { - if(($btn_api -> get_status())["channels"][2]["indicator"] != "error") { - $btn_api -> set_channel_state("error", 2); - } else { - $btn_api -> set_channel_state("mute", 2); - } - } - } catch(\Exception $e) { - echo $e -> getMessage(); - } - }); + // if($btn_api instanceof \SHServ\Tools\DeviceAPI\Button) { + // if(($btn_api -> get_status())["channels"][2]["indicator"] != "error") { + // $btn_api -> set_channel_state("error", 2); + // } else { + // $btn_api -> set_channel_state("mute", 2); + // } + // } + // } catch(\Exception $e) { + // echo $e -> getMessage(); + // } + // }); } // EVENTS HANDLERS - protected function stand_btn_pressed_to_stand_relay() { - $this -> add_event_handler("button@backdoor_buttons(1).press", function(Device $device, Array $data) { - $relay = $this -> devices() -> by_alias("stand_relay"); - $relay -> device_api() -> toggle_channel(0); - $relay_channels = ($relay -> device_api() -> get_status())["channels"]; + // protected function stand_btn_pressed_to_stand_relay() { + // $this -> add_event_handler("button@backdoor_buttons(1).press", function(Device $device, Array $data) { + // $relay = $this -> devices() -> by_alias("stand_relay"); + // $relay -> device_api() -> toggle_channel(0); + // $relay_channels = ($relay -> device_api() -> get_status())["channels"]; - $device_api = $device -> device_api(); - if($device_api instanceof \SHServ\Tools\DeviceAPI\Button) { - $device_api -> set_channel_state( - $relay_channels[0]["state"] == "on" ? "enabled" : "disabled", - $data["channel"] - ); - } - }); - } + // $device_api = $device -> device_api(); + // if($device_api instanceof \SHServ\Tools\DeviceAPI\Button) { + // $device_api -> set_channel_state( + // $relay_channels[0]["state"] == "on" ? "enabled" : "disabled", + // $data["channel"] + // ); + // } + // }); + // } } \ No newline at end of file