huawei_lte: support out of range values in default sensor formatter (#26052)

* Update sensor.py

Change regexp to cope with out of range values, ie "rssi" : ">=-51dBm".

* Add tests for format_default

* Fix black formatting
This commit is contained in:
flebourse authored and Ville Skyttä committed 2019-08-19 20:34:33 +03:00
1 parent a38bdc4deb
commit 45aec2ea40
2 files changed
+17 -1

No files matched your search

@@ -137,7 +137,9 @@ def format_default(value):
unit = None
if value is not None:
# Clean up value and infer unit, e.g. -71dBm, 15 dB
match = re.match(r"(?P<value>.+?)\s*(?P<unit>[a-zA-Z]+)\s*$", str(value))
match = re.match(
r"([>=<]*)(?P<value>.+?)\s*(?P<unit>[a-zA-Z]+)\s*$", str(value)
)
if match:
try:
value = float(match.group("value"))