From 22306f06962ab61448ef0c54d09e92318675fccf Mon Sep 17 00:00:00 2001 From: bengarrett1971 <56556045+bengarrett1971@users.noreply.github.com> Date: Fri, 21 Feb 2020 19:38:01 +0000 Subject: [PATCH] Add unit Hertz Updated the MeterValues schema to allow a unit of measure called "Hertz". This was missing from the original 1.6 spec, but was added as an errata (see the OCPP 1.6 Errata sheet, v4.0 Release, 2019-10-23, on page 34). Fixes: #71 --- ocpp/v16/enums.py | 1 + ocpp/v16/schemas/MeterValues.json | 3 ++- tests/test_messages.py | 26 ++++++++++++++++++++++++++ tests/v16/test_enums.py | 1 + 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ocpp/v16/enums.py b/ocpp/v16/enums.py index 2662dfa1f..56830b652 100644 --- a/ocpp/v16/enums.py +++ b/ocpp/v16/enums.py @@ -467,6 +467,7 @@ class UnitOfMeasure: fahrenheit = "Fahrenheit" k = "K" percent = "Percent" + hertz = "Hertz" class UnlockStatus: diff --git a/ocpp/v16/schemas/MeterValues.json b/ocpp/v16/schemas/MeterValues.json index 94234693e..f2220ebd5 100644 --- a/ocpp/v16/schemas/MeterValues.json +++ b/ocpp/v16/schemas/MeterValues.json @@ -123,7 +123,8 @@ "Celcius", "Celsius", "Fahrenheit", - "Percent" + "Percent", + "Hertz" ] } }, diff --git a/tests/test_messages.py b/tests/test_messages.py index b8bec242e..f06a04acc 100644 --- a/tests/test_messages.py +++ b/tests/test_messages.py @@ -232,3 +232,29 @@ def test_serializing_decimal(): [decimal.Decimal(2.000001)], cls=_DecimalEncoder ) == "[2.0]" + + +def test_validate_meter_values_hertz(): + """ + Tests that a unit of measure called "Hertz" is permitted in validation. + This was missing from the original 1.6 spec, but was added as an errata + (see the OCPP 1.6 Errata sheet, v4.0 Release, 2019-10-23, page 34). + """ + message = Call( + unique_id="1234", + action="MeterValues", + payload={ + 'connectorId': 1, + 'transactionId': 123456789, + 'meterValue': [{ + 'timestamp': '2020-02-21T13:48:45.459756Z', + 'sampledValue': [{ + "value": "50.0", + "measurand": "Frequency", + "unit": "Hertz", + }] + }] + } + ) + + validate_payload(message, ocpp_version="1.6") diff --git a/tests/v16/test_enums.py b/tests/v16/test_enums.py index 1625165a4..32b133c43 100644 --- a/tests/v16/test_enums.py +++ b/tests/v16/test_enums.py @@ -288,6 +288,7 @@ def test_unit_of_measure(): assert UnitOfMeasure.fahrenheit == "Fahrenheit" assert UnitOfMeasure.k == "K" assert UnitOfMeasure.percent == "Percent" + assert UnitOfMeasure.hertz == "Hertz" def test_unlock_status():