async def set_publishing_mode(self, publishing: bool) -> ua.uatypes.StatusCode: """ Disable publishing of NotificationMessages for the subscription, but doesn't discontinue the sending of keep-alive Messages, nor change the monitoring mode. :param publishing: The publishing mode to apply :return: Return a Set Publishing Mode Result """ self.logger.info("set_publishing_mode") params = ua.SetPublishingModeParameters() params.SubscriptionIds = [self.subscription_id] params.PublishingEnabled = publishing result = await self.server.set_publishing_mode(params) if result[0].is_good(): self.parameters.PublishingEnabled = publishing return result
async def test_set_publishing_mode(opc, mocker): """ test flipping the publishing parameter for an existing subscription """ myhandler = MySubHandler() o = opc.opc.nodes.objects publishing_mode = ua.SetPublishingModeParameters() mock_set_monitoring = mocker.patch.object(ua, "SetPublishingModeParameters", return_value=publishing_mode) mock_client_monitoring = mocker.patch("asyncua.client.ua_client.UaClient.set_publishing_mode", new=CoroutineMock()) v = await o.add_variable(3, 'SubscriptionVariable', 123) sub = await opc.opc.create_subscription(100, myhandler) await sub.set_publishing_mode(False) assert publishing_mode.PublishingEnabled == False await sub.set_publishing_mode(True) assert publishing_mode.PublishingEnabled == True