mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 22:57:17 +00:00
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
@ -74,6 +74,11 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
|
|||||||
name="Uptime",
|
name="Uptime",
|
||||||
device_class=SensorDeviceClass.TIMESTAMP,
|
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:
|
elif "DownloadRate" in sensor_type and value > 0:
|
||||||
# Convert download rate from Bytes/s to MBytes/s
|
# Convert download rate from Bytes/s to MBytes/s
|
||||||
self._native_value = round(value / 2**20, 2)
|
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:
|
elif "UpTimeSec" in sensor_type and value > 0:
|
||||||
uptime = utcnow().replace(microsecond=0) - timedelta(seconds=value)
|
uptime = utcnow().replace(microsecond=0) - timedelta(seconds=value)
|
||||||
if not isinstance(self._attr_native_value, datetime) or abs(
|
if not isinstance(self._attr_native_value, datetime) or abs(
|
||||||
|
@ -49,6 +49,7 @@ MOCK_STATUS = {
|
|||||||
"PostPaused": False,
|
"PostPaused": False,
|
||||||
"RemainingSizeMB": 512,
|
"RemainingSizeMB": 512,
|
||||||
"UpTimeSec": 600,
|
"UpTimeSec": 600,
|
||||||
|
"DownloadLimit": 1000000,
|
||||||
}
|
}
|
||||||
|
|
||||||
MOCK_HISTORY = [
|
MOCK_HISTORY = [
|
||||||
|
@ -40,6 +40,12 @@ async def test_sensors(hass, nzbget_api) -> None:
|
|||||||
"post_processing_paused": ("PostPaused", "False", None, None),
|
"post_processing_paused": ("PostPaused", "False", None, None),
|
||||||
"queue_size": ("RemainingSizeMB", "512", DATA_MEGABYTES, None),
|
"queue_size": ("RemainingSizeMB", "512", DATA_MEGABYTES, None),
|
||||||
"uptime": ("UpTimeSec", uptime.isoformat(), None, SensorDeviceClass.TIMESTAMP),
|
"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():
|
for (sensor_id, data) in sensors.items():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user