Skip to content
focuser.py 1.66 KiB
Newer Older
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'''REST API for Focuser related operations'''

# Third-party modules
from flask import request

from .baseresource import ResourceDev
Davide Ricci's avatar
Davide Ricci committed

# @api.route("/focuser")
class Focuser(ResourceDev):
    '''Secondary mirror position.'''

    def get(self):
        '''Retrieve the secondary mirror position.'''
        res = {
Davide Ricci's avatar
Davide Ricci committed
            "response": self.dev.position,
            "error": self.dev.error,
        }
        return res


# @api.route("/focuser/movement")
class FocuserMovement(ResourceDev):
    '''Manage the secondary mirror position.'''

    def get(self):
        '''Check if the secondary mirror is moving.'''
        res = {
Davide Ricci's avatar
Davide Ricci committed
            "response": self.dev.is_moving,
            "error": self.dev.error,
        }
        return res

    def put(self):
        '''Update the secondary mirror position.'''
        target = request.json
Davide Ricci's avatar
Davide Ricci committed
        self.dev.position = target
Davide Ricci's avatar
Davide Ricci committed
            "response": self.dev.position,
            "error": self.dev.error,
        }
        return res

    # def delete(self):
    #     '''Stop the movement.'''
    #     return
Davide Ricci's avatar
Davide Ricci committed

# @api.route("/connection")
class Connection(ResourceDev):
Davide Ricci's avatar
Davide Ricci committed
    '''Manage the connection to ASCOM.'''

    def get(self):
        '''Check if the focuser is connected.'''

        res = {
            "response": self.dev.connection,
            "error": self.dev.error,
        }
        return res

    def put(self):
        '''Connect or disconnect the focuser.'''

        connection = request.json
Davide Ricci's avatar
Davide Ricci committed
        self.dev.connection = connection
        res = {
            "response": self.dev.connection,
            "error": self.dev.error,
        }
        return res