diff --git a/src/sdc11073/roles/metricprovider.py b/src/sdc11073/roles/metricprovider.py index dc54e5c3..39a19fe4 100644 --- a/src/sdc11073/roles/metricprovider.py +++ b/src/sdc11073/roles/metricprovider.py @@ -148,7 +148,6 @@ def _set_numeric_value(self, params: ExecuteParameters) -> ExecuteResult: def _set_string(self, params: ExecuteParameters) -> ExecuteResult: """Set a string value (ExecuteHandler).""" value = params.operation_request.argument - pm_types = self._mdib.data_model.pm_types self._logger.info('set value %s from %s to %s', params.operation_instance.operation_target_handle, params.operation_instance.current_value, value) @@ -159,12 +158,5 @@ def _set_string(self, params: ExecuteParameters) -> ExecuteResult: if state.MetricValue is None: state.mk_metric_value() state.MetricValue.Value = value - # SF1823: For Metrics with the MetricCategory = Set|Preset that are being modified as a result of a - # SetValue or SetString operation a Metric Provider shall set the MetricQuality / Validity = Vld. - metric_descriptor_container = self._mdib.descriptions.handle.get_one( - params.operation_instance.operation_target_handle) - if metric_descriptor_container.MetricCategory in (pm_types.MetricCategory.SETTING, - pm_types.MetricCategory.PRESETTING): - state.MetricValue.Validity = pm_types.MeasurementValidity.VALID return ExecuteResult(params.operation_instance.operation_target_handle, self._mdib.data_model.msg_types.InvocationState.FINISHED) diff --git a/tests/70041_MDIB_Final.xml b/tests/70041_MDIB_Final.xml index 2116b07a..5ecc0764 100644 --- a/tests/70041_MDIB_Final.xml +++ b/tests/70041_MDIB_Final.xml @@ -144,6 +144,30 @@ An operation to set the time zone of a clock. + + + + + + + + + An operation to set the patient category. + + + + + + + + + + + + An operation to set a numeric value. + + + diff --git a/tests/test_operations.py b/tests/test_operations.py index 81c58e27..eee17309 100644 --- a/tests/test_operations.py +++ b/tests/test_operations.py @@ -610,4 +610,55 @@ def test_set_operating_mode(self): operation.set_operating_mode(op_mode) time.sleep(1) operation_state = client_mdib.states.descriptor_handle.get_one(operation_handle) - self.assertEqual(operation_state.OperatingMode, op_mode) \ No newline at end of file + self.assertEqual(operation_state.OperatingMode, op_mode) + + def test_set_string_value(self): + """Verify that metricprovider instantiated an operation for SetString call. + + OperationTarget of operation 0815 is an EnumStringMetricState. + """ + set_service = self.sdc_client.client('Set') + client_mdib = ConsumerMdib(self.sdc_client) + client_mdib.init_mdib() + coding = pm_types.Coding('0815') + my_operation_descriptor = self.sdc_device.mdib.descriptions.coding.get_one(coding, allow_none=True) + + operation_handle = my_operation_descriptor.Handle + for value in ('ADULT', 'PEDIATRIC'): + self._logger.info('string value = %s', value) + future = set_service.set_string(operation_handle=operation_handle, requested_string=value) + result = future.result(timeout=SET_TIMEOUT) + state = result.InvocationInfo.InvocationState + self.assertEqual(state, msg_types.InvocationState.FINISHED) + self.assertIsNone(result.InvocationInfo.InvocationError) + self.assertEqual(0, len(result.InvocationInfo.InvocationErrorMessage)) + + # verify that the corresponding state has been updated + state = client_mdib.states.descriptor_handle.get_one(my_operation_descriptor.OperationTarget) + self.assertEqual(state.MetricValue.Value, value) + + def test_set_metric_value(self): + """Verify that metricprovider instantiated an operation for SetNumericValue call. + + OperationTarget of operation 0815-1 is a NumericMetricState. + """ + set_service = self.sdc_client.client('Set') + client_mdib = ConsumerMdib(self.sdc_client) + client_mdib.init_mdib() + coding = pm_types.Coding('0815-1') + my_operation_descriptor = self.sdc_device.mdib.descriptions.coding.get_one(coding, allow_none=True) + + operation_handle = my_operation_descriptor.Handle + for value in (Decimal(1), Decimal(42)): + self._logger.info('metric value = %s', value) + future = set_service.set_numeric_value(operation_handle=operation_handle, + requested_numeric_value=value) + result = future.result(timeout=SET_TIMEOUT) + state = result.InvocationInfo.InvocationState + self.assertEqual(state, msg_types.InvocationState.FINISHED) + self.assertIsNone(result.InvocationInfo.InvocationError) + self.assertEqual(0, len(result.InvocationInfo.InvocationErrorMessage)) + + # verify that the corresponding state has been updated + state = client_mdib.states.descriptor_handle.get_one(my_operation_descriptor.OperationTarget) + self.assertEqual(state.MetricValue.Value, value)