Repository: Bluetooth-Devices/bthome-ble (language: python)

Issue:
How to correctly transmit 220 volts?
Hello.

'voltage' has a size of 2 bytes. This is 0xffff or 65535. Factor - 0.001. So only 65V.


Discussion / hints:
You can't. I can add another object id with 2 bytes, factor 0.1, so you can go up to 6553.5 V. Is that OK for you?
Yes. Thanks.

Fix patch:
diff --git a/src/bthome_ble/const.py b/src/bthome_ble/const.py
index 0e3ffa7..b890216 100644
--- a/src/bthome_ble/const.py
+++ b/src/bthome_ble/const.py
@@ -312,4 +312,9 @@ class MeasTypes:
         data_length=2,
         factor=0.001,
     ),
+    0x4A: MeasTypes(
+        meas_format=SensorLibrary.VOLTAGE__ELECTRIC_POTENTIAL_VOLT,
+        data_length=2,
+        factor=0.1,
+    ),
 }


Test patch:
diff --git a/tests/test_parser_v2.py b/tests/test_parser_v2.py
index d53e5c6..1fdeed1 100644
--- a/tests/test_parser_v2.py
+++ b/tests/test_parser_v2.py
@@ -1787,6 +1787,48 @@ def test_bthome_volume_flow_rate(caplog):
     )
 
 
+def test_bthome_voltage_2(caplog):
+    """Test BThome parser for voltage reading without encryption."""
+    data_string = b"\x40\x4a\x02\x0c"
+    advertisement = bytes_to_service_info(
+        data_string, local_name="TEST DEVICE", address="A4:C1:38:8D:18:B2"
+    )
+
+    device = BTHomeBluetoothDeviceData()
+    assert device.update(advertisement) == SensorUpdate(
+        title="TEST DEVICE 18B2",
+        devices={
+            None: SensorDeviceInfo(
+                name="TEST DEVICE 18B2",
+                manufacturer=None,
+                model="BTHome sensor",
+                sw_version="BTHome BLE v2",
+                hw_version=None,
+            )
+        },
+        entity_descriptions={
+            KEY_VOLTAGE: SensorDescription(
+                device_key=KEY_VOLTAGE,
+                device_class=SensorDeviceClass.VOLTAGE,
+                native_unit_of_measurement=Units.ELECTRIC_POTENTIAL_VOLT,
+            ),
+            KEY_SIGNAL_STRENGTH: SensorDescription(
+                device_key=KEY_SIGNAL_STRENGTH,
+                device_class=SensorDeviceClass.SIGNAL_STRENGTH,
+                native_unit_of_measurement=Units.SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
+            ),
+        },
+        entity_values={
+            KEY_VOLTAGE: SensorValue(
+                device_key=KEY_VOLTAGE, name="Voltage", native_value=307.4
+            ),
+            KEY_SIGNAL_STRENGTH: SensorValue(
+                device_key=KEY_SIGNAL_STRENGTH, name="Signal Strength", native_value=-60
+            ),
+        },
+    )
+
+
 def test_bthome_double_temperature(caplog):
     """Test BTHome parser for double temperature reading without encryption."""
     data_string = b"\x40\x02\xca\x09\x02\xcf\x09"