Files
cnc-service/src/resources.py
Torma Kristóf 028313380f
All checks were successful
continuous-integration/drone/push Build is passing
remove state capabilities
2021-06-12 19:55:27 +02:00

92 lines
2.1 KiB
Python

#!/usr/bin/env python3
from flask_restful import Resource
from mqtt_flask_instance import mqtt
import config
"""
Flask Restful endpoints
"""
__author__ = '@tormakris'
__copyright__ = "Copyright 2020, Birbnetes Team"
__module_name__ = "resources"
__version__text__ = "1"
class AllDevicesOfflineResource(Resource):
"""
Shut down all devices
"""
def post(self):
"""
Shut down every device
:return:
"""
mqtt.publish(f"{config.MQTT_COMMAND_TOPIC}/+", {"command": "offline"})
class AllDevicesOnlineResource(Resource):
"""
Bring every device online
"""
def post(self):
"""
Bring every device online
:return:
"""
mqtt.publish(f"{config.MQTT_COMMAND_TOPIC}/+", {"command": "online"})
class DeviceOfflineResrouce(Resource):
"""
Bring a device offline
"""
def post(self, deviceid: str):
"""
Shut down a device
:param deviceid: ID of device
:return:
"""
mqtt.publish(f"{config.MQTT_COMMAND_TOPIC}/{deviceid}", {"command": "offline"})
class DeviceOnlineResrouce(Resource):
"""
Bring a device online
"""
def post(self, deviceid: str):
"""
Bring a device online
:param deviceid: ID of device
:return:
"""
mqtt.publish(f"{config.MQTT_COMMAND_TOPIC}/{deviceid}", {"command": "online"})
class SensorOfflineResource(Resource):
"""
Bring a sensor offline
"""
def post(self, deviceid: str, sensorid: str):
"""
Shut down a sensor of a device
:param deviceid: ID of device
:param sensorid: ID of sensor
:return:
"""
mqtt.publish(f"{config.MQTT_COMMAND_TOPIC}/{deviceid}/{sensorid}", {"command": "offline"})
class SensorOnlineResource(Resource):
"""
Bring a sensor online
"""
def post(self, deviceid: str, sensorid: str):
"""
Bring a sensor online
:param deviceid: ID of device
:param sensorid: ID of sensor
:return:
"""
mqtt.publish(f"{config.MQTT_COMMAND_TOPIC}/{deviceid}/{sensorid}", {"command": "online"})