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

from Soti.Connect.SemanticEngine.Conversions import Converter

print("Loading GeneralToBixolonSpeedSRP_v2 Converter")

class GeneralToBixolonSpeedSRP_v2(Converter):

    def Execute(self, args):

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

        if val <= 110:
            return 110
        elif val >= 180:
            return 180

        values = [110, 120, 130, 140, 150, 160, 170, 180]

        closest = values[0]
        min_diff = abs(val - closest)

        for item in values:
            diff = abs(item - val)
            if diff < min_diff:
                closest = item
                min_diff = diff

        return closest

plugin = GeneralToBixolonSpeedSRP_v2("GeneralToBixolonSpeedSRP_v2")

store.AddConverter(plugin)