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:
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"))
|
||||
|
||||
Reference in new issue
Block a user