Use suggested_display_precision for AsusWrt sensors (#87396)

* Use native_precision for AsusWrt sensors

* Use  suggested_display_precision
pull/87574/head
ollo69 2023-02-06 11:05:10 +01:00 committed by GitHub
parent c7980bda82
commit ade0d6fcae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 15 deletions

View File

@ -36,7 +36,6 @@ class AsusWrtSensorEntityDescription(SensorEntityDescription):
"""A class that describes AsusWrt sensor entities."""
factor: int | None = None
precision: int = 2
UNIT_DEVICES = "Devices"
@ -57,6 +56,7 @@ CONNECTION_SENSORS: tuple[AsusWrtSensorEntityDescription, ...] = (
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfDataRate.MEGABITS_PER_SECOND,
entity_registry_enabled_default=False,
suggested_display_precision=2,
factor=125000,
),
AsusWrtSensorEntityDescription(
@ -67,6 +67,7 @@ CONNECTION_SENSORS: tuple[AsusWrtSensorEntityDescription, ...] = (
state_class=SensorStateClass.MEASUREMENT,
native_unit_of_measurement=UnitOfDataRate.MEGABITS_PER_SECOND,
entity_registry_enabled_default=False,
suggested_display_precision=2,
factor=125000,
),
AsusWrtSensorEntityDescription(
@ -77,6 +78,7 @@ CONNECTION_SENSORS: tuple[AsusWrtSensorEntityDescription, ...] = (
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
suggested_display_precision=2,
factor=1000000000,
),
AsusWrtSensorEntityDescription(
@ -87,6 +89,7 @@ CONNECTION_SENSORS: tuple[AsusWrtSensorEntityDescription, ...] = (
native_unit_of_measurement=UnitOfInformation.GIGABYTES,
device_class=SensorDeviceClass.DATA_SIZE,
entity_registry_enabled_default=False,
suggested_display_precision=2,
factor=1000000000,
),
AsusWrtSensorEntityDescription(
@ -96,8 +99,7 @@ CONNECTION_SENSORS: tuple[AsusWrtSensorEntityDescription, ...] = (
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
factor=1,
precision=1,
suggested_display_precision=1,
),
AsusWrtSensorEntityDescription(
key=SENSORS_LOAD_AVG[1],
@ -106,8 +108,7 @@ CONNECTION_SENSORS: tuple[AsusWrtSensorEntityDescription, ...] = (
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
factor=1,
precision=1,
suggested_display_precision=1,
),
AsusWrtSensorEntityDescription(
key=SENSORS_LOAD_AVG[2],
@ -116,8 +117,7 @@ CONNECTION_SENSORS: tuple[AsusWrtSensorEntityDescription, ...] = (
state_class=SensorStateClass.MEASUREMENT,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
factor=1,
precision=1,
suggested_display_precision=1,
),
AsusWrtSensorEntityDescription(
key=SENSORS_TEMPERATURES[0],
@ -127,8 +127,7 @@ CONNECTION_SENSORS: tuple[AsusWrtSensorEntityDescription, ...] = (
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
factor=1,
precision=1,
suggested_display_precision=1,
),
AsusWrtSensorEntityDescription(
key=SENSORS_TEMPERATURES[1],
@ -138,8 +137,7 @@ CONNECTION_SENSORS: tuple[AsusWrtSensorEntityDescription, ...] = (
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
factor=1,
precision=1,
suggested_display_precision=1,
),
AsusWrtSensorEntityDescription(
key=SENSORS_TEMPERATURES[2],
@ -149,8 +147,7 @@ CONNECTION_SENSORS: tuple[AsusWrtSensorEntityDescription, ...] = (
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
entity_category=EntityCategory.DIAGNOSTIC,
entity_registry_enabled_default=False,
factor=1,
precision=1,
suggested_display_precision=1,
),
)
@ -203,5 +200,5 @@ class AsusWrtSensor(CoordinatorEntity, SensorEntity):
descr = self.entity_description
state: float | int | str | None = self.coordinator.data.get(descr.key)
if state is not None and descr.factor and isinstance(state, (float, int)):
return round(state / descr.factor, descr.precision)
return state / descr.factor
return state

View File

@ -50,7 +50,7 @@ MAC_ADDR = "a1:b2:c3:d4:e5:f6"
MOCK_BYTES_TOTAL = [60000000000, 50000000000]
MOCK_CURRENT_TRANSFER_RATES = [20000000, 10000000]
MOCK_LOAD_AVG = [1.1, 1.2, 1.3]
MOCK_TEMPERATURES = {"2.4GHz": 40, "5.0GHz": 0, "CPU": 71.2}
MOCK_TEMPERATURES = {"2.4GHz": 40.0, "5.0GHz": 0.0, "CPU": 71.2}
MOCK_MAC_1 = "A1:B1:C1:D1:E1:F1"
MOCK_MAC_2 = "A2:B2:C2:D2:E2:F2"
MOCK_MAC_3 = "A3:B3:C3:D3:E3:F3"