def enable_feature(self, feature_name, callback):
        """
        Enable the given feature by subscribing to the appropriate topics.

        :param feature_name: one of the feature name constants from constant.py
        :param callback: callback which is called when the feature is enabled

        :raises: ValueError if feature_name is invalid
        """
        logger.debug("enable_feature {} called".format(feature_name))
        if feature_name not in self.feature_enabled:
            raise ValueError("Invalid feature_name")

        def on_complete(op, error):
            if error:
                logger.warning(
                    "Subscribe for {} failed.  Not enabling feature".format(
                        feature_name))
            else:
                self.feature_enabled[feature_name] = True
            callback(error=error)

        self._pipeline.run_op(
            pipeline_ops_base.EnableFeatureOperation(feature_name=feature_name,
                                                     callback=on_complete))
    def enable_feature(self, feature_name, callback=None):
        """
        Enable the given feature by subscribing to the appropriate topics.

        :param feature_name: one of the feature name constants from constant.py
        :param callback: callback which is called when the feature is enabled

        :raises: ValueError if feature_name is invalid
        """
        logger.info("enable_feature {} called".format(feature_name))
        if feature_name not in self.feature_enabled:
            raise ValueError("Invalid feature_name")
        self.feature_enabled[feature_name] = True

        def on_complete(call):
            if call.error:
                # TODO we need error semantics on the client
                sys.exit(1)
            if callback:
                callback()

        self._pipeline.run_op(
            pipeline_ops_base.EnableFeatureOperation(
                feature_name=feature_name, callback=on_complete
            )
        )
    def enable_responses(self, callback=None):
        """
        Enable response from the DPS service by subscribing to the appropriate topics.

        :param callback: callback which is called when responses are enabled
        """
        logger.debug("enable_responses called")

        self.responses_enabled[provisioning_constants.REGISTER] = True

        def pipeline_callback(op, error):
            callback(error=error)

        self._pipeline.run_op(
            pipeline_ops_base.EnableFeatureOperation(
                feature_name=None, callback=pipeline_callback))
Esempio n. 4
0
    def enable_responses(self, callback=None):
        """
        Disable response from the DPS service by subscribing to the appropriate topics.

        :param callback: callback which is called when the feature is enabled
        """
        logger.debug("enable_responses called")

        def pipeline_callback(call):
            if call.error:
                # TODO we need error semantics on the client
                exit(1)
            if callback:
                callback()

        self._pipeline.run_op(
            pipeline_ops_base.EnableFeatureOperation(feature_name=None, callback=pipeline_callback)
        )
    def enable_feature(self, feature_name, callback):
        """
        Enable the given feature by subscribing to the appropriate topics.

        :param feature_name: one of the feature name constants from constant.py
        :param callback: callback which is called when the feature is enabled

        :raises: ValueError if feature_name is invalid
        :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.PipelineNotRunning` if the
            pipeline has previously been shut down

        The following exceptions are not "raised", but rather returned via the "error" parameter
        when invoking "callback":

        :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.NoConnectionError`
        :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.ProtocolClientError`

        The following exceptions can be returned via the "error" parameter only if auto-connect
        is enabled in the pipeline configuration:

        :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.ConnectionFailedError`
        :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.ConnectionDroppedError`
        :raises: :class:`azure.iot.device.iothub.pipeline.exceptions.UnauthorizedError`
        """
        self._verify_running()
        logger.debug("enable_feature {} called".format(feature_name))
        if feature_name not in self.feature_enabled:
            raise ValueError("Invalid feature_name")
        # TODO: What about if the feature is already enabled?

        def on_complete(op, error):
            if error:
                logger.error("Subscribe for {} failed.  Not enabling feature".format(feature_name))
            else:
                self.feature_enabled[feature_name] = True
            callback(error=error)

        self._pipeline.run_op(
            pipeline_ops_base.EnableFeatureOperation(
                feature_name=feature_name, callback=on_complete
            )
        )
Esempio n. 6
0
    def enable_responses(self, callback=None):
        """
        Enable response from the DPS service by subscribing to the appropriate topics.

        :raises: :class:`azure.iot.device.provisioning.pipeline.exceptions.PipelineNotRunning` if the
            pipeline has already been shut down

        :param callback: callback which is called when responses are enabled
        """
        self._verify_running()
        logger.debug("enable_responses called")

        self.responses_enabled[provisioning_constants.REGISTER] = True

        def pipeline_callback(op, error):
            callback(error=error)

        self._pipeline.run_op(
            pipeline_ops_base.EnableFeatureOperation(
                feature_name=provisioning_constants.REGISTER,
                callback=pipeline_callback))
Esempio n. 7
0
 def op(self, mocker):
     return pipeline_ops_base.EnableFeatureOperation(
         feature_name="fake_feature_name", callback=mocker.MagicMock()
     )
 def op(self, mocker, iothub_pipeline_feature):
     return pipeline_ops_base.EnableFeatureOperation(
         feature_name=iothub_pipeline_feature, callback=mocker.MagicMock())
 def op(self, mocker):
     return pipeline_ops_base.EnableFeatureOperation(
         feature_name=pipeline_constant.REGISTER,
         callback=mocker.MagicMock())