try:
	import RPi.GPIO as GPIO #Importe la bibliothèque pour contrôler les GPIOs
	test_environment = False
except (ImportError, RuntimeError):
	test_environment = True

import time

class GPIOController:
	
	def __init__(self):
		self.test_environment = test_environment
		self.regions_leds = {
			"Eastern Asia": 4,
			"Europe": 18,
			"Africa": 23,
			"Oceania": 24,
			"Northern America": 25,
			"South America": 12,
			"Western Asia": 16
		}
		self.regions_leds_states = {}
		
		if not test_environment:
			#Définit le mode de numérotation (Board)
			GPIO.setmode(GPIO.BCM)
			#On désactive les messages d'alerte
			GPIO.setwarnings(False)
			
			#Active le contrôle du GPIO
			for region in self.regions_leds:
				GPIO.setup(self.regions_leds[region], GPIO.OUT)
			
			self.read_state()

	def read_state(self):
		
		#Lit l'état actuel du GPIO, vrai si allumé, faux si éteint
		if not test_environment:
			for region in self.regions_leds:
				self.regions_leds_states[region] = GPIO.input(self.regions_leds[region])
				
	def switch_leds_states(self, regions_booleans = {
			"Eastern Asia": True,
			"Europe": True,
			"Africa": True,
			"Oceania": True,
			"Northern America": True,
			"South America": True,
			"Western Asia": True
		}):
			
		if not test_environment:
			
			for region in regions_booleans:
				if regions_booleans[region] :
					GPIO.output(self.regions_leds[region], GPIO.HIGH) 
				else:
					GPIO.output(self.regions_leds[region], GPIO.LOW) 
				
				time.sleep(0.5)
			
			self.read_state()
