From 693fbbecf6babdc6c0a03570b10e24a4b6e5a51f Mon Sep 17 00:00:00 2001 From: spacemanspiff2007 <10754716+spacemanspiff2007@users.noreply.github.com> Date: Mon, 25 Mar 2024 13:09:59 +0100 Subject: [PATCH] . --- docs/configuration.rst | 12 ++++-------- docs/operations.rst | 2 +- src/sml2mqtt/config/types.py | 12 ++++++------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/docs/configuration.rst b/docs/configuration.rst index 1ac8751..7833414 100644 --- a/docs/configuration.rst +++ b/docs/configuration.rst @@ -93,14 +93,10 @@ Example # If one operation blocks nothing will be reported for this frame operations: - negative on energy meter status: true # Make value negative based on an energy meter status. Set to "true" to enable or to "false" to disable workaround. If the default obis code for the energy meter is wrong set to the appropriate meter obis code instead - - factor: 3 # Factor with which the value gets multiplied - - offset: 100 # Offset that gets added on the value - - round: 2 # Round to the specified digits - # A sequence of operations that will be evaluated one after another. - # The first value that gets returned by an operation will be used. - - or: - - type: change filter # Filter which passes only changes - - heartbeat filter: 120 # Filter which lets a value pass periodically every specified interval. + - factor: 3 # Factor with which the value gets multiplied + - offset: 100 # Offset that gets added on the value + - round: 2 # Round to the specified digits + - refresh action: 300 # Republish value every 300s Configuration Reference diff --git a/docs/operations.rst b/docs/operations.rst index df30b25..dd156de 100644 --- a/docs/operations.rst +++ b/docs/operations.rst @@ -367,7 +367,7 @@ Examples These are some examples for sml value configurations Energy consumption today -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +-------------------------------------- This will report the power consumption of today diff --git a/src/sml2mqtt/config/types.py b/src/sml2mqtt/config/types.py index 610916c..37e3e09 100644 --- a/src/sml2mqtt/config/types.py +++ b/src/sml2mqtt/config/types.py @@ -1,12 +1,12 @@ from typing import Annotated, TypeAlias from annotated_types import Interval -from pydantic import StrictFloat, StrictInt, StringConstraints +from pydantic import Strict, StrictFloat, StrictInt, StringConstraints ObisHex = Annotated[ str, - StringConstraints(to_lower=True, strip_whitespace=True, pattern=r'[0-9a-fA-F]{12}') + StringConstraints(to_lower=True, strip_whitespace=True, pattern=r'[0-9a-fA-F]{12}', strict=True) ] LowerStr = Annotated[ @@ -17,9 +17,9 @@ Number: TypeAlias = StrictInt | StrictFloat -PercentStr = Annotated[str, StringConstraints(strip_whitespace=True, pattern=r'^\d+\.?\d*\s*%$')] +PercentStr = Annotated[str, Strict(), StringConstraints(strip_whitespace=True, pattern=r'^\d+\.?\d*\s*%$')] -StrippedStr = Annotated[str, StringConstraints(strip_whitespace=True)] +StrippedStr = Annotated[str, Strict(), StringConstraints(strip_whitespace=True)] -MqttTopicStr = Annotated[str, StringConstraints(strip_whitespace=True, min_length=1)] -MqttQosInt = Annotated[int, Interval(ge=0, le=2)] +MqttTopicStr = Annotated[str, Strict(), StringConstraints(strip_whitespace=True, min_length=1)] +MqttQosInt = Annotated[int, Strict(), Interval(ge=0, le=2)]