def plugin_reconfigure(handle, new_config):
    """ Reconfigures the plugin

    Args:
        handle: handle returned by the plugin initialisation call
        new_config: JSON object representing the new configuration category for the category
    Returns:
        new_handle: new handle to be used in the future calls
    """
    _LOGGER.info("Old config for testsample plugin {} \n new config {}".format(
        handle, new_config))
    # Find diff between old config and new config
    diff = utils.get_diff(handle, new_config)
    # Plugin should re-initialize and restart if key configuration is changed
    if 'dataPointsPerSec' in diff or 'assetName' in diff or 'noOfAssets' in diff:
        plugin_shutdown(handle)
        new_handle = plugin_init(new_config)
        new_handle['restart'] = 'yes'
        _LOGGER.info(
            "Restarting testsample plugin due to change in configuration key [{}]"
            .format(', '.join(diff)))
    else:
        new_handle = copy.deepcopy(new_config)
        new_handle['restart'] = 'no'
    return new_handle
예제 #2
0
def plugin_reconfigure(handle, new_config):
    """  Reconfigures the plugin

    it should be called when the configuration of the plugin is changed during the operation of the South device service;
    The new configuration category should be passed.

    Args:
        handle: handle returned by the plugin initialisation call
        new_config: JSON object representing the new configuration category for the category
    Returns:
        new_handle: new handle to be used in the future calls
    Raises:
    """
    _LOGGER.info("Old config for COAP plugin {} \n new config {}".format(
        handle, new_config))

    # Find diff between old config and new config
    diff = utils.get_diff(handle, new_config)

    # Plugin should re-initialize and restart if key configuration is changed
    if 'port' in diff or 'uri' in diff or 'management_host' in diff:
        _plugin_stop(handle)
        new_handle = plugin_init(new_config)
        new_handle['restart'] = 'yes'
        _LOGGER.info(
            "Restarting COAP plugin due to change in configuration keys [{}]".
            format(', '.join(diff)))
    else:
        new_handle = copy.deepcopy(handle)
        new_handle['restart'] = 'no'
    return new_handle
예제 #3
0
def plugin_reconfigure(handle, new_config):
    """ Reconfigures the plugin

    it should be called when the configuration of the plugin is changed during the operation of the south service.
    The new configuration category should be passed.

    Args:
        handle: handle returned by the plugin initialisation call
        new_config: JSON object representing the new configuration category for the category
    Returns:
        new_handle: new handle to be used in the future calls
    Raises:
    """

    _LOGGER.info("Old config for B100 plugin {} \n new config {}".format(
        handle, new_config))

    diff = utils.get_diff(handle, new_config)

    if 'address' in diff or 'port' in diff:
        plugin_shutdown(handle)
        new_handle = plugin_init(new_config)
        new_handle['restart'] = 'yes'
        _LOGGER.info(
            "Restarting Modbus TCP plugin due to change in configuration keys [{}]"
            .format(', '.join(diff)))
    else:
        new_handle = copy.deepcopy(new_config)
        new_handle['restart'] = 'no'

    return new_handle
def plugin_reconfigure(handle, new_config):
    """  Reconfigures the plugin

    it should be called when the configuration of the plugin is changed during the operation of the South device service;
    The new configuration category should be passed.

    Args:
        handle: handle returned by the plugin initialisation call
        new_config: JSON object representing the new configuration category for the category
    Returns:
        new_handle: new handle to be used in the future calls
    Raises:
    """
    _LOGGER.info("Old config for ENVHATPOLL plugin {} \n new config {}".format(
        handle, new_config))

    # Find diff between old config and new config
    diff = utils.get_diff(handle, new_config)

    # Plugin should re-initialize and restart if key configuration is changed
    if 'pollInterval' in diff:
        new_handle = copy.deepcopy(new_config)
        new_handle['restart'] = 'no'
    else:
        new_handle = copy.deepcopy(handle)
        new_handle['restart'] = 'no'
    return new_handle
예제 #5
0
def plugin_reconfigure(handle, new_config):
    """ Reconfigures the plugin, it should be called when the configuration of the plugin is changed during the
        operation of the south service.
        The new configuration category should be passed.

    Args:
        handle: handle returned by the plugin initialisation call
        new_config: JSON object representing the new configuration category for the category
    Returns:
        new_handle: new handle to be used in the future calls
    Raises:
    """
    _LOGGER.info("Old config for Wind Sensors plugin {} \n new config {}".format(handle, new_config))

    # Find diff between old config and new config
    diff = utils.get_diff(handle, new_config)

    # Plugin should re-initialize and restart if i2cURL configuration is changed
    if 'i2cURL' in diff:
        # TODO: disconnect before restart ?
        new_handle = plugin_init(new_config)
        new_handle['restart'] = 'yes'
        _LOGGER.info("Restarting Wind Sensors plugin due to change in configuration keys [{}]".format(', '.join(diff)))
    else:
        new_handle = copy.deepcopy(new_config)
        new_handle['am2315'] = handle['am2315']
        new_handle['ina219'] = handle['ina219']
        new_handle['mma8451'] = handle['mma8451']
        new_handle['temperatureModCount'] = 0
        new_handle['humidityModCount'] = 0
        new_handle['currentModCount'] = 0
        new_handle['accelerationModCount'] = 0
        new_handle['restart'] = 'no'

    return new_handle
예제 #6
0
def plugin_reconfigure(handle, new_config):
    """  Reconfigures the plugin

    it should be called when the configuration of the plugin is changed during the operation of the South service;
    The new configuration category should be passed.

    Args:
        handle: handle returned by the plugin initialisation call
        new_config: JSON object representing the new configuration category for the category
    Returns:
        new_handle: new handle to be used in the future calls
    Raises:
    """
    # In this method, cannot use "handle" as it might have changed due to restart. Hence use "_handle".
    global _handle

    bluetooth_adr = _handle['bluetoothAddress']['value']
    _LOGGER.info("Old config for CC2650 {} plugin {} \n new config {}".format(
        bluetooth_adr, _handle, new_config))

    # Find diff between old config and new config
    diff = utils.get_diff(_handle, new_config)

    # Plugin should re-initialize and restart if key configuration is changed
    if 'bluetoothAddress' in diff:
        plugin_shutdown(_handle)
        new_handle = plugin_init(new_config)
        _LOGGER.info(
            "Restarting CC2650 {} plugin due to change in configuration keys [{}]"
            .format(bluetooth_adr, ', '.join(diff)))
    else:
        # If tag remains unchanged, just update _handle with new_config values and return the same
        for h in diff:
            _handle[h] = new_config[h]
        new_handle = {}
        for i, v in _handle.items():
            if i != 'tag':
                new_handle[i] = copy.deepcopy(v)
        new_handle['tag'] = _handle[
            'tag']  # tag copied separately as it does not behave well with copy.deepcopy()
    return new_handle
예제 #7
0
 def test_get_diff(self, test_input_old, test_input_new, expected):
     actual = utils.get_diff(test_input_old, test_input_new)
     assert Counter(expected) == Counter(actual)