From b1c20da7a1d3fa0e9ceed6b8545fa8ffbce62fd8 Mon Sep 17 00:00:00 2001 From: Adam Goldsmith Date: Tue, 3 Jan 2023 12:16:15 -0500 Subject: [PATCH] Use try/except for numeric state conversion instead of str.isnumeric() --- check_home_assistant_state.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/check_home_assistant_state.py b/check_home_assistant_state.py index 4624d24..544ec78 100755 --- a/check_home_assistant_state.py +++ b/check_home_assistant_state.py @@ -62,9 +62,10 @@ class Entities(nagiosplugin.Resource): uom = None else: if self.numeric: - value = ( - float(state["state"]) if state["state"].isnumeric() else -1 - ) + try: + value = float(state["state"]) + except ValueError: + value = "-1" else: value = state["state"] uom = state["attributes"].get("unit_of_measurement")