diff --git a/server/ControlScripts/Common.php b/server/ControlScripts/Common.php index dfd76f8..f07b2a4 100644 --- a/server/ControlScripts/Common.php +++ b/server/ControlScripts/Common.php @@ -15,4 +15,27 @@ $this -> helper() -> sync_btn_channels($this -> sync_map(), $btns_block -> alias); }); } + + protected function set_btns_click_handlers($alias): void { + $self = $this; + $buttons = $this -> helper() -> prepare_sync_map_by_alias($this -> sync_map(), $alias); + foreach($buttons as $btn_channel => $entry) { + if($entry[0]["type"] != "relay") { + continue; + } + + $relay_alias = $entry[0]["alias"]; + $relay_channel = $entry[0]["channel"]; + + $this -> add_event_handler("button@{$alias}({$btn_channel}).press", function(Device $btns_block, Array $data) use ($self, $btn_channel, $relay_alias, $relay_channel) { + $btns_block_api = $btns_block -> device_api(); + $relay_api = $this -> devices() -> by_alias($relay_alias) -> device_api(); + + if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay and $btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { + $relay_api -> toggle_channel($relay_channel); + $this -> helper() -> sync_relay_to_btns($this -> sync_map(), $relay_alias); + } + }); + } + } } \ No newline at end of file diff --git a/server/ControlScripts/Scopes/LightHubScope.php b/server/ControlScripts/Scopes/LightHubScope.php index 2248288..4c21ced 100644 --- a/server/ControlScripts/Scopes/LightHubScope.php +++ b/server/ControlScripts/Scopes/LightHubScope.php @@ -18,8 +18,8 @@ public function register_events_handlers(): void { $this -> btn_on_online("master_room_btns", [2, 3]); $this -> btn_on_online("btns_hall2_1", [1]); - $this -> btns_click_handlers("master_room_btns"); - $this -> btns_click_handlers("btns_hall2_1"); + $this -> set_btns_click_handlers("master_room_btns"); + $this -> set_btns_click_handlers("btns_hall2_1"); } public function register_actions_scripts(): void { @@ -72,28 +72,5 @@ "result" => $result ]; } - - protected function btns_click_handlers($alias): void { - $self = $this; - $buttons = $this -> helper() -> prepare_sync_map_by_alias($this -> sync_map(), $alias); - foreach($buttons as $btn_channel => $entry) { - if($entry[0]["type"] != "relay") { - continue; - } - - $relay_alias = $entry[0]["alias"]; - $relay_channel = $entry[0]["channel"]; - - $this -> add_event_handler("button@{$alias}({$btn_channel}).press", function(Device $btns_block, Array $data) use ($self, $btn_channel, $relay_alias, $relay_channel) { - $btns_block_api = $btns_block -> device_api(); - $relay_api = $this -> devices() -> by_alias($relay_alias) -> device_api(); - - if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay and $btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { - $relay_api -> toggle_channel($relay_channel); - $this -> helper() -> sync_relay_to_btns($this -> sync_map(), $relay_alias); - } - }); - } - } } diff --git a/server/ControlScripts/Scopes/OfficeRoomScope.php b/server/ControlScripts/Scopes/OfficeRoomScope.php index b6484d1..bff6fc2 100644 --- a/server/ControlScripts/Scopes/OfficeRoomScope.php +++ b/server/ControlScripts/Scopes/OfficeRoomScope.php @@ -30,8 +30,8 @@ } public function register_events_handlers(): void { - $this -> btns_online("buttons_office_room"); - $this -> btns_handlers("buttons_office_room"); + $this -> btn_on_online("buttons_office_room"); + $this -> set_btns_click_handlers("buttons_office_room"); } public function register_actions_scripts(): void { @@ -86,32 +86,32 @@ ]; } - protected function btns_online(String $button_alias): void { - $this -> add_event_handler("button@{$button_alias}.online", function(Device $btns_block, Array $data) { - $btns_block_api = $btns_block -> device_api(); - $this -> helper() -> sync_btn_channels($this -> sync_map(), $btns_block -> alias); - }); - } + // protected function btns_online(String $button_alias): void { + // $this -> add_event_handler("button@{$button_alias}.online", function(Device $btns_block, Array $data) { + // $btns_block_api = $btns_block -> device_api(); + // $this -> helper() -> sync_btn_channels($this -> sync_map(), $btns_block -> alias); + // }); + // } - protected function btns_handlers(String $button_alias): void { - $buttons_channels = $this -> helper() -> prepare_sync_map_by_alias($this -> sync_map(), $button_alias); - foreach($buttons_channels as $btn_channel => $entry) { - if($entry[0]["type"] != "relay") { - continue; - } + // protected function btns_handlers(String $button_alias): void { + // $buttons_channels = $this -> helper() -> prepare_sync_map_by_alias($this -> sync_map(), $button_alias); + // foreach($buttons_channels as $btn_channel => $entry) { + // if($entry[0]["type"] != "relay") { + // continue; + // } - $relay_alias = $entry[0]["alias"]; - $relay_channel = $entry[0]["channel"]; + // $relay_alias = $entry[0]["alias"]; + // $relay_channel = $entry[0]["channel"]; - $this -> add_event_handler("button@{$button_alias}({$btn_channel}).press", function(Device $btns_block, Array $data) use ($btn_channel, $relay_alias, $relay_channel) { - $btns_block_api = $btns_block -> device_api(); - $relay_api = $this -> devices() -> by_alias($relay_alias) -> device_api(); + // $this -> add_event_handler("button@{$button_alias}({$btn_channel}).press", function(Device $btns_block, Array $data) use ($btn_channel, $relay_alias, $relay_channel) { + // $btns_block_api = $btns_block -> device_api(); + // $relay_api = $this -> devices() -> by_alias($relay_alias) -> device_api(); - if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay and $btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { - $relay_api -> toggle_channel($relay_channel); - $this -> helper() -> sync_relay_to_btn_channel($relay_api, $btns_block_api, $relay_channel, $btn_channel); - } - }); - } - } + // if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay and $btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { + // $relay_api -> toggle_channel($relay_channel); + // $this -> helper() -> sync_relay_to_btn_channel($relay_api, $btns_block_api, $relay_channel, $btn_channel); + // } + // }); + // } + // } } diff --git a/server/ControlScripts/Scopes/SpotlightsScope.php b/server/ControlScripts/Scopes/SpotlightsScope.php index 99e7b25..064468a 100644 --- a/server/ControlScripts/Scopes/SpotlightsScope.php +++ b/server/ControlScripts/Scopes/SpotlightsScope.php @@ -26,10 +26,10 @@ } public function register_events_handlers(): void { - $this -> btns_click_handlers("buttons_backdoor"); - $this -> btns_click_handlers("master_door_btns"); - $this -> on_online("buttons_backdoor"); - $this -> on_online("master_door_btns"); + $this -> set_btns_click_handlers("buttons_backdoor"); + $this -> set_btns_click_handlers("master_door_btns"); + $this -> btn_on_online("buttons_backdoor"); + $this -> btn_on_online("master_door_btns"); } public function register_actions_scripts(): void { @@ -139,37 +139,37 @@ // EVENTS HANDLERS - protected function on_online($alias) { - $this -> add_event_handler("button@{$alias}.online", function(Device $btns_block, Array $data) { - $btns_block_api = $btns_block -> device_api(); - if($btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { - $btns_block_api -> set_channel_state("mute", 3); - } + // protected function on_online($alias) { + // $this -> add_event_handler("button@{$alias}.online", function(Device $btns_block, Array $data) { + // $btns_block_api = $btns_block -> device_api(); + // if($btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { + // $btns_block_api -> set_channel_state("mute", 3); + // } - $this -> helper() -> sync_btn_channels($this -> sync_map(), $btns_block -> alias); - }); - } + // $this -> helper() -> sync_btn_channels($this -> sync_map(), $btns_block -> alias); + // }); + // } - protected function btns_click_handlers($alias): void { - $self = $this; - $buttons = $this -> helper() -> prepare_sync_map_by_alias($this -> sync_map(), $alias); - foreach($buttons as $btn_channel => $entry) { - if($entry[0]["type"] != "relay") { - continue; - } + // protected function btns_click_handlers($alias): void { + // $self = $this; + // $buttons = $this -> helper() -> prepare_sync_map_by_alias($this -> sync_map(), $alias); + // foreach($buttons as $btn_channel => $entry) { + // if($entry[0]["type"] != "relay") { + // continue; + // } - $relay_alias = $entry[0]["alias"]; - $relay_channel = $entry[0]["channel"]; + // $relay_alias = $entry[0]["alias"]; + // $relay_channel = $entry[0]["channel"]; - $this -> add_event_handler("button@{$alias}({$btn_channel}).press", function(Device $btns_block, Array $data) use ($self, $btn_channel, $relay_alias, $relay_channel) { - $btns_block_api = $btns_block -> device_api(); - $relay_api = $this -> devices() -> by_alias($relay_alias) -> device_api(); + // $this -> add_event_handler("button@{$alias}({$btn_channel}).press", function(Device $btns_block, Array $data) use ($self, $btn_channel, $relay_alias, $relay_channel) { + // $btns_block_api = $btns_block -> device_api(); + // $relay_api = $this -> devices() -> by_alias($relay_alias) -> device_api(); - if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay and $btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { - $relay_api -> toggle_channel($relay_channel); - $this -> helper() -> sync_relay_to_btns($this -> sync_map(), $relay_alias); - } - }); - } - } + // if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay and $btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { + // $relay_api -> toggle_channel($relay_channel); + // $this -> helper() -> sync_relay_to_btns($this -> sync_map(), $relay_alias); + // } + // }); + // } + // } }