Skip to content

Commit 8f516cd

Browse files
committed
Replaced NotImplementedError in example with prints
1 parent 994a7e8 commit 8f516cd

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

examples/httpserver_url_parameters.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525

2626
class Device:
2727
def turn_on(self):
28-
raise NotImplementedError
28+
print("Turning on device.")
2929

3030
def turn_off(self):
31-
raise NotImplementedError
31+
print("Turning off device.")
3232

3333

3434
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
4040

4141
@server.route("/device/<device_id>/action/<action>")
4242
@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"):
4444
"""
4545
Performs an "action" on a specified device.
4646
"""
4747

4848
device = get_device(device_id)
4949

50-
if action == "turn_on":
50+
if action in ["turn_on",]:
5151
device.turn_on()
52-
elif action == "turn_off" or action is None:
52+
elif action in ["turn_off", "emergency_power_off"]:
5353
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
5458

5559
with HTTPResponse(request, content_type=MIMEType.TYPE_TXT) as response:
5660
response.send(f"Action ({action}) performed on device with ID: {device_id}")

0 commit comments

Comments
 (0)