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

namespace ControlScripts;

trait Common {
	public function btn_on_online(String $alias, Array $muted = []) {
		$this -> add_event_handler("button@{$alias}.online", function(Device $btns_block, Array $data) use ($muted) {
			$btns_block_api = $btns_block -> device_api();
			if($btns_block_api instanceof \SHServ\Tools\DeviceAPI\Button) {
				foreach($muted as $ch) {
					$btns_block_api -> set_channel_state("mute", $ch);
				}
			}

			$this -> helper() -> sync_btn_channels($this -> sync_map, $btns_block -> alias);
		});
	}
}