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

# System modules

from devices import stx  # scientific camera
from devices import ascom  # telescope and dome
from devices import meteo  # meteo station
from devices import astelco  # telescope cabinet
from devices import cabinet  # cabinet switch
from devices import domotics  # camera switch and sensors
from devices import ipcam  #ipcam under the dome

from config.addresses import STX, ASCOM, METEO
from config.addresses import CABINET, DOMOTICS, CABINET_SWITCH, IPCAM

# ASCOM STUFF
tel = ascom.Telescope(ASCOM)
tel.sim = 1  # 0: AstelOS, 1: Hub
foc = ascom.Focuser(ASCOM)
rot = ascom.Rotator(ASCOM)
lamp = ascom.Switch(ASCOM, 2)  # Flat lamp
light = ascom.Switch(ASCOM, 3)  # Dome light
dom = ascom.Dome(ASCOM)
dom.sim = 1  # 0: Ricerca, 1: Hub

# STX CAMERA
cam = stx.Camera(STX)

# METEO STATION
met = meteo.Meteo(METEO)

# CABINET
ast = astelco.OpenTSI(CABINET)
cab = cabinet.Cabinet(CABINET_SWITCH)

# DOMOTICS
sof = domotics.Switch(DOMOTICS, 3)  # fork switch
fork = domotics.Sensor(DOMOTICS, 1, 2)  # temp, hum on fork
rec = domotics.Sensor(DOMOTICS, 5, 4)  # temp, hum of reception
rack = domotics.Sensor(DOMOTICS, 7, 6)  # temp, hum on the rack

#IPCAM
ipcam = ipcam.DlinkDCSCamera(IPCAM)

#
# curl http://ccd-sbig/api/VersionNumbers.cgi
# curl http://orsa-windows.orsa.unige.net:533/api/v1/switch/0/description
# curl "http://antola:davide2022@web8.com.dist.unige.it:8080/json.htm?type=devices&rid=52"


# if __name__ == '__main__':
#     import sys

#     dev = sys.argv[1]
#     met = sys.argv[2]
#     if len(sys.argv) < 4:
#         try:
#             res = globals()[dev]()
#         except TypeError as e:
#             try:
#                 res = getattr(globals()[dev], met)
#                 print(res)
#             except:
#                 log.error(e)
#     else:
#         val = sys.argv[3]
#         res = setattr(globals()[dev], met, val)
#         print(res)
