From dd3f683006ea6f3995788409789610d7cfea9810 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 23 Feb 2023 01:04:33 +0100 Subject: [PATCH] Added `unit` to `bluetooth` mappers whenever available. --- platypush/plugins/bluetooth/ble/_mappers.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/platypush/plugins/bluetooth/ble/_mappers.py b/platypush/plugins/bluetooth/ble/_mappers.py index a8be0ef08..4ce1ffcb8 100644 --- a/platypush/plugins/bluetooth/ble/_mappers.py +++ b/platypush/plugins/bluetooth/ble/_mappers.py @@ -101,7 +101,14 @@ _property_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { # Maps reported units to transformer methods (second mapper choice). _unit_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { 'status': lambda value, _: BinarySensor(value=value), - 'int': lambda value, _: NumericSensor(value=value), + 'int': lambda value, conf: NumericSensor( + value=value, + unit=conf.get('unit'), + ), + 'float': lambda value, conf: NumericSensor( + value=value, + unit=conf.get('unit'), + ), '%': lambda value, conf: NumericSensor( value=value, unit='%', @@ -114,9 +121,9 @@ _unit_to_entity: Dict[str, Callable[[Any, Dict[str, Any]], Entity]] = { # Maps value types to transformer methods (third mapper choice). _value_type_to_entity: Dict[type, Callable[[Any, Dict[str, Any]], Entity]] = { bool: lambda value, _: BinarySensor(value=value), - int: lambda value, _: NumericSensor(value=value), - float: lambda value, _: NumericSensor(value=value), - str: lambda value, _: RawSensor(value=value), + int: lambda value, conf: NumericSensor(value=value, unit=conf.get('unit')), + float: lambda value, conf: NumericSensor(value=value, unit=conf.get('unit')), + str: lambda value, conf: RawSensor(value=value, unit=conf.get('unit')), bytes: lambda value, _: RawSensor(value=value), bytearray: lambda value, _: RawSensor(value=value), }