diff --git a/server/ControlScripts/SpotlightsScope.php b/server/ControlScripts/SpotlightsScope.php index fad7347..37dcf83 100644 --- a/server/ControlScripts/SpotlightsScope.php +++ b/server/ControlScripts/SpotlightsScope.php @@ -110,13 +110,6 @@ $btns_block_api = $btns_block -> device_api(); if($btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) { $btns_block_api -> set_channel_state("mute", 3); - - // foreach($this -> aliases as $btn_channel => $relay_alias) { - // $relay_api = $this -> devices() -> by_alias($relay_alias) -> device_api(); - // if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay) { - // $this -> helper() -> sync_relay_to_btn_channel($relay_api, $btns_block_api, 0, $btn_channel); - // } - // } } $this -> helper() -> sync_btn_channels($this -> sync_map, $btns_block -> alias); @@ -124,7 +117,14 @@ } protected function backdoor_btns_handlers(): void { - foreach($this -> aliases as $btn_channel => $relay_alias) { + $buttons_backdoor = $this -> helper() -> prepare_sync_map_by_alias($this -> sync_map, "buttons_backdoor"); + foreach($buttons_backdoor as $btn_channel => $entry) { + if($entry[0]["type"] != "relay") { + continue; + } + + $relay_alias = $entry[0]["alias"]; + $this -> add_event_handler("button@buttons_backdoor({$btn_channel}).press", function(Device $btns_block, Array $data) use ($btn_channel, $relay_alias) { $btns_block_api = $btns_block -> device_api(); $relay_api = $this -> devices() -> by_alias($relay_alias) -> device_api(); diff --git a/server/SHServ/Helpers/DeviceScriptsHelper.php b/server/SHServ/Helpers/DeviceScriptsHelper.php index 7e97f24..2420de0 100644 --- a/server/SHServ/Helpers/DeviceScriptsHelper.php +++ b/server/SHServ/Helpers/DeviceScriptsHelper.php @@ -148,17 +148,9 @@ } public function prepare_sync_map_by_alias(Array $sync_map, String $alias): Array { - /*$sync_map [ - * button_channel_num => [ - * ["alias" => "relay_alias", "channel" => 1], - * ["alias" => "relay_alias_2", "channel" => 0], - * ] - * ] - * */ - $map = $sync_map["connections"]; $result = []; - foreach($map as $connection) { + foreach($sync_map["connections"] as $connection) { foreach($connection as $device_entry) { if($device_entry["alias"] != $alias) { continue;