diff --git a/server/ControlScripts/Common.php b/server/ControlScripts/Common.php index f07b2a4..5182999 100644 --- a/server/ControlScripts/Common.php +++ b/server/ControlScripts/Common.php @@ -3,6 +3,53 @@ namespace ControlScripts; trait Common { + public function register_global_device_sync_map() { + $this -> add_sync_connection([ + ["type" => "relay", "alias" => "spotlight_main_back_1", "channel" => 0], + ["type" => "button", "alias" => "buttons_backdoor", "channel" => 0], + ["type" => "button", "alias" => "master_door_btns", "channel" => 0], + ]); + + $this -> add_sync_connection([ + ["type" => "relay", "alias" => "spotlight_main_back_2", "channel" => 0], + ["type" => "button", "alias" => "buttons_backdoor", "channel" => 1], + ["type" => "button", "alias" => "master_door_btns", "channel" => 1], + ]); + + $this -> add_sync_connection([ + ["type" => "relay", "alias" => "spotlight_main_front_1", "channel" => 0], + ["type" => "button", "alias" => "buttons_backdoor", "channel" => 2], + ["type" => "button", "alias" => "master_door_btns", "channel" => 2], + ]); + + $this -> add_sync_connection([ + ["type" => "relay", "alias" => "light_hub_1", "channel" => 0], + ["type" => "button", "alias" => "buttons_office_room", "channel" => 3], + ]); + + $this -> add_sync_connection([ + ["type" => "relay", "alias" => "craft_table_lamp", "channel" => 0], + ["type" => "button", "alias" => "buttons_office_room", "channel" => 2], + ]); + + $this -> add_sync_connection([ + ["type" => "relay", "alias" => "computer_table_lamp", "channel" => 0], + ["type" => "button", "alias" => "buttons_office_room", "channel" => 1], + ]); + + $this -> add_sync_connection([ + ["type" => "relay", "alias" => "light_hub_1", "channel" => 2], + ["type" => "button", "alias" => "buttons_office_room", "channel" => 0], + ["type" => "button", "alias" => "master_room_btns", "channel" => 1], + ["type" => "button", "alias" => "btns_hall2_1", "channel" => 0], + ]); + + $this -> add_sync_connection([ + ["type" => "relay", "alias" => "light_hub_1", "channel" => 1], + ["type" => "button", "alias" => "master_room_btns", "channel" => 0], + ]); + } + public function btn_on_online(String $alias, Array $muted = []) { $this -> add_event_handler("button@{$alias}.online", function(Device $btns_block, Array $data) use ($muted) { $btns_block_api = $btns_block -> device_api(); diff --git a/server/ControlScripts/Scopes/LightHubScope.php b/server/ControlScripts/Scopes/LightHubScope.php index 4c21ced..6d04b9c 100644 --- a/server/ControlScripts/Scopes/LightHubScope.php +++ b/server/ControlScripts/Scopes/LightHubScope.php @@ -9,10 +9,7 @@ use \ControlScripts\Common; public function register_sync_map(): void { - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "light_hub_1", "channel" => 1], - ["type" => "button", "alias" => "master_room_btns", "channel" => 0], - ]); + $this -> register_global_device_sync_map(); } public function register_events_handlers(): void { diff --git a/server/ControlScripts/Scopes/OfficeRoomScope.php b/server/ControlScripts/Scopes/OfficeRoomScope.php index 517b8d7..9b5dc93 100644 --- a/server/ControlScripts/Scopes/OfficeRoomScope.php +++ b/server/ControlScripts/Scopes/OfficeRoomScope.php @@ -8,27 +8,7 @@ use \ControlScripts\Common; public function register_sync_map(): void { - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "light_hub_1", "channel" => 0], - ["type" => "button", "alias" => "buttons_office_room", "channel" => 3], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "craft_table_lamp", "channel" => 0], - ["type" => "button", "alias" => "buttons_office_room", "channel" => 2], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "computer_table_lamp", "channel" => 0], - ["type" => "button", "alias" => "buttons_office_room", "channel" => 1], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "light_hub_1", "channel" => 2], - ["type" => "button", "alias" => "buttons_office_room", "channel" => 0], - ["type" => "button", "alias" => "master_room_btns", "channel" => 1], - ["type" => "button", "alias" => "btns_hall2_1", "channel" => 0], - ]); + $this -> register_global_device_sync_map(); } public function register_events_handlers(): void { diff --git a/server/ControlScripts/Scopes/SpotlightsScope.php b/server/ControlScripts/Scopes/SpotlightsScope.php index 18719a3..5642fac 100644 --- a/server/ControlScripts/Scopes/SpotlightsScope.php +++ b/server/ControlScripts/Scopes/SpotlightsScope.php @@ -6,25 +6,9 @@ class SpotlightsScope extends \SHServ\Middleware\ControlScripts implements \SHServ\Implements\ControlScriptsInterface { use \ControlScripts\Common; - + public function register_sync_map(): void { - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "spotlight_main_back_1", "channel" => 0], - ["type" => "button", "alias" => "buttons_backdoor", "channel" => 0], - ["type" => "button", "alias" => "master_door_btns", "channel" => 0], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "spotlight_main_back_2", "channel" => 0], - ["type" => "button", "alias" => "buttons_backdoor", "channel" => 1], - ["type" => "button", "alias" => "master_door_btns", "channel" => 1], - ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "spotlight_main_front_1", "channel" => 0], - ["type" => "button", "alias" => "buttons_backdoor", "channel" => 2], - ["type" => "button", "alias" => "master_door_btns", "channel" => 2], - ]); + $this -> register_global_device_sync_map(); } public function register_events_handlers(): void {