import json
import configparser
import socket
import threading
import os
import sys
import traceback
from digtemp import read_dig_temp
sys.path.append( "../lib" )
from iseclogger import Logger


from rpiinfo import get_temperature

#remove _dud for production
from rpictrl import addGPIOEvent
from rpictrl import getGPIOInput
from rpictrl import getGPIOOutputStatusVerbose
from rpictrl import initOutputGPIO

import pdb


class PeripheralObject:
    serialid = None
    devid = None
    name = None
    description = None
    ptype = None
    pgpio = None
    

class LocalPeripherals:

    CFG_PERI_SECTION_MAIN="main"
    CFG_PERI_SECTION_PERI="peri_{0}"
    CFG_PERI_ID = "id"
    CFG_PERI_ID_SERIAL = "id_serial"
    CFG_PERI_NAME = "name"
    CFG_PERI_DESCRIPTION = "description"
    CFG_PERI_TYPE="type"
    CFG_PERI_COUNT="count"
    CFG_PERI_GPIO="gpio"

    ST_DEV_NAME = "device_name"
    ST_DEV_ID = "device_id"
    ST_PERIPHERAL_ID = "peripheral_id"
    ST_DEV_SERIAL_ID = "device_serial_id"
    ST_DEV_TYPE = "device_type"
    ST_DEV_DESC = "device_desc"

    filename = "../cfg/peripherals.cfg";
    
    log = None
    _peripherals = []
    
    def __init__(self, logger):
        self.log = logger
        
    def load(self):
        self._peripherals = []
        
        peri_config = configparser.ConfigParser()
        peri_config.read(self.filename)
        sectionmain = dict(peri_config.items(self.CFG_PERI_SECTION_MAIN))