diff --git a/hassio-addon-lifepo4wered/__pycache__/lifepo4wered_monitor.cpython-314.pyc b/hassio-addon-lifepo4wered/__pycache__/lifepo4wered_monitor.cpython-314.pyc index aacfbd5..d1f45cc 100644 Binary files a/hassio-addon-lifepo4wered/__pycache__/lifepo4wered_monitor.cpython-314.pyc and b/hassio-addon-lifepo4wered/__pycache__/lifepo4wered_monitor.cpython-314.pyc differ diff --git a/hassio-addon-lifepo4wered/config.json b/hassio-addon-lifepo4wered/config.json index b5c5f93..f1a646e 100644 --- a/hassio-addon-lifepo4wered/config.json +++ b/hassio-addon-lifepo4wered/config.json @@ -1,6 +1,6 @@ { "name": "LiFePO4wered Addon", - "version": "0.1.2", + "version": "0.1.3", "init": false, "slug": "lifepo4wered", "description": "Add-on with service and MQTT monitor for LiFePO4wered/Pi+ UPS", diff --git a/hassio-addon-lifepo4wered/lifepo4wered_monitor.py b/hassio-addon-lifepo4wered/lifepo4wered_monitor.py index 495735d..d34a31c 100644 --- a/hassio-addon-lifepo4wered/lifepo4wered_monitor.py +++ b/hassio-addon-lifepo4wered/lifepo4wered_monitor.py @@ -83,23 +83,25 @@ DIAG_VOLTAGE = [ ("VBAT_MIN", "Battery minimum voltage"), ("VBAT_SHDN", "Battery shutdown voltage"), ("VBAT_BOOT", "Battery boot voltage"), - ("VOUT_MAX", "Output maximum voltage"), + ("VOUT_MAX", "Max output voltage to allow boot"), ("VIN_THRESHOLD", "Input voltage threshold"), ] -# raw-value diagnostic registers (units vary or are unitless flags/timers) +# raw-value diagnostic registers; units per the product brief (the CLI +# scales the timeouts to s and AUTO_SHDN_TIME to min; SHDN_DELAY stays +# raw ~8 Hz ticks) DIAG_RAW = [ - ("AUTO_BOOT", "Auto boot mode"), - ("SHDN_DELAY", "Shutdown delay"), - ("AUTO_SHDN_TIME", "Auto shutdown time"), - ("PI_BOOT_TO", "Pi boot timeout"), - ("PI_SHDN_TO", "Pi shutdown timeout"), - ("WATCHDOG_CFG", "Watchdog mode"), - ("WATCHDOG_GRACE", "Watchdog grace"), - ("WATCHDOG_TIMER", "Watchdog timer"), - ("PI_RUNNING", "Pi running flag"), - ("LED_STATE", "LED state"), - ("TOUCH_STATE", "Touch state"), + ("AUTO_BOOT", "Auto boot mode", None), + ("SHDN_DELAY", "Shutdown delay", None), + ("AUTO_SHDN_TIME", "Auto shutdown time", "min"), + ("PI_BOOT_TO", "Pi boot timeout", "s"), + ("PI_SHDN_TO", "Pi shutdown timeout", "s"), + ("WATCHDOG_CFG", "Watchdog mode", None), + ("WATCHDOG_GRACE", "Watchdog grace period", "s"), + ("WATCHDOG_TIMER", "Watchdog timer", "s"), + ("PI_RUNNING", "Pi running", None), + ("LED_STATE", "LED state", None), + ("TOUCH_STATE", "Touch button state", None), ] @@ -184,11 +186,13 @@ def discovery_messages(discovery_prefix, state_topic, availability_topic): value_template=millivolts(key), ) - for key, name in DIAG_RAW: + for key, name, unit in DIAG_RAW: + extra = {"unit_of_measurement": unit} if unit else {} yield entity( "sensor", key, name, entity_category="diagnostic", value_template="{{ value_json.%s }}" % key, + **extra, ) yield entity( diff --git a/tests/__pycache__/test_monitor.cpython-314.pyc b/tests/__pycache__/test_monitor.cpython-314.pyc index ab252ba..e8e4d0a 100644 Binary files a/tests/__pycache__/test_monitor.cpython-314.pyc and b/tests/__pycache__/test_monitor.cpython-314.pyc differ diff --git a/tests/test_monitor.py b/tests/test_monitor.py index eae1530..edb6c49 100644 --- a/tests/test_monitor.py +++ b/tests/test_monitor.py @@ -62,6 +62,17 @@ class DiscoveryTest(unittest.TestCase): self.assertEqual(cfg["entity_category"], "diagnostic") self.assertEqual(cfg["unit_of_measurement"], "V") + def test_timer_registers_have_documented_units(self): + for key, unit in (("pi_boot_to", "s"), ("pi_shdn_to", "s"), + ("watchdog_grace", "s"), ("watchdog_timer", "s"), + ("auto_shdn_time", "min")): + cfg = self.messages[ + "homeassistant/sensor/lifepo4wered/%s/config" % key] + self.assertEqual(cfg["unit_of_measurement"], unit, key) + self.assertNotIn( + "unit_of_measurement", + self.messages["homeassistant/sensor/lifepo4wered/shdn_delay/config"]) + def test_skipped_registers_have_no_entity(self): for key in ("i2c_reg_ver", "dco_rsel", "vbat_offset", "cfg_write"): self.assertNotIn(