Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/bo4e/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
"Messart",
"Messgroesse",
"Messpreistyp",
"Messwert",
"Messwerterfassung",
"Messwertstatus",
"Messwertstatuszusatz",
Expand Down Expand Up @@ -277,6 +278,7 @@
from .com.lastprofil import Lastprofil
from .com.marktgebietinfo import MarktgebietInfo
from .com.menge import Menge
from .com.messwert import Messwert
from .com.positionsaufabschlag import PositionsAufAbschlag
from .com.preis import Preis
from .com.preisgarantie import Preisgarantie
Expand Down
43 changes: 43 additions & 0 deletions src/bo4e/com/messwert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Contains Messwert class
"""

from typing import TYPE_CHECKING, Annotated, Literal, Optional

import pydantic
from pydantic import Field

from ..enum.comtyp import ComTyp
from ..utils import postprocess_docstring
from .com import COM

if TYPE_CHECKING:
from ..com.menge import Menge
from ..enum.messwertstatus import Messwertstatus
from ..enum.messwertstatuszusatz import Messwertstatuszusatz


@postprocess_docstring
class Messwert(COM):
"""
Abbildung eines Messwertes mit Stati, Zeitpunkt und Wert.

.. raw:: html

<object data="../_static/images/bo4e/com/Messwert.svg" type="image/svg+xml"></object>

.. HINT::
`Messwert JSON Schema <https://json-schema.app/view/%23?url=https://raw.githubusercontent.com/BO4E/BO4E-Schemas/{__gh_version__}/src/bo4e_schemas/com/Messwert.json>`_

"""

typ: Annotated[Literal[ComTyp.MESSWERT], Field(alias="_typ")] = ComTyp.MESSWERT

messwertstatus: Optional["Messwertstatus"] = None
"""Gibt den Status des Messwerts an."""
messwertstatuszusatz: Optional["Messwertstatuszusatz"] = None
"""Gibt den Status Zusatz des Messwerts an."""
zeitpunkt: Optional[pydantic.AwareDatetime] = None
"""Gibt den Zeitpunkt des Messwerts an."""
wert: Optional["Menge"] = None
"""Gibt die gemessene Menge an."""
1 change: 1 addition & 0 deletions src/bo4e/enum/comtyp.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ComTyp(StrEnum):
LASTPROFIL = "LASTPROFIL"
MARKTGEBIETINFO = "MARKTGEBIETINFO"
MENGE = "MENGE"
MESSWERT = "MESSWERT"
POSITIONSAUFABSCHLAG = "POSITIONSAUFABSCHLAG"
PREIS = "PREIS"
PREISGARANTIE = "PREISGARANTIE"
Expand Down
28 changes: 28 additions & 0 deletions tests/test_messwert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from datetime import datetime, timezone

import pytest

from bo4e import Menge, Messwert, Messwertstatus, Messwertstatuszusatz
from tests.serialization_helper import assert_serialization_roundtrip


class TestMesswert:
@pytest.mark.parametrize(
"messwert",
[
pytest.param(
Messwert(
messwertstatus=Messwertstatus.ABGELESEN,
messwertstatuszusatz=Messwertstatuszusatz.Z84_LEERSTAND,
zeitpunkt=datetime(2022, 2, 1, 0, 0, 0, tzinfo=timezone.utc),
wert=Menge(),
),
id="all attributes at first level",
),
],
)
def test_serialization_roundtrip(self, messwert: Messwert) -> None:
"""
Test de-/serialisation roundtrip.
"""
assert_serialization_roundtrip(messwert)
Loading