From 70b7e512314151ca0c0c6b7637620dee9f0141ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Thu, 27 Jan 2022 11:36:26 +0100 Subject: [PATCH] Fix listenvs/listfields for new driver format. --- src/main.cc | 35 +++++++++++++++- test.sh | 3 ++ tests/test_list_envs.sh | 88 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 2 deletions(-) create mode 100755 tests/test_list_envs.sh diff --git a/src/main.cc b/src/main.cc index 59fafb0..12fe85e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -187,8 +187,24 @@ void list_shell_envs(Configuration *config, string meter_driver) Telegram t; t.about.device = "?"; MeterInfo mi; + shared_ptr meter; + DriverInfo di; + mi.driver = toMeterDriver(meter_driver); - shared_ptr meter = createMeter(&mi); + if (mi.driver != MeterDriver::UNKNOWN) + { + meter = createMeter(&mi); + } + else + { + mi.driver_name = meter_driver; + if (!lookupDriverInfo(meter_driver, &di)) + { + error("No such driver %s\n", meter_driver.c_str()); + } + meter = di.construct(mi); + } + meter->printMeter(&t, &ignore1, &ignore2, config->separator, @@ -209,8 +225,23 @@ void list_shell_envs(Configuration *config, string meter_driver) void list_fields(Configuration *config, string meter_driver) { MeterInfo mi; + shared_ptr meter; + DriverInfo di; + mi.driver = toMeterDriver(meter_driver); - shared_ptr meter = createMeter(&mi); + if (mi.driver != MeterDriver::UNKNOWN) + { + meter = createMeter(&mi); + } + else + { + mi.driver_name = meter_driver; + if (!lookupDriverInfo(meter_driver, &di)) + { + error("No such driver %s\n", meter_driver.c_str()); + } + meter = di.construct(mi); + } int width = 13; // Width of timestamp_utc for (auto &p : meter->prints()) diff --git a/test.sh b/test.sh index 874fe4f..d3f6234 100755 --- a/test.sh +++ b/test.sh @@ -30,6 +30,9 @@ if [ "$?" != "0" ]; then RC="1"; fi tests/test_anyid.sh $PROG if [ "$?" != "0" ]; then RC="1"; fi +./tests/test_list_envs.sh $PROG +if [ "$?" != "0" ]; then RC="1"; fi + #tests/test_unknown.sh $PROG #if [ "$?" != "0" ]; then RC="1"; fi diff --git a/tests/test_list_envs.sh b/tests/test_list_envs.sh new file mode 100755 index 0000000..15a0c36 --- /dev/null +++ b/tests/test_list_envs.sh @@ -0,0 +1,88 @@ +#!/bin/sh + +PROG="$1" + +mkdir -p testoutput +TEST=testoutput + +TESTNAME="Test list-envs and list-fields" +TESTRESULT="ERROR" + +$PROG --listenvs=amiplus > $TEST/test_output.txt 2>&1 + +cat < $TEST/test_expected.txt +METER_JSON +METER_ID +METER_NAME +METER_MEDIA +METER_TYPE +METER_TIMESTAMP +METER_TIMESTAMP_UTC +METER_TIMESTAMP_UT +METER_TIMESTAMP_LT +METER_DEVICE +METER_RSSI_DBM +METER_TOTAL_ENERGY_CONSUMPTION_KWH +METER_CURRENT_POWER_CONSUMPTION_KW +METER_TOTAL_ENERGY_PRODUCTION_KWH +METER_CURRENT_POWER_PRODUCTION_KW +METER_VOLTAGE_AT_PHASE_1_Volt +METER_VOLTAGE_AT_PHASE_2_Volt +METER_VOLTAGE_AT_PHASE_3_Volt +METER_DEVICE_DATE_TIME +EOF + +if [ "$?" = "0" ] +then + diff $TEST/test_expected.txt $TEST/test_output.txt + if [ "$?" = "0" ] + then + echo OK: $TESTNAME + TESTRESULT="OK" + fi +fi + +if [ "$TESTRESULT" = "ERROR" ] +then + echo ERROR: $TESTNAME + exit 1 +fi + +$PROG --listfields=amiplus > $TEST/test_output.txt 2>&1 + +cat < $TEST/test_expected.txt + id The meter id number. + name Your name for the meter. + media What does the meter measure? + meter Meter driver. + timestamp Timestamp when wmbusmeters received the telegram. Local time for hr/fields UTC for json. + timestamp_ut Unix timestamp when wmbusmeters received the telegram. + timestamp_lt Local time when wmbusmeters received the telegram. + timestamp_utc UTC time when wmbusmeters received the telegram. + device The wmbus device that received the telegram. + rssi_dbm The rssi for the received telegram as reported by the device. +total_energy_consumption_kwh The total energy consumption recorded by this meter. +current_power_consumption_kw Current power consumption. + total_energy_production_kwh The total energy production recorded by this meter. + current_power_production_kw Current power production. + voltage_at_phase_1_v Voltage at phase L1. + voltage_at_phase_2_v Voltage at phase L2. + voltage_at_phase_3_v Voltage at phase L3. + device_date_time_txt Device date time. +EOF + +if [ "$?" = "0" ] +then + diff $TEST/test_expected.txt $TEST/test_output.txt + if [ "$?" = "0" ] + then + echo OK: $TESTNAME + TESTRESULT="OK" + fi +fi + +if [ "$TESTRESULT" = "ERROR" ] +then + echo ERROR: $TESTNAME + exit 1 +fi