diff --git a/server/ControlScripts/LightHubScope.php b/server/ControlScripts/LightHubScope.php index d6794c9..27dde3e 100644 --- a/server/ControlScripts/LightHubScope.php +++ b/server/ControlScripts/LightHubScope.php @@ -5,39 +5,12 @@ use \SHServ\Entities\Device; class LightHubScope extends \SHServ\Middleware\ControlScripts implements \SHServ\Implements\ControlScriptsInterface { - protected $sync_map = [ - "connections" => [ - [ - ["type" => "relay", "alias" => "light_hub_1", "channel" => 0], - ["type" => "button", "alias" => "buttons_office_room", "channel" => 0], - ], - - [ - ["type" => "relay", "alias" => "craft_table_lamp", "channel" => 0], - ["type" => "button", "alias" => "buttons_office_room", "channel" => 1], - ], - - [ - ["type" => "relay", "alias" => "computer_table_lamp", "channel" => 0], - ["type" => "button", "alias" => "buttons_office_room", "channel" => 2], - ], - ] - ]; + public function register_events_handlers(): void { } public function register_actions_scripts(): void { $this -> add_action_script([ - "alias" => "main_lamps_switcher", - "name" => "Осн. свет в кабинете", - "icon" => '', - "description" => "Включить/выключить основной свет в кабинете", - "author" => "Eugene Sukhodolskiy" - ], function($params) { - return $this -> lamp_switch("light_hub_1", 0); - }); - - $this -> add_action_script([ "alias" => "master_room_lamp_switcher", "name" => "Осн. свет в спальне", "icon" => '', @@ -74,33 +47,15 @@ // ACTIONS protected function lamp_switch(String $relay_alias, int $channel): Array { - $btns_block_api = $this -> devices() -> by_alias("buttons_office_room") -> device_api(); - $device_entries = $this -> helper() -> get_sync_entries_by_type($this -> sync_map, "relay"); + $relay_api= $this -> devices() -> by_alias($relay_alias) -> device_api(); $result = false; if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay) { $result = $relay_api -> toggle_channel($channel); - $this -> helper() -> sync_relay_to_btns($this -> sync_map, $relay_alias); } return [ "result" => $result ]; } - -// protected function spotlight_switch(String $relay_alias, Bool $state = false) { -// $btns_block_api = $this -> devices() -> by_alias("buttons_backdoor") -> device_api(); -// $device_entries = $this -> helper() -> get_sync_entries_by_type($this -> sync_map, "relay"); -// -// $relay_api = $this -> devices() -> by_alias($relay_alias) -> device_api(); -// $result = false; -// if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay) { -// $result = $relay_api -> set_state($state); -// $this -> helper() -> sync_relay_to_btns($this -> sync_map, $relay_alias); -// } -// -// return [ -// "result" => $result -// ]; -// } } diff --git a/server/ControlScripts/OfficeRoomScope.php b/server/ControlScripts/OfficeRoomScope.php index d33d3bd..d100770 100644 --- a/server/ControlScripts/OfficeRoomScope.php +++ b/server/ControlScripts/OfficeRoomScope.php @@ -5,48 +5,57 @@ use \SHServ\Entities\Device; class OfficeRoomScope extends \SHServ\Middleware\ControlScripts implements \SHServ\Implements\ControlScriptsInterface { + protected $sync_map = [ + "connections" => [ + [ + ["type" => "relay", "alias" => "light_hub_1", "channel" => 0], + ["type" => "button", "alias" => "buttons_office_room", "channel" => 0], + ], + + [ + ["type" => "relay", "alias" => "craft_table_lamp", "channel" => 0], + ["type" => "button", "alias" => "buttons_office_room", "channel" => 1], + ], + + [ + ["type" => "relay", "alias" => "computer_table_lamp", "channel" => 0], + ["type" => "button", "alias" => "buttons_office_room", "channel" => 2], + ], + ] + ]; + public function register_events_handlers(): void { } public function register_actions_scripts(): void { $this -> add_action_script([ - "alias" => "computer_table_lamp_on", - "name" => "ВКЛ комп. лампу", + "alias" => "computer_table_lamp_switch", + "name" => "Комп. лампа", "icon" => '', - "description" => "Включить настольную компьютерную лампу", + "description" => "Вкл/Выкл. настольную компьютерную лампу", "author" => "Eugene Sukhodolskiy" ], function($params) { - return $this -> lamp_switch("computer_table_lamp", true); + return $this -> lamp_switch("computer_table_lamp", 0); }); $this -> add_action_script([ - "alias" => "computer_table_lamp_off", - "name" => "ВЫКЛ комп. лампу", - "icon" => '', - "description" => "Выключить настольную компьютерную лампу", + "alias" => "craft_table_lamp_switch", + "name" => "Крафт. лампа", + "icon" => '>', + "description" => "Вкл/Выкл. настольную лампу на столе для крафта", "author" => "Eugene Sukhodolskiy" ], function($params) { - return $this -> lamp_switch("computer_table_lamp", false); + return $this -> lamp_switch("craft_table_lamp", 0); }); $this -> add_action_script([ - "alias" => "craft_table_lamp_on", - "name" => "ВКЛ крафт. лампу", - "icon" => '', - "description" => "Включить настольную лампу на столе для крафта", + "alias" => "main_lamps_switcher", + "name" => "Осн. свет в кабинете", + "icon" => '', + "description" => "Включить/выключить основной свет в кабинете", "author" => "Eugene Sukhodolskiy" ], function($params) { - return $this -> lamp_switch("craft_table_lamp", true); - }); - - $this -> add_action_script([ - "alias" => "craft_table_lamp_off", - "name" => "ВЫКЛ крафт. лампу", - "icon" => '', - "description" => "Выключить настольную лампу на столе для крафта", - "author" => "Eugene Sukhodolskiy" - ], function($params) { - return $this -> lamp_switch("craft_table_lamp", false); + return $this -> lamp_switch("light_hub_1", 0); }); } @@ -54,21 +63,19 @@ } // ACTIONS - - protected function lamp_switch(String $device_alias, Bool $state = false): Array { - $relay_api = $this -> devices() -> by_alias($device_alias) -> device_api(); - if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay) { - $status = $relay_api -> get_status(); - if(isset($status["channels"][0]["state"]) and $status["channels"][0]["state"] != ($state ? "on" : "off")) { - return [ - "device" => $relay_api -> set_state($state) - ]; - } + protected function lamp_switch(String $relay_alias, int $channel): Array { + $btns_block_api = $this -> devices() -> by_alias("buttons_office_room") -> device_api(); + $relay_api = $this -> devices() -> by_alias($relay_alias) -> device_api(); + + $result = false; + if($relay_api instanceof \SHServ\Tools\DeviceAPI\Relay) { + $result = $relay_api -> toggle_channel($channel); + $this -> helper() -> sync_relay_to_btns($this -> sync_map, $relay_alias); } return [ - "result" => false + "result" => $result ]; } } \ No newline at end of file