-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEntertainment_Power.ips.php
More file actions
86 lines (81 loc) · 3.83 KB
/
Copy pathEntertainment_Power.ips.php
File metadata and controls
86 lines (81 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?
include_once "IPSLogger.ips.php";
include_once "Entertainment_Constants.ips.php";
include_once "Entertainment_Configuration.ips.php";
include_once "Entertainment_Communication.ips.php";
include_once "Entertainment_Connect.ips.php";
include_once "Entertainment_Source.ips.php";
// ---------------------------------------------------------------------------------------------------------------------------
function Entertainment_TurnOffAllRoomesAndDevices() {
IPSLogger_Inf(__file__, 'Turn Off all Roomes and Devices');
$RoomIds = get_ActiveRoomIds();
foreach ($RoomIds as $RoomId) {
Entertainment_SetRoomPowerByRoomId($RoomId, false);
}
Entertainment_PowerOffUnusedDevices();
}
// ---------------------------------------------------------------------------------------------------------------------------
function Entertainment_PowerOffUnusedDevices() {
IPSLogger_Trc(__file__, 'Power Off unused Devices ...');
$ActiveDeviceNames = get_ActiveDeviceNames();
$DeviceIds = IPS_GetChildrenIDs(c_ID_Devices);
foreach ($DeviceIds as $DeviceId) {
$DeviceName = IPS_GetName($DeviceId);
$PowerId = get_ControlIdByDeviceName($DeviceName, c_Control_DevicePower, false);
if ($PowerId !== false) {
if (GetValue($PowerId) and !array_key_exists($DeviceName, $ActiveDeviceNames)) {
Entertainment_SetDevicePowerByDeviceName($DeviceName, false);
}
}
}
}
// ---------------------------------------------------------------------------------------------------------------------------
function Entertainment_SetDevicePower($PowerId, $Value, $MessageType=c_MessageType_Action) {
$DeviceName = IPS_GetName(IPS_GetParent($PowerId));
Entertainment_SetDevicePowerByDeviceName($DeviceName, $Value, $MessageType);
}
// ---------------------------------------------------------------------------------------------------------------------------
function Entertainment_SetDevicePowerByDeviceName($DeviceName, $Value, $MessageType=c_MessageType_Action) {
IPSLogger_Trc(__file__, 'Handle Device Power for "'.$DeviceName.'" '.bool2OnOff($Value));
$PowerId = get_ControlIdByDeviceName($DeviceName, c_Control_DevicePower, false);
if ($PowerId !== false) {
if (!is_bool($Value)) { /*Toggle Power Value*/
$Value = !GetValue($PowerId);
IPSLogger_Dbg(__file__, "Toogle Device Power for '$DeviceName' to ".bool2OnOff($Value));
}
if (GetValue($PowerId) <> $Value) {
IPSLogger_Inf(__file__, 'Set Device Power for "'.$DeviceName.'" '.bool2OnOff($Value));
if ($Value) {
Entertainment_SendDataByDeviceName($DeviceName, c_Control_DevicePower,
array(c_Property_CommPowerOn, c_Property_CommPower), $MessageType);
} else {
Entertainment_SendDataByDeviceName($DeviceName, c_Control_DevicePower,
array(c_Property_CommPowerOff, c_Property_CommPower), $MessageType);
}
SetValue($PowerId, $Value);
Entertainment_Connect($DeviceName, $Value, true);
Entertainment_SetDeviceControlByDeviceName($DeviceName, c_Control_Muting, false);
Entertainment_SetRoomPowerByDeviceName($DeviceName, $Value);
}
}
}
// ---------------------------------------------------------------------------------------------------------------------------
function Entertainment_SetDevicePowerByRoomId($RoomId, $Value=true) {
if ($Value) {
$RoomName = IPS_GetName($RoomId);
$DeviceNames = get_DeviceNamesByRoomId($RoomId);
$DeviceData = get_DeviceConfiguration();
foreach ($DeviceNames as $DeviceName) {
if(isset($DeviceData[$DeviceName][c_Control_DevicePower])) {
$devicePower = $DeviceData[$DeviceName][c_Control_DevicePower];
if(isset($devicePower[c_Property_PowerDelay])) {
usleep($devicePower[c_Property_PowerDelay] * 1000);
}
}
Entertainment_SetDevicePowerByDeviceName($DeviceName, true);
}
} else {
Entertainment_PowerOffUnusedDevices();
}
}
?>