import time
import asyncio


async def checkTemp(tempObj,LEDObj,loop):
    """Samples temperature reading and returns it, and also flashes RED or GREEN LED based on weather the temp reading is higher than threshold.

    :param tempObj: Object from Temp class
    :type tempObj: temp
    :param LEDObj: Object from LED class
    :type LEDObj: LED
    :param loop: Main event loop to be used to run coroutines concurrenlty
    :type loop: asyncio application
    :return: Temperature value of target object
    :rtype: float
    """
    tic = time.perf_counter()
    tempValue = await asyncio.gather(tempObj.readTemp())
    toc = time.perf_counter()  
    print(f"Time taken to get Temp readings: {toc - tic:0.4f} seconds")
    if tempValue[0] < 35.00 and tempValue[0] > 29.00:
        tic = time.perf_counter() 
        asyncio.gather(LEDObj.swichOnTempGreen())
        toc = time.perf_counter()  
        print(f"Time taken to toggle red LED: {toc - tic:0.4f} seconds")  
        return tempValue
        
    else:
        tic = time.perf_counter()
        asyncio.gather(LEDObj.swichOnTempRed())
        toc = time.perf_counter()  
        print(f"Time taken to toggle green LED :{toc - tic:0.4f} seconds")  
        return tempValue