-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOpen-GarageDoor.ps1
39 lines (39 loc) · 1002 Bytes
/
Open-GarageDoor.ps1
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
function Open-GarageDoor ([array]$commands)
{
$state = "Door: CLOSED"
$state
foreach ($command in $commands)
{
if ($command -eq "button_clicked")
{
if ($state -eq "Door: CLOSED" -or $state -eq "Door: STOPPED_WHILE_CLOSING")
{
$state = "Door: OPENING"
}
elseif ($state -eq "Door: OPEN" -or $state -eq "Door: STOPPED_WHILE_OPENING")
{
$state = "Door: CLOSING"
}
elseif ($state -eq "Door: CLOSING")
{
$state = "Door: STOPPED_WHILE_CLOSING"
}
else
{
$state = "Door: STOPPED_WHILE_OPENING"
}
}
else {
if ($state -eq "Door: OPENING")
{
$state = "Door: OPEN"
}
else
{
$state = "Door: CLOSED"
}
}
$command
$state
}
}