"""
This spidr_communicator.py is generated by FB Devkit. This file contains the FB and spidr communication mechanism.
Please do not modify this file.
"""
import sys
import json

def get_datain(key):
    """
    Parse the json string and get the corresponding key value by key
    @params
        key string - creem workflow xml element <cm:Input>
    @returns
        param[key] - parameter value of input key, type can be list, int, float, string, dict etc..
    """

    param = json.loads(sys.argv[1])
    if key in param:
        return param[key]

def get_duration():
    
    """
    Get the parameter value corresponding to duration
    @returns
        duration - float type
    """
    
    
    duration: float = json.loads(get_datain('duration'))
    return duration



def update_state(machine_state):
    print(json.dumps({"result.state":machine_state}))


# Get param input instance in spidr communicator
def get_param_input():
    return ParamInput()


# Get param output instance in spidr communicator
def get_param_output():
    return ParamOutput()


# The parameter input class, all input parameter can get here
class ParamInput():

    def __init__(self):
        self.duration = get_duration()


# The parameter output class, all output parameter can set here
class ParamOutput():

    def __init__(self):
        pass

    def send_to_spidr(self):
        pass
