File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 25
25
26
26
class Device :
27
27
def turn_on (self ):
28
- raise NotImplementedError
28
+ print ( "Turning on device." )
29
29
30
30
def turn_off (self ):
31
- raise NotImplementedError
31
+ print ( "Turning off device." )
32
32
33
33
34
34
def get_device (device_id : str ) -> Device : # pylint: disable=unused-argument
@@ -40,17 +40,21 @@ def get_device(device_id: str) -> Device: # pylint: disable=unused-argument
40
40
41
41
@server .route ("/device/<device_id>/action/<action>" )
42
42
@server .route ("/device/emergency-power-off/<device_id>" )
43
- def perform_action (request : HTTPRequest , device_id : str , action : str = None ):
43
+ def perform_action (request : HTTPRequest , device_id : str , action : str = "emergency_power_off" ):
44
44
"""
45
45
Performs an "action" on a specified device.
46
46
"""
47
47
48
48
device = get_device (device_id )
49
49
50
- if action == "turn_on" :
50
+ if action in [ "turn_on" ,] :
51
51
device .turn_on ()
52
- elif action == "turn_off" or action is None :
52
+ elif action in [ "turn_off" , "emergency_power_off" ] :
53
53
device .turn_off ()
54
+ else :
55
+ with HTTPResponse (request , content_type = MIMEType .TYPE_TXT ) as response :
56
+ response .send (f"Unknown action ({ action } )" )
57
+ return
54
58
55
59
with HTTPResponse (request , content_type = MIMEType .TYPE_TXT ) as response :
56
60
response .send (f"Action ({ action } ) performed on device with ID: { device_id } " )
You can’t perform that action at this time.
0 commit comments