@@ -24,7 +24,7 @@ def __init__(self, light):
24
24
def execute (self ):
25
25
self .level = self .light .get_level ()
26
26
self .light .on ()
27
-
27
+
28
28
def undo (self ):
29
29
self .light .dim (self .level )
30
30
@@ -36,13 +36,13 @@ def __init__(self, light):
36
36
def execute (self ):
37
37
self .level = self .light .get_level ()
38
38
self .light .off ()
39
-
39
+
40
40
def undo (self ):
41
41
self .light .dim (self .level )
42
42
43
43
44
- class Light () :
45
- def __init__ (self , location :str ):
44
+ class Light :
45
+ def __init__ (self , location : str ):
46
46
self .location = location
47
47
self .level = 0
48
48
@@ -60,12 +60,12 @@ def dim(self, level):
60
60
self .off ()
61
61
else :
62
62
print (f"Light is dimmed to { self .level } %" )
63
-
63
+
64
64
def get_level (self ):
65
65
return self .level
66
66
67
67
68
- class RemoteControlWithUndo () :
68
+ class RemoteControlWithUndo :
69
69
"""The Invoker"""
70
70
71
71
def __init__ (self ) -> None :
@@ -91,17 +91,21 @@ def undo_button_was_pushed(self):
91
91
def __str__ (self ) -> str :
92
92
buffer = []
93
93
buffer .append ("\n ------ Remote Control -------\n " )
94
- for i , (on_command , off_command ) in enumerate (zip (self .on_commands , self .off_commands )):
95
- buffer .append (f"[slot { i } ] { on_command .__class__ .__name__ } " +
96
- f" { off_command .__class__ .__name__ } \n " )
97
-
94
+ for i , (on_command , off_command ) in enumerate (
95
+ zip (self .on_commands , self .off_commands )
96
+ ):
97
+ buffer .append (
98
+ f"[slot { i } ] { on_command .__class__ .__name__ } "
99
+ + f" { off_command .__class__ .__name__ } \n "
100
+ )
101
+
98
102
buffer .append (f"[undo] { self .undo_command .__class__ .__name__ } \n " )
99
103
return "" .join (buffer )
100
104
101
105
102
106
def remote_loader ():
103
- remoteControl = RemoteControlWithUndo ()
104
- living_room_light = Light ("Living Room" )
107
+ remoteControl = RemoteControlWithUndo ()
108
+ living_room_light = Light ("Living Room" )
105
109
living_room_light_on = LightOnCommand (living_room_light )
106
110
living_room_light_off = LightOffCommand (living_room_light )
107
111
@@ -116,5 +120,6 @@ def remote_loader():
116
120
print (remoteControl )
117
121
remoteControl .undo_button_was_pushed ()
118
122
119
- if __name__ == '__main__' :
120
- remote_loader ()
123
+
124
+ if __name__ == "__main__" :
125
+ remote_loader ()
0 commit comments