Coverage for C: \ Users \ peaco \ OneDrive \ Documents \ GitHub \ mt_metadata \ mt_metadata \ timeseries \ battery.py: 93%
15 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-10 00:11 -0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-10 00:11 -0800
1# =====================================================
2# Imports
3# =====================================================
4from typing import Annotated
6from pydantic import Field, field_validator, ValidationInfo
8from mt_metadata.base import MetadataBase
9from mt_metadata.common import Comment, StartEndRange
12# =====================================================
13class Battery(MetadataBase):
14 type: Annotated[
15 str | None,
16 Field(
17 default=None,
18 description="Description of battery type.",
19 alias=None,
20 json_schema_extra={
21 "units": None,
22 "required": False,
23 "examples": "pb-acid gel cell",
24 "type": "string",
25 },
26 ),
27 ] = None
29 id: Annotated[
30 str | None,
31 Field(
32 default=None,
33 description="battery id",
34 alias=None,
35 json_schema_extra={
36 "units": None,
37 "required": False,
38 "examples": "battery01",
39 "type": "string",
40 },
41 ),
42 ] = None
44 voltage: Annotated[
45 StartEndRange,
46 Field(
47 default=StartEndRange(),
48 description="Range of voltages.",
49 alias=None,
50 json_schema_extra={
51 "units": "volts",
52 "required": False,
53 "examples": "Range(minimum=0.0, maximum=1.0)",
54 "type": "object",
55 },
56 ),
57 ]
59 comments: Annotated[
60 Comment,
61 Field(
62 default_factory=Comment,
63 description="Any comments about the channel.",
64 alias=None,
65 json_schema_extra={
66 "units": None,
67 "required": False,
68 "examples": "ambient air temperature was chilly, ice on cables",
69 },
70 ),
71 ]
73 @field_validator("comments", mode="before")
74 @classmethod
75 def validate_comments(cls, value, info: ValidationInfo) -> Comment:
76 """
77 Validate that the value is a valid comment.
78 """
79 if isinstance(value, str):
80 return Comment(value=value)
81 return value