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

from Soti.Connect.SemanticEngine.Conversions import Converter

print("Loading GeneralToBixolonSpeedSRP Converter")

class GeneralToBixolonSpeedSRP(Converter):

    def Execute(self, args):

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

        if val <= 200:
            return 200
        elif val >= 400:
            return 400
        else:
            values = [230, 250, 270, 300, 330, 350, 370]
            val1 = 230
            val2 = abs(val - 230)

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

            return val1;


plugin = GeneralToBixolonSpeedSRP("GeneralToBixolonSpeedSRP")

store.AddConverter(plugin)