-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 41ed321
Showing
6 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
instance | ||
.vscode |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
.PHONY: install | ||
install: | ||
pipenv install | ||
|
||
.PHONY: dev | ||
dev: | ||
pipenv run python app.py |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[[source]] | ||
name = "pypi" | ||
url = "https://pypi.org/simple" | ||
verify_ssl = true | ||
|
||
[dev-packages] | ||
|
||
[packages] | ||
flask = "*" | ||
flask-mqtt = "*" | ||
flask-restful = "*" | ||
|
||
[requires] | ||
python_version = "3.7" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Roller Shutter | ||
|
||
TODO |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from flask import Flask | ||
from flask_restful import Resource, Api, reqparse | ||
from flask_mqtt import Mqtt | ||
|
||
app = Flask(__name__, instance_relative_config=True) | ||
app.config.from_pyfile("config.py") | ||
api = Api(app) | ||
mqtt = Mqtt(app) | ||
|
||
parser = reqparse.RequestParser() | ||
parser.add_argument("command", type=str, help="") | ||
|
||
|
||
@mqtt.on_connect() | ||
def handle_connect(client, userdata, flags, rc): | ||
mqtt.subscribe("shellies/command") | ||
for blind in app.config.get("BLINDS", []): | ||
# mqtt.subscribe("shellies/{id}".format(id=blind.get("id", ""))) | ||
mqtt.subscribe("shellies/{id}/online".format(id=blind.get("id", ""))) | ||
mqtt.subscribe("shellies/{id}/roller/0/pos".format(id=blind.get("id", ""))) | ||
mqtt.subscribe("shellies/{id}/roller/0".format(id=blind.get("id", ""))) | ||
|
||
|
||
@mqtt.on_message() | ||
def handle_mqtt_message(client, userdata, message): | ||
print("{} - {}".format(message.topic, message.payload)) | ||
|
||
|
||
class HomePage(Resource): | ||
def get(self): | ||
return app.config.get("BLINDS", []) | ||
|
||
|
||
class Announce(Resource): | ||
def get(self): | ||
# force all shellies to announce their status | ||
mqtt.publish("shellies/command", "announce") | ||
return "", 204 | ||
|
||
|
||
class Update(Resource): | ||
def get(self): | ||
# force all shellies to announce their status | ||
mqtt.publish("shellies/command", "update") | ||
return "", 204 | ||
|
||
|
||
class Open(Resource): | ||
def get(self, id): | ||
mqtt.publish("shellies/{id}/roller/0/command".format(id=id), "open") | ||
return "", 204 | ||
|
||
|
||
class Close(Resource): | ||
def get(self, id): | ||
mqtt.publish("shellies/{id}/roller/0/command".format(id=id), "close") | ||
return "", 204 | ||
|
||
|
||
class Stop(Resource): | ||
def get(self, id): | ||
mqtt.publish("shellies/{id}/roller/0/command".format(id=id), "stop") | ||
return "", 204 | ||
|
||
|
||
class Command(Resource): | ||
def post(self): | ||
args = parser.parse_args() | ||
mqtt.publish("shellies/shellyswitch25-68E5F8/roller/0/command", "close") | ||
return {todo_id: todos[todo_id]} | ||
|
||
|
||
api.add_resource(HomePage, "/") | ||
api.add_resource(Announce, "/announce") | ||
api.add_resource(Update, "/update") | ||
api.add_resource(Command, "/command") | ||
api.add_resource(Close, "/<string:id>/close") | ||
api.add_resource(Open, "/<string:id>/open") | ||
api.add_resource(Stop, "/<string:id>/stop") | ||
|
||
if __name__ == "__main__": | ||
app.run(debug=False) |