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

namespace ControlScripts;

use \SHServ\Entities\Device;

class SpotlightsScope 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) {
			return $this -> all_spotlight_toggle(true);
		});

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

	public function register_regular_scripts(): void {

	}

	// ACTIONS
	
	protected function all_spotlight_toggle(Bool $state = false): Array {
		$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($state);
		}

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

	// EVENTS HANDLERS
	
	protected function stand_btn_pressed_to_stand_relay() {

	}
}