Newer
Older
smart-home-server / server / ControlScripts / SpotlightsScope.php
<?php

namespace ControlScripts;

use \SHServ\Entities\Device;

class TestScriptsScope extends \SHServ\Middleware\ControlScripts implements \SHServ\Implements\ControlScriptsInterface {
	public function register_events_handlers(): void {
		$this -> stand_btn_pressed_to_stand_relay();
	}

	public function register_actions_scripts(): void {
		$this -> add_action_script([
			"alias" => "spotlights_on",
			"name" => "All Spotlights On",
			"description" => "Включить все прожекторы",
			"author" => "Eugene Sukhodolskiy"
		], function($params) {
			$aliases = [
				"spotlight_main_back_1", 
				"spotlight_main_back_2", 
				"spotlight_main_front_1"
			];

			$results = [];

			foreach($aliases as $alias) { 
				$results[$alias] = $this -> devices() -> by_alias($alias) -> device_api() -> set_state(true);
			}

			return [
				"devices" => $results
			];
		});

		$this -> add_action_script([
			"alias" => "spotlights_off",
			"name" => "All Spotlights Off",
			"description" => "Выключить все прожекторы",
			"author" => "Eugene Sukhodolskiy"
		], function($params) {
			$aliases = [
				"spotlight_main_back_1", 
				"spotlight_main_back_2", 
				"spotlight_main_front_1"
			];

			$results = [];

			foreach($aliases as $alias) { 
				$results[$alias] = $this -> devices() -> by_alias($alias) -> device_api() -> set_state(false);
			}

			return [
				"devices" => $results
			];
		});
	}

	public function register_regular_scripts(): void {

	}

	// EVENTS HANDLERS
	
	protected function stand_btn_pressed_to_stand_relay() {

	}
}