#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# System modules
import json

# Third-party modules
from astropy.time import Time

# Custom modules
from config.constants import (dateobs, dir_number, dir_type, frame_number,
                              frame_type, imagetyp)
from devices import cab, cam, dom, foc, lamp, light, rot, tel
from utils.logger import log

offset = tel.offset
camall = cam.all
domaz = dom.azimuth
domop = dom.open
dommov = dom.is_moving
dompark = dom.is_parked
#basic = cab.basic()

now = Time.now()

#####################
##### Init page #####
#####################

init_panel = {

    "Telescope status": {
        "status": tel.park,
        "cover": tel.cover,
    },

    "Telescope offsets": {
        "zd": offset[0],
        "az": offset[1],
        "rot": rot.position,
    },

    "Dome": {
        "az": dom.azimuth,
        "open": dom.open,
        "moving": dommov,
        "parked": dompark,
    }

}

########################
##### Control page #####
########################

control_panel = {

    "Dome": {
        "slaved": dom.slave,
        "moving": dommov,
        "parked": dompark,
        "az": domaz,
        "open": domop,
        #        "position": foc.position,
        "lamp": lamp.state,
        "light": light.state,
    }

}


dumps = {
    "init": init_panel,
    "control": control_panel
}

print(json.dumps(dumps, indent=4))

log.debug(f"Total elapsed time: {(Time.now()-now).sec :.2f}s")
