Home automation
An extensible and moduarized Home automation system built using Flask and Sql Alchemy.
Flask: Flask is a microframework, makes deploying web applications simpler and faster than other conventional methods.
SqlAlchemy: SqlAlchemy is the python SQL toolkit and ObjectRelationalMapper. It provides an easier interface to communicate with databases with its Classes and objects paradigm.
The application allows a user to do the following:
1. Add a new device to the system.
2. Delete an installed device from the system.
3. List all the devices in the system.
4. Perform actions on the system (switching on and switching off a device).
5. Logs of the actions performed on the devices.
Small flask applications can be implemented in a simple way, but larger applications tend to get out of hand and requires to be structured. Structuring a flask applications makes it Highly extensible and modularized.
Model View Controller design pattern is implemented.
Model: A model is responsible for managing data storage.
View: A view is what is presented to the user.
Controller: The brain behind the operations.
- Flask: microframework.
- flask_script: To help write external scripts(eg: migrate,init,upgrade).
- flask_migrate: To make system migrations.
- flask_sqlalchemy: Flask's wrapper for SqlAlchemy toolkit.
- flask_modus: To handle method overrides.
- flask_wtf: Flask's form.
- wtforms
--manage.py
manage.py allows to make migrations in the application, helps access the applications and databases using external scripts. This can be used for testing purposes.
Commands to run
- Signzy$python manage.py db init
Creates the database.
- Signzy$python manage.py db migrate -m "comments"
Creates the tables in the database based on the schema present in Signzy/project/models.py.
- Signzy$python manage.py db upgrade
Creates the database file in Signzy/project/.
--Signzy/project/models.py
can be understood as the schema for the tables in the database. Currently has two tables Devices and Actions, new tables can easily be added in this file. If a new column or table is added in the database.
Signzy$python manage.py db migrate -m "comments"
Signzy$python manage.py db upgrade
--app.py
Runs the application
Signzy$python app.py
The application will be running on the url mentioned in the file(https://127.0.0.1:5000/ as of now).
--Signzy/project/init.py
Creates the database and other configurations like registering the blueprints of the resources.
--Signzy/project/ consists of two folders called devices and actions, these are the resources or modules of the application. New modules can be added by following the file structure present in other modules.
RESOURCES:
Signzy/project/devices/ has the files views.py which has the APIs related to devices and forms.py has various form validation techniques for the forms pertaining to these APIs and csrf token retention techniques which makes the forms secure.
devices/templates/devices has the html files for these APIs.
Signzy/project/actions/ has the files views.py which has the APIs related to devices and forms.py has various form validation techniques for the forms pertaining to these APIs and csrf token retention techniques which makes the forms secure.
devices/templates/actions has the html files for these APIs.