1313import hightime as ht
1414from grpc import Channel
1515from ni .datamonikers .v1 .client import MonikerClient
16- from ni .datamonikers .v1 .data_moniker_pb2 import Moniker
1716from ni .datastore .data ._grpc_conversion import (
1817 get_publish_measurement_timestamp ,
1918 populate_publish_condition_batch_request_values ,
2221 populate_publish_measurement_request_value ,
2322 unpack_and_convert_from_protobuf_any ,
2423)
24+ from ni .datastore .data ._types ._error_information import ErrorInformation
25+ from ni .datastore .data ._types ._moniker import Moniker
26+ from ni .datastore .data ._types ._outcome import Outcome
2527from ni .datastore .data ._types ._published_condition import PublishedCondition
2628from ni .datastore .data ._types ._published_measurement import PublishedMeasurement
2729from ni .datastore .data ._types ._step import Step
2830from ni .datastore .data ._types ._test_result import TestResult
2931from ni .measurementlink .discovery .v1 .client import DiscoveryClient
3032from ni .measurements .data .v1 .client import DataStoreClient as DataStoreServiceClient
31- from ni .measurements .data .v1 .data_store_pb2 import (
32- ErrorInformation ,
33- Outcome ,
34- )
3533from ni .measurements .data .v1 .data_store_service_pb2 import (
3634 CreateStepRequest ,
3735 CreateTestResultRequest ,
@@ -227,7 +225,7 @@ def publish_measurement(
227225 value : object , # More strongly typed Union[bool, AnalogWaveform] can be used if needed
228226 step_id : str ,
229227 timestamp : ht .datetime | None = None ,
230- outcome : Outcome . ValueType = Outcome .OUTCOME_UNSPECIFIED ,
228+ outcome : Outcome = Outcome .UNSPECIFIED ,
231229 error_information : ErrorInformation | None = None ,
232230 hardware_item_ids : Iterable [str ] = tuple (),
233231 test_adapter_ids : Iterable [str ] = tuple (),
@@ -291,8 +289,10 @@ def publish_measurement(
291289 publish_request = PublishMeasurementRequest (
292290 measurement_name = measurement_name ,
293291 step_id = step_id ,
294- outcome = outcome ,
295- error_information = error_information ,
292+ outcome = outcome .to_protobuf (),
293+ error_information = (
294+ error_information .to_protobuf () if error_information is not None else None
295+ ),
296296 hardware_item_ids = hardware_item_ids ,
297297 test_adapter_ids = test_adapter_ids ,
298298 software_item_ids = software_item_ids ,
@@ -311,7 +311,7 @@ def publish_measurement_batch(
311311 values : object ,
312312 step_id : str ,
313313 timestamps : Iterable [ht .datetime ] = tuple (),
314- outcomes : Iterable [Outcome . ValueType ] = tuple (),
314+ outcomes : Iterable [Outcome ] = tuple (),
315315 error_information : Iterable [ErrorInformation ] = tuple (),
316316 hardware_item_ids : Iterable [str ] = tuple (),
317317 test_adapter_ids : Iterable [str ] = tuple (),
@@ -372,8 +372,10 @@ def publish_measurement_batch(
372372 measurement_name = measurement_name ,
373373 step_id = step_id ,
374374 timestamps = [hightime_datetime_to_protobuf (ts ) for ts in timestamps ],
375- outcomes = outcomes ,
376- error_information = error_information ,
375+ outcomes = [outcome .to_protobuf () for outcome in outcomes ],
376+ error_information = (
377+ [ei .to_protobuf () for ei in (error_information or [])] if error_information else []
378+ ),
377379 hardware_item_ids = hardware_item_ids ,
378380 test_adapter_ids = test_adapter_ids ,
379381 software_item_ids = software_item_ids ,
@@ -407,7 +409,7 @@ def read_data(
407409
408410 Args:
409411 moniker_source: The source from which to read data. Can be:
410- - A Moniker directly
412+ - A Moniker (wrapper type) directly
411413 - A PublishedMeasurement (uses its moniker)
412414 - A PublishedCondition (uses its moniker)
413415
@@ -428,19 +430,25 @@ def read_data(
428430 TypeError: If expected_type is provided and the actual data type
429431 doesn't match.
430432 """
433+ from ni .datamonikers .v1 .data_moniker_pb2 import Moniker as MonikerProto
434+
435+ moniker_proto : MonikerProto
436+
431437 if isinstance (moniker_source , Moniker ):
432- moniker = moniker_source
438+ moniker_proto = moniker_source . to_protobuf ()
433439 elif isinstance (moniker_source , PublishedMeasurement ):
434440 if moniker_source .moniker is None :
435441 raise ValueError ("PublishedMeasurement must have a Moniker to read data" )
436- moniker = moniker_source .moniker
442+ moniker_proto = moniker_source .moniker . to_protobuf ()
437443 elif isinstance (moniker_source , PublishedCondition ):
438444 if moniker_source .moniker is None :
439445 raise ValueError ("PublishedCondition must have a Moniker to read data" )
440- moniker = moniker_source .moniker
446+ moniker_proto = moniker_source .moniker .to_protobuf ()
447+ else :
448+ raise TypeError (f"Unsupported moniker_source type: { type (moniker_source )} " )
441449
442- moniker_client = self ._get_moniker_client (moniker .service_location )
443- read_result = moniker_client .read_from_moniker (moniker )
450+ moniker_client = self ._get_moniker_client (moniker_proto .service_location )
451+ read_result = moniker_client .read_from_moniker (moniker_proto )
444452 converted_data = unpack_and_convert_from_protobuf_any (read_result .value )
445453 if expected_type is not None and not isinstance (converted_data , expected_type ):
446454 raise TypeError (f"Expected type { expected_type } , got { type (converted_data )} " )
0 commit comments