diff --git a/server/ControlScripts/Scopes/LightHubScope.php b/server/ControlScripts/Scopes/LightHubScope.php index 845139e..2248288 100644 --- a/server/ControlScripts/Scopes/LightHubScope.php +++ b/server/ControlScripts/Scopes/LightHubScope.php @@ -13,13 +13,6 @@ ["type" => "relay", "alias" => "light_hub_1", "channel" => 1], ["type" => "button", "alias" => "master_room_btns", "channel" => 0], ]); - - $this -> add_sync_connection([ - ["type" => "relay", "alias" => "light_hub_1", "channel" => 2], - ["type" => "button", "alias" => "master_room_btns", "channel" => 1], - ["type" => "button", "alias" => "buttons_office_room", "channel" => 0], - ["type" => "button", "alias" => "btns_hall2_1", "channel" => 0], - ]); } public function register_events_handlers(): void { diff --git a/server/ControlScripts/Scopes/SpotlightsScope.php b/server/ControlScripts/Scopes/SpotlightsScope.php index 90de4e3..99e7b25 100644 --- a/server/ControlScripts/Scopes/SpotlightsScope.php +++ b/server/ControlScripts/Scopes/SpotlightsScope.php @@ -146,13 +146,13 @@ $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); + $buttons = $this -> helper() -> prepare_sync_map_by_alias($this -> sync_map(), $alias); foreach($buttons as $btn_channel => $entry) { if($entry[0]["type"] != "relay") { continue; @@ -167,7 +167,7 @@ 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); + $this -> helper() -> sync_relay_to_btns($this -> sync_map(), $relay_alias); } }); } diff --git a/server/SHServ/Helpers/DeviceScriptsHelper.php b/server/SHServ/Helpers/DeviceScriptsHelper.php index 2420de0..e0e3cc8 100644 --- a/server/SHServ/Helpers/DeviceScriptsHelper.php +++ b/server/SHServ/Helpers/DeviceScriptsHelper.php @@ -150,6 +150,10 @@ public function prepare_sync_map_by_alias(Array $sync_map, String $alias): Array { $result = []; + if(!isset($sync_map["connections"])) { + return $result; + } + foreach($sync_map["connections"] as $connection) { foreach($connection as $device_entry) { if($device_entry["alias"] != $alias) { diff --git a/server/SHServ/Middleware/ControlScripts.php b/server/SHServ/Middleware/ControlScripts.php index a078190..034fbdb 100644 --- a/server/SHServ/Middleware/ControlScripts.php +++ b/server/SHServ/Middleware/ControlScripts.php @@ -11,7 +11,7 @@ protected $device_scripts_helper; protected static $regular_scripts = []; protected static $actions_scripts = []; - protected $sync_map = [ + protected static $sync_map_storage = [ "connection" => [], ]; @@ -21,8 +21,8 @@ abstract protected function register_actions_scripts(): void; public function __construct() { - list($scope_folder, $scope_name) = explode("\\", str_replace("SHServ", "", static::class)); - + list($scope_folder, $scope_name) = explode("\\", str_replace("\\Scopes", "", str_replace("SHServ", "", static::class))); + if($scope_folder != "ControlScripts" or (new Scripts()) -> script_state("scope", $scope_name)) { $this -> register_sync_map(); $this -> register_events_handlers(); @@ -160,10 +160,10 @@ } protected function add_sync_connection(Array $sync_connection) { - $this -> sync_map["connection"][] = $sync_connection; + self::$sync_map_storage["connection"][] = $sync_connection; } public function sync_map() { - return $this -> sync_map; + return self::$sync_map_storage; } } \ No newline at end of file