Add NZBGet speed limit sensor (#77104)
* Added sensor for download rate limit * Added test for speed limit
This commit is contained in:
parent
cba2893862
commit
8b46174667
3 changed files with 15 additions and 0 deletions
|
@ -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(
|
||||
|
|
|
@ -49,6 +49,7 @@ MOCK_STATUS = {
|
|||
"PostPaused": False,
|
||||
"RemainingSizeMB": 512,
|
||||
"UpTimeSec": 600,
|
||||
"DownloadLimit": 1000000,
|
||||
}
|
||||
|
||||
MOCK_HISTORY = [
|
||||
|
|
|
@ -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():
|
||||
|
|
Loading…
Add table
Reference in a new issue