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

'''REST API for Dome related operations'''

from flask import request
# Custom modules
from config import constants
Davide Ricci's avatar
Davide Ricci committed
from .baseresource import ResourceDev
Davide Ricci's avatar
Davide Ricci committed

# @api.route("/position")
Davide Ricci's avatar
Davide Ricci committed
class Position(ResourceDev):
    '''Get the position of the dome.'''
        '''Check the azimuth of the dome, and if
        this corresponds to the parking position.'''
                "azimuth": self.dev.azimuth,
                "parked": constants.yes_no[self.dev.is_parked],
            "error": self.dev.error,
            "timestamp": self.timestamp,
vertighel's avatar
vertighel committed

# @api.route("/shutter")
Davide Ricci's avatar
Davide Ricci committed
class Shutter(ResourceDev):
        '''Check the state of the dome shutter.'''
            "raw": self.dev.shutter,
            "response": constants.open_state[self.dev.shutter],
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/shutter/movement")
Davide Ricci's avatar
Davide Ricci committed
class ShutterMovement(ResourceDev):
    '''Manage the movement of the dome shutter.'''
        '''Move the shutter to a new position
        (open or closed).'''
        target = request.json
        self.dev.open = target
            "raw": self.dev.open,
            "response": constants.open_state[self.open],
            "error": self.dev.error,
            "timestamp": self.timestamp,
        '''Stop the movement of the shutter.'''
        res = {
            "response": self.dev.abort(),
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/position/slaved")
Davide Ricci's avatar
Davide Ricci committed
class PositionSlaved(ResourceDev):
    '''Manage the minioning of the shutter
    to the telescope.'''
        '''Check if the dome is slaved
        to the telescope or not.'''
            "raw": self.dev.slave,
            "response": constants.yes_no[self.dev.slave],
            "error": self.dev.error,
            "timestamp": self.timestamp,
        '''Make the dome slaved to the telescope
        or release it.'''
        slaved = request.json
        self.dev.slave = slaved
            "raw": self.dev.slave,
            "response": constants.yes_no[self.dev.slave],
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/position/sync")
Davide Ricci's avatar
Davide Ricci committed
class PositionSync(ResourceDev):
    '''Manage the reference azimuth of the dome'''
        '''Tell the dome that its current position
        corresponds to a given azimuth.'''
        new_azimuth = request.json
            "response": self.dev.sync(new_azimuth),
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/position/movement")
Davide Ricci's avatar
Davide Ricci committed
class PositionMovement(ResourceDev):
    '''Manage the movement of the dome.'''
    # @api.marshal_with(model_bool, 200)
        '''Return if the dome is moving or not.'''
            "raw": self.dev.is_moving,
            "response": constants.yes_no[self.dev.is_moving],
            "error": self.dev.error,
            "timestamp": self.timestamp,
        '''Stop the movement of the dome.'''
            "response": self.dev.abort(),
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/position/movement/park")
Davide Ricci's avatar
Davide Ricci committed
class PositionMovementPark(ResourceDev):
    '''Manage the dome parking.'''
        '''Park the dome.'''
            "response": self.dev.park(),
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/position/movement/azimuth")
Davide Ricci's avatar
Davide Ricci committed
class PositionMovementAzimuth(ResourceDev):
    '''Manage the position of the dome.'''
        '''Set a new dome azimuth.'''
        azimuth = request.json
        self.dev.azimuth = azimuth
            "response": self.dev.azimuth,
            "error": self.dev.error,
            "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed

# @api.route("/connection")
Davide Ricci's avatar
Davide Ricci committed
class Connection(ResourceDev):
        '''check if the dome is connected to ASCOM.'''
            "raw": conn,
            "response": constants.yes_no[conn] if bool(conn) else False,
            "error": self.dev.error,
            "timestamp": self.timestamp,
        }
        return res

    def put(self):
        '''Connect or disconnect the telescope to ASCOM.'''
Davide Ricci's avatar
Davide Ricci committed
        connection = request.json
        self.dev.connection = connection
            "raw": self.dev.connection,
            "response": constants.yes_no[self.dev.connection],
            "error": self.dev.error,
            "timestamp": self.timestamp,