|
|
@@ -9,7 +9,11 @@ from custom_components.tuya_local.const import (
|
|
|
CONF_TYPE,
|
|
|
DOMAIN,
|
|
|
)
|
|
|
-from custom_components.tuya_local.sensor import async_setup_entry, TuyaLocalSensor
|
|
|
+from custom_components.tuya_local.helpers.device_config import TuyaEntityConfig
|
|
|
+from custom_components.tuya_local.sensor import (
|
|
|
+ async_setup_entry,
|
|
|
+ TuyaLocalSensor,
|
|
|
+)
|
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
|
@@ -86,3 +90,32 @@ async def test_init_entry_fails_if_config_is_missing(hass):
|
|
|
except ValueError:
|
|
|
pass
|
|
|
m_add_entities.assert_not_called()
|
|
|
+
|
|
|
+
|
|
|
+def test_sensor_suggested_display_precision():
|
|
|
+ mock_device = Mock()
|
|
|
+ config = TuyaEntityConfig(
|
|
|
+ mock_device,
|
|
|
+ {
|
|
|
+ "entity": "sensor",
|
|
|
+ "dps": [
|
|
|
+ {
|
|
|
+ "id": 1,
|
|
|
+ "name": "sensor",
|
|
|
+ "type": "integer",
|
|
|
+ "precision": 1,
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ },
|
|
|
+ )
|
|
|
+ sensor = TuyaLocalSensor(mock_device, config)
|
|
|
+ assert sensor.suggested_display_precision == 1
|
|
|
+ config = TuyaEntityConfig(
|
|
|
+ mock_device,
|
|
|
+ {
|
|
|
+ "entity": "sensor",
|
|
|
+ "dps": [{"id": 1, "name": "sensor", "type": "integer"}],
|
|
|
+ },
|
|
|
+ )
|
|
|
+ sensor = TuyaLocalSensor(mock_device, config)
|
|
|
+ assert sensor.suggested_display_precision is None
|