import compLib.CompLib_pb2 as CompLib_pb2
from compLib.CompLibClient import CompLibClient


class IRSensor(object):
    """Access the different IR Sensors of the robot
    """

    @staticmethod
    def read_all():
        """Read all IR sensors at once.

        :return: Tuple of all current ir sensors
        """
        request = CompLib_pb2.IRSensorsReadAllRequest()
        request.header.message_type = request.DESCRIPTOR.full_name

        response = CompLib_pb2.IRSensorsReadAllResponse()
        response.ParseFromString(CompLibClient.send(request.SerializeToString(), request.ByteSize()))

        return tuple(i for i in response.data)

    @staticmethod
    def enable():
        """Turn on all IR emitters
        """
        request = CompLib_pb2.IRSensorsEnableRequest()
        request.header.message_type = request.DESCRIPTOR.full_name

        CompLibClient.send(request.SerializeToString(), request.ByteSize())

    @staticmethod
    def disable():
        """Turn off all IR emitters
        """
        request = CompLib_pb2.IRSensorsDisableRequest()
        request.header.message_type = request.DESCRIPTOR.full_name

        CompLibClient.send(request.SerializeToString(), request.ByteSize())
