Search for question
Question

School of Computing Module Code M30299 Module Title(s) Programming Assessment Item number Item 6 Assessment Title Date Issued Schedule and Deliverables Deliverable Value Python Assignment - Smart Home Format Deadline Date Late/ECF deadline Program 100% - all marks for your Zip file containing your code, named after your UP number (e.g., 2123456.zip) 16:00, 11 Mar 2024 program will Demo be awarded in the demo 16:00, 25 Mar 2024 In your practical class between 12 and 15 Mar 2024 All late demos are to be completed by 26 Apr 2024 Notes and Advice • • The Extenuating Circumstances procedure is there to support you if you have had any circumstances (problems) that have been serious or significant enough to prevent you from attending, completing or submitting an assessment on time. If you complete an Extenuating Circumstances Form (ECF) for this assessment, it is important that you use the correct module code, item number and deadline (not the late deadline) given above. ASDAC are available to any students who disclose a disability or require additional support for their academic studies, with a good set of resources on the ASDAC Moodle site The University takes any form of academic misconduct (such as plagiarism or cheating) seriously, so please make sure your work is your own. Please ensure you adhere to our Code of Student Behaviour. • Any material included in your coursework should be TECFAC 08 Plagiarism fully cited and referenced in APA 7 format. Detailed advice on referencing is available from the library. • Any material submitted that does not meet format or submission guidelines, or falls outside the submission deadline could be subject to a cap on your overall result or disqualification entirely. • Instead of referring to external sites for help, join our Module Discord channel to post your questions. If you need additional assistance, ask your personal tutor or the student engagement officer at ana.baker@port.ac.uk. The faculty academic tutors are also available for you to book a one-to-one session with them using the Moodle page for faculty academic tutors. If you are concerned about your mental well-being, please contact our Well-being service. M30299, Item 6 Python Coursework 2: Smart Home Scenario A fictional UK-Finnish company, Alikoti, develops eco-friendly smart home technologies. Since 2011 they have developed fully integrated Smart Home Solutions. Since 2022 they have begun selling standalone smart home devices, including smart lights and smart fridges, to be supported by third-party software. Last year, the company made the decision to build its own Smart Home App. They have asked you to develop a prototype GUI app. This prototype must provide a graphical user interface that interacts with a smart home object. The smart home object is responsible for managing data for all smart devices. The company will use this prototype to make a business case for a fully developed application. Tasks This document contains a list of tasks. Tasks 1, 2 and 3 must be completed in a file named backend.py and tasks 4 and 5 should be done in frontend.py. It is suggested that you complete the tasks in this order. Note that it is not compulsory to complete the challenge features. Only attempt these if you feel confident and have completed tasks 1–5. Once you are ready to submit, zip (compress) the folder containing both files (backend.py and frontend.py). No other files should be included in the folder. Please make sure you submit a .zip file (not.rar, .7z, .tar or .pdf). Submit your zip file using the link on Moodle (in the Assessments tab) called "Item 6 - Python Smart Home Assignment Dropbox". Task 1 — SmartPlug Class [15 marks] In backend.py, create a class called SmartPlug. This class represents a smart plug object with the instance variables and methods described below: SmartPlug switchedOn: bool consumptionRate: int _init_(consumptionRate: int) toggleSwitch() getSwitched On(): bool getConsumption Rate(): int setConsumption Rate(rate: int) _str_(): str The SmartPlug class should have two instance variables: switched On and consumptionRate. switched on represents the plug's operational status, while consumption Rate indicates the rate of consumption within the range of 0 to 150. The constructor should initialise switched on to False (representing off) and set consumption Rate to an initial value set from the supplied parameter. The SmartPlug class should include a toggleSwitch method to modify the operational status (from off to on, and on to off), an accessor method for retrieving the operational status, and both accessor and mutator methods for handling the consumption rate. Make sure that your accessor and mutator methods handle invalid parameters appropriately. Finally, add a __str_ method to provide a human- readable string representation of a SmartPlug object. Testing Test your SmartPlug class by writing a testSmartPlug function outside the SmartPlug class. The testSmartPlug function should: 1. Create an instance of the SmartPlug class with a consumption rate of 45. 2. Toggle the status of this plug by calling its toggleSwitch method. 3. Print the value of switchedon using the appropriate accessor method. 4. Print the value of consumptionRate, set it to a new valid value (of your choice), and then print it again. 5. Print the SmartPlug object. Task 2 - CustomDevice Class [15 marks] Start by looking at table 1 to find out which device you need to create a class for. You should add this class and its test function to backend.py. The diagram and description below are for a generic CustomDevice class that demonstrates the basic idea of what you will have to do from table 1. The class name and option instance variable should be replaced by the class name and instance variable for your custom class from table 1. C CustomDevice switched On: bool option: int _init_() toggleSwitch() getSwitchedon(): bool getOption(): int setOption(option: int) _str_(): str The CustomDevice class should have two instance variables: switched On, reflecting the switch state of the CustomDevice, and option, representing the CustomDevice's specific option as outlined in table 1. The constructor should initialise switched on to a default state of off and set option to its default value from table 1. The class should have a method for toggling the switch state and an accessor method for retrieving it. The class should also have both accessor and mutator methods for handling the CustomDevice's option. Also, ensure your mutator method handles invalid parameters. When an object of your CustomDevice is printed, it should display information about its switch state and the current value of the option (so implement the _ str__ method appropriately). Testing Test your device by writing a testDevice function (this should be named to reflect your particular custom device), which should: 1. Create an instance of your CustomDevice class. 2. Toggle the status of this device using the toggleSwitch method. 3. Print the switched On instance variable using the appropriate accessor method. 4. Print the current value of the option instance variable (from table 1). Then set it to a new value (of your choice). Next, print it again. 5. Print the Custom Device object. Task 3 - SmartHome Class [15 marks] In backend.py, add a SmartHome class that manages and controls a collection of devices. devices: list __init__() SmartHome get Devices(): list getDeviceAt(index: int): object remove DeviceAt(index: int) addDevice(device: object) toggleSwitch(index: int) turnOnAll() turnOffAll() _str_(): str The SmartHome class should include a single instance variable, devices, representing a collection of devices. Each element of this collection can either be a SmartPlug or a custom device. The constructor should ensure that devices is initially empty. The class should have methods that let the user access all devices, retrieve or delete a specific device, and add a device. The user should be able to toggle a specific device but also turn all of them on or off at once. Additionally, when a smart home is printed, it should display a well-formatted message describing all of its devices and their attributes. Ensure that your accessor and mutator methods handle invalid parameters. Testing Test your class by writing a testSmartHome function, which should: 1. Create an instance of the SmartHome class and two instances of the SmartPlug class with consumption rates of 45. Additionally, create an instance of your custom device. 2. Toggle the first plug, hence turning it on. Then set its consumption rate to 150. Then, set the consumptionRate of the second plug to 25. Lastly, set the option of the custom device to a value of your choice. 3. Add both plugs and the custom device to the smart home object. 4. Toggle the status of the second plug using the appropriate method of the smart home object. 5. Print the smart home object. 6. Turn on all devices in the smart home and print the smart home object again. 7. Remove the first device and print the smart home.