1
mirror of https://github.com/home-assistant/core synced 2024-07-12 07:21:24 +02:00

Add NZBGet speed limit sensor (#77104)

* Added sensor for download rate limit

* Added test for speed limit
This commit is contained in:
sophof 2022-08-22 09:02:05 +02:00 committed by GitHub
parent cba2893862
commit 8b46174667
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -74,6 +74,11 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
name="Uptime",
device_class=SensorDeviceClass.TIMESTAMP,
),
SensorEntityDescription(
key="DownloadLimit",
name="Speed Limit",
native_unit_of_measurement=DATA_RATE_MEGABYTES_PER_SECOND,
),
)
@ -127,6 +132,9 @@ class NZBGetSensor(NZBGetEntity, SensorEntity):
elif "DownloadRate" in sensor_type and value > 0:
# Convert download rate from Bytes/s to MBytes/s
self._native_value = round(value / 2**20, 2)
elif "DownloadLimit" in sensor_type and value > 0:
# Convert download rate from Bytes/s to MBytes/s
self._native_value = round(value / 2**20, 2)
elif "UpTimeSec" in sensor_type and value > 0:
uptime = utcnow().replace(microsecond=0) - timedelta(seconds=value)
if not isinstance(self._attr_native_value, datetime) or abs(

View File

@ -49,6 +49,7 @@ MOCK_STATUS = {
"PostPaused": False,
"RemainingSizeMB": 512,
"UpTimeSec": 600,
"DownloadLimit": 1000000,
}
MOCK_HISTORY = [

View File

@ -40,6 +40,12 @@ async def test_sensors(hass, nzbget_api) -> None:
"post_processing_paused": ("PostPaused", "False", None, None),
"queue_size": ("RemainingSizeMB", "512", DATA_MEGABYTES, None),
"uptime": ("UpTimeSec", uptime.isoformat(), None, SensorDeviceClass.TIMESTAMP),
"speed_limit": (
"DownloadLimit",
"0.95",
DATA_RATE_MEGABYTES_PER_SECOND,
None,
),
}
for (sensor_id, data) in sensors.items():