Add and use more unit constants (#32122)
* Add and use speed constants * Add and use meter based volume and area constants * Add and use more mass unit constants * Add and use concentration unit constants * Add and use watts per square meter constant * Use more time constants * Use more data constants
This commit is contained in:
1 parent
c98f50115d
commit
496bd3dddf
44 files changed
+422
-177
No files matched your search
@@ -1,7 +1,7 @@
|
||||
"""Support for UPnP/IGD Sensors."""
|
||||
import logging
|
||||
|
||||
from homeassistant.const import TIME_SECONDS
|
||||
from homeassistant.const import DATA_BYTES, DATA_KIBIBYTES, TIME_SECONDS
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
@@ -19,15 +19,15 @@ PACKETS_RECEIVED = "packets_received"
|
||||
PACKETS_SENT = "packets_sent"
|
||||
|
||||
SENSOR_TYPES = {
|
||||
BYTES_RECEIVED: {"name": "bytes received", "unit": "bytes"},
|
||||
BYTES_SENT: {"name": "bytes sent", "unit": "bytes"},
|
||||
BYTES_RECEIVED: {"name": "bytes received", "unit": DATA_BYTES},
|
||||
BYTES_SENT: {"name": "bytes sent", "unit": DATA_BYTES},
|
||||
PACKETS_RECEIVED: {"name": "packets received", "unit": "packets"},
|
||||
PACKETS_SENT: {"name": "packets sent", "unit": "packets"},
|
||||
}
|
||||
|
||||
IN = "received"
|
||||
OUT = "sent"
|
||||
KBYTE = 1024
|
||||
KIBIBYTE = 1024
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
@@ -226,7 +226,7 @@ class KBytePerSecondUPnPIGDSensor(PerSecondUPnPIGDSensor):
|
||||
@property
|
||||
def unit(self) -> str:
|
||||
"""Get unit we are measuring in."""
|
||||
return "kB"
|
||||
return DATA_KIBIBYTES
|
||||
|
||||
async def _async_fetch_value(self) -> float:
|
||||
"""Fetch value from device."""
|
||||
@@ -241,7 +241,7 @@ class KBytePerSecondUPnPIGDSensor(PerSecondUPnPIGDSensor):
|
||||
if self._state is None:
|
||||
return None
|
||||
|
||||
return format(float(self._state / KBYTE), ".1f")
|
||||
return format(float(self._state / KIBIBYTE), ".1f")
|
||||
|
||||
|
||||
class PacketsPerSecondUPnPIGDSensor(PerSecondUPnPIGDSensor):
|
||||
|
||||
Reference in new issue
Block a user