Created
March 19, 2025 23:47
-
-
Save waseemhnyc/610bcfc081fa8ac685e9661efadb83b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Problem 1: Smart Home Device Hierarchy | |
""" | |
Instructions: | |
1. Create a base class called 'SmartDevice' with attributes for device name, connection status, and power status | |
2. Implement methods to turn on/off the device and connect/disconnect from WiFi | |
3. Create a child class 'SmartThermostat' that inherits from SmartDevice | |
4. Add temperature-related attributes and methods to the SmartThermostat class | |
5. Test your implementation with the provided test cases | |
Your SmartThermostat class should have methods to: | |
- Set the target temperature | |
- Read the current temperature | |
- Adjust the HVAC mode (heat, cool, off) | |
""" | |
# Base class - implement this | |
class SmartDevice: | |
# Your code here | |
pass | |
# Child class - implement this | |
class SmartThermostat(SmartDevice): | |
# Your code here | |
pass | |
# Test cases - DO NOT MODIFY | |
def test_smart_thermostat(): | |
print("Testing SmartThermostat implementation...") | |
# Create a new thermostat | |
nest = SmartThermostat("Living Room Thermostat") | |
# Test inherited functionality | |
assert nest.name == "Living Room Thermostat", "Name attribute not set correctly" | |
assert not nest.is_on, "Device should start in powered off state" | |
assert not nest.is_connected, "Device should start disconnected" | |
nest.power_on() | |
assert nest.is_on, "Power on method failed" | |
nest.connect() | |
assert nest.is_connected, "Connect method failed" | |
# Test thermostat-specific functionality | |
nest.set_temperature(72) | |
assert nest.target_temp == 72, "Target temperature not set correctly" | |
nest.current_temp = 68 # Simulate temperature reading | |
assert nest.get_temperature() == 68, "Current temperature reading incorrect" | |
nest.set_hvac_mode("heat") | |
assert nest.hvac_mode == "heat", "HVAC mode not set correctly" | |
# Test status reporting | |
status = nest.get_status() | |
print(status) | |
print("All tests passed!") | |
# Uncomment to run tests when your implementation is ready | |
# test_smart_thermostat() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment