Use DATA_SIZE device class in netgear lte (#83908)

This commit is contained in:
epenet 2022-12-13 10:18:35 +01:00 committed by GitHub
parent 69bc95a715
commit 1ad4cb40df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -1,7 +1,7 @@
"""Support for Netgear LTE sensors."""
from __future__ import annotations
from homeassistant.components.sensor import SensorEntity
from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import PlatformNotReady
from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -73,8 +73,10 @@ class SMSTotalSensor(LTESensor):
class UsageSensor(LTESensor):
"""Data usage sensor entity."""
_attr_device_class = SensorDeviceClass.DATA_SIZE
@property
def native_value(self):
def native_value(self) -> float:
"""Return the state of the sensor."""
return round(self.modem_data.data.usage / 1024**2, 1)

View File

@ -2,9 +2,9 @@
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.const import (
DATA_MEBIBYTES,
PERCENTAGE,
SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
UnitOfInformation,
)
SENSOR_SMS = "sms"
@ -14,7 +14,7 @@ SENSOR_USAGE = "usage"
SENSOR_UNITS = {
SENSOR_SMS: "unread",
SENSOR_SMS_TOTAL: "messages",
SENSOR_USAGE: DATA_MEBIBYTES,
SENSOR_USAGE: UnitOfInformation.MEBIBYTES,
"radio_quality": PERCENTAGE,
"rx_level": SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
"tx_level": SIGNAL_STRENGTH_DECIBELS_MILLIWATT,