Newer
Older
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
'''REST API for Switch related operations'''
# Third-party modules
from flask import request
# Custom modules
from config import constants
from .baseresource import ResourceDev
# @api.route("/dome/light")
# @api.route("/telescope/lamp")
# @api.route("/camera/power")
class State(ResourceDev):
'''Manage a switch state.'''
def __init__(self, *args, **kwargs):
'''Constructor.'''
super().__init__(self, *args, **kwargs)
self.dev = kwargs["dev"]
def get(self):
'''Check if the switch on or off.'''
res = {
"raw": self.dev.state,
"response": constants.on_off[self.dev.state],
}
return res
def put(self):
'''Switch on or off.'''
state = request.json
self.dev.state = state
res = {
"raw": self.dev.state,
"response": constants.on_off[self.dev.state],