def __init__(self, protocol, dataInput):
        """Initalize the Tahoma Device."""
        self.__protocol = protocol
        self.__raw_data = dataInput
        self.__active_states = {}

        debug_output = json.dumps(dataInput)

        if 'label' not in dataInput.keys():
            raise ValueError('No device name found: ' + debug_output)

        self.__label = dataInput['label']

        if 'controllableName' not in dataInput.keys():
            raise ValueError('No control label name found: ' + debug_output)

        self.__type = dataInput['controllableName']

        if 'deviceURL' not in dataInput.keys():
            raise ValueError('No control URL: ' + debug_output)

        self.__url = dataInput['deviceURL']

        # Parse definitions

        if 'definition' not in dataInput.keys():
            raise ValueError('No device definition found: ' + debug_output)

        self.__definitions = {
            'commands': [],
            'states': []
        }

        definition = dataInput['definition']

        if 'commands' in definition.keys():
            for command in definition['commands']:
                if command['commandName'] in self.__definitions['commands']:
                    raise ValueError("Command '" + command['commandName'] +
                                     "' double defined - " + debug_output)

                self.__definitions['commands'].append(command['commandName'])

        if 'states' in definition.keys():
            for state in definition['states']:
                if state['qualifiedName'] in self.__definitions['states']:
                    raise ValueError("State '" + state['qualifiedName'] +
                                     "' double defined - " + debug_output)

                self.__definitions['states'].append(state['qualifiedName'])

        # Parse active states

        # calculate the amount of known active states
        active_states_amount = 0
        if 'states' in dataInput.keys():
            for state in dataInput['states']:
                active_states_amount += 1

        # make sure there are not more active states than definitions
        if active_states_amount > len(self.state_definitions):
            raise ValueError(
                "Missmatch of state definition and active states (" +
                str(len(self.state_definitions)) + "/" +
                str(active_states_amount) + "): " + debug_output)

        if len(self.state_definitions) > 0:

            if 'states' in dataInput.keys():
                #raise ValueError("No active states given.")

                for state in dataInput['states']:

                    if state['name'] not in self.state_definitions:
                        raise ValueError(
                            "Active state '" + state['name'] +
                            "' has not been defined: " + debug_output)

                    if state['name'] in self.__active_states.keys():
                        raise ValueError(
                            "Active state '" + state['name'] +
                            "' has been double defined: " + debug_output)

                    self.__active_states[state['name']] = state['value']
def __init__ ( self , protocol , dataInput ) : self . __protocol = protocol self . __raw_data = dataInput self . __active_states = { } debug_output = json . dumps ( dataInput ) if 'label' not in dataInput . keys ( ) : raise ValueError ( 'No device name found: ' + debug_output ) self . __label = dataInput [ 'label' ] if 'controllableName' not in dataInput . keys ( ) : raise ValueError ( 'No control label name found: ' + debug_output ) self . __type = dataInput [ 'controllableName' ] if 'deviceURL' not in dataInput . keys ( ) : raise ValueError ( 'No control URL: ' + debug_output ) self . __url = dataInput [ 'deviceURL' ] if 'definition' not in dataInput . keys ( ) : raise ValueError ( 'No device definition found: ' + debug_output ) self . __definitions = { 'commands' : [ ] , 'states' : [ ] } definition = dataInput [ 'definition' ] if 'commands' in definition . keys ( ) : for command in definition [ 'commands' ] : if command [ 'commandName' ] in self . __definitions [ 'commands' ] : raise ValueError ( "Command '" + command [ 'commandName' ] + "' double defined - " + debug_output ) self . __definitions [ 'commands' ] . append ( command [ 'commandName' ] ) if 'states' in definition . keys ( ) : for state in definition [ 'states' ] : if state [ 'qualifiedName' ] in self . __definitions [ 'states' ] : raise ValueError ( "State '" + state [ 'qualifiedName' ] + "' double defined - " + debug_output ) self . __definitions [ 'states' ] . append ( state [ 'qualifiedName' ] ) active_states_amount = 0 if 'states' in dataInput . keys ( ) : for state in dataInput [ 'states' ] : active_states_amount += 1 if active_states_amount > len ( self . state_definitions ) : raise ValueError ( "Missmatch of state definition and active states (" + str ( len ( self . state_definitions ) ) + "/" + str ( active_states_amount ) + "): " + debug_output ) if len ( self . state_definitions ) > 0 : if 'states' in dataInput . keys ( ) : for state in dataInput [ 'states' ] : if state [ 'name' ] not in self . state_definitions : raise ValueError ( "Active state '" + state [ 'name' ] + "' has not been defined: " + debug_output ) if state [ 'name' ] in self . __active_states . keys ( ) : raise ValueError ( "Active state '" + state [ 'name' ] + "' has been double defined: " + debug_output ) self . __active_states [ state [ 'name' ] ] = state [ 'value' ]
Initalize the Tahoma Device.