Skip to content

Commit c75cd0c

Browse files
committed
chapter 6
1 parent b212397 commit c75cd0c

33 files changed

+589
-5
lines changed

command/party/CeilingFan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def low(self) -> None:
2929

3030
def off(self) -> None:
3131
# turns the ceiling fan off
32-
self.speed = self.Off
32+
self.speed = self.OFF
3333
print(f'{self.location} ceiling fan is off')
3434

3535
def getSpeed(self) -> int:

command/party/CeilingFanMediumCommand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self, ceilingFan: CeilingFan):
1313
self.ceilingFan = ceilingFan
1414

1515
def execute(self) -> None:
16-
self.prevSpeed = ceilingFan.getSpeed()
16+
self.prevSpeed = self.ceilingFan.getSpeed()
1717
self.ceilingFan.medium()
1818

1919
def undo(self) -> None:

command/party/CeilingFanOffCommand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self, ceilingFan: CeilingFan):
1313
self.ceilingFan = ceilingFan
1414

1515
def execute(self) -> None:
16-
self.prevSpeed = ceilingFan.getSpeed()
16+
self.prevSpeed = self.ceilingFan.getSpeed()
1717
self.ceilingFan.off()
1818

1919
def undo(self) -> None:

command/party/Light.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def dim(self, level: int) -> None:
1818
if level == 0:
1919
self.off()
2020
else:
21-
print(f"Light is dimmed to {level}%")
21+
print(f"Light is dimmed to {self.level}%")
2222

2323
def getLevel(self) -> int:
2424
return self.level

command/party/LightOnCommand.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,7 @@ def __init__(self, light: Light):
99
self.light = light
1010

1111
def execute(self) -> None:
12-
self.light.on()
12+
self.light.on()
13+
14+
def undo(self) -> None:
15+
self.light.off()

command/simpleremote/Command.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Command:
2+
def execute(self) -> None:
3+
pass

command/simpleremote/GarageDoor.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class GarageDoor:
2+
location: str
3+
4+
def __init__(self):
5+
pass
6+
7+
def up(self) -> None:
8+
print("Garage Door is Open")
9+
10+
def down(self) -> None:
11+
print("Garage Door is Closed")
12+
13+
def stop(self) -> None:
14+
print("Garage Door is Stopped")
15+
16+
def lightOn(self) -> None:
17+
print("Garage light is on")
18+
19+
def lightOff(self) -> None:
20+
print("Garage light is off")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from Command import Command
2+
from GarageDoor import GarageDoor
3+
4+
5+
class GarageDoorOpenCommand(Command):
6+
garageDoor: GarageDoor
7+
8+
def __init__(self, garageDoor: GarageDoor):
9+
self.garageDoor = garageDoor
10+
11+
def execute(self) -> None:
12+
self.garageDoor.up()

command/simpleremote/Light.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Light:
2+
location: str = ""
3+
4+
def __init__(self):
5+
pass
6+
7+
def on(self) -> None:
8+
print("Light is on")
9+
10+
def off(self) -> None:
11+
print("Light is off")
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from Command import Command
2+
from Light import Light
3+
4+
5+
class LightOffCommand(Command):
6+
light: Light
7+
8+
def __init__(self, light: Light):
9+
self.light = light
10+
11+
def execute(self) -> None:
12+
self.light.off()

0 commit comments

Comments
 (0)