import clr
clr.AddReference('Soti.IoT.SemanticEngine.Conversions')

from Soti.IoT.SemanticEngine.Conversions import Converter

print("Loading GeneralTocabSquixSpeed Converter")

class GeneralTocabSquixSpeed(Converter):

	def Execute(self, myList=[], *args):

		val = int(float(myList[0]))

		if val <= 30:
			return 30
		elif val >= 300:
			return 300
		else:
			values = [30, 40, 50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300]
			val1 = 230
			val2 = abs(val - 230)

			for item in values:
				diff = abs(item - val)
				if  diff < val2:
					val1 = item
					val2 = diff

			return val1;		


plugin = GeneralTocabSquixSpeed("GeneralTocabSquixSpeed")

store.AddConverter(plugin)