class Light:
def __init__(self, location):
self.location = location
self.power = False
def turn_on(self):
self.power = True
def turn_off(self):
self.power = False
def is_on(self):
return self.power
def get_name(self):
return f"{self.location} 전등"
class AirConditioner:
def __init__(self):
self.power = False
def turn_on(self):
self.power = True
def turn_off(self):
self.power = False
def is_on(self):
return self.power
def get_name(self):
return "에어컨"
class RobotCleaner:
def __init__(self):
self.power = False
def turn_on(self):
self.power = True
def turn_off(self):
self.power = False
def is_on(self):
return self.power
def get_name(self):
return "로봇청소기"
class SmartHub:
def __init__(self):
self.devices = []
def register_device(self, device):
self.devices.append(device)
def activate_away_mode(self):
turned_off = []
already_off = []
for device in self.devices:
if device.is_on():
device.turn_off()
turned_off.append(device.get_name())
else:
already_off.append(device.get_name())
message = "외출 모드 가동: "
if turned_off:
message += f"{', '.join(turned_off)}의 전원을 차단했습니다. "
if already_off:
message += f"{', '.join(already_off)}는 이미 대기 상태입니다."
return message
living_light = Light("거실")
aircon = AirConditioner()
robot = RobotCleaner()
living_light.turn_on()
aircon.turn_on()
hub = SmartHub()
hub.register_device(living_light)
hub.register_device(aircon)
hub.register_device(robot)
print(hub.activate_away_mode())
To embed this project on your website, copy the following code and paste it into your website's HTML: