From 597fca90722cbb79598d40a8058222adf505b8a7 Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Mon, 24 Jan 2022 13:50:54 +0100 Subject: [PATCH] Make UniFi bandwidth sensors be about current transfer rather than total transfer (#64701) --- homeassistant/components/unifi/sensor.py | 8 ++++---- tests/components/unifi/test_sensor.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/homeassistant/components/unifi/sensor.py b/homeassistant/components/unifi/sensor.py index 7f825ed8052..165507c0498 100644 --- a/homeassistant/components/unifi/sensor.py +++ b/homeassistant/components/unifi/sensor.py @@ -115,8 +115,8 @@ class UniFiRxBandwidthSensor(UniFiBandwidthSensor): def native_value(self) -> int: """Return the state of the sensor.""" if self._is_wired: - return self.client.wired_rx_bytes / 1000000 - return self.client.rx_bytes / 1000000 + return self.client.wired_rx_bytes_r / 1000000 + return self.client.rx_bytes_r / 1000000 class UniFiTxBandwidthSensor(UniFiBandwidthSensor): @@ -128,8 +128,8 @@ class UniFiTxBandwidthSensor(UniFiBandwidthSensor): def native_value(self) -> int: """Return the state of the sensor.""" if self._is_wired: - return self.client.wired_tx_bytes / 1000000 - return self.client.tx_bytes / 1000000 + return self.client.wired_tx_bytes_r / 1000000 + return self.client.tx_bytes_r / 1000000 class UniFiUpTimeSensor(UniFiClient, SensorEntity): diff --git a/tests/components/unifi/test_sensor.py b/tests/components/unifi/test_sensor.py index c0b45efb119..398c6c6c3f5 100644 --- a/tests/components/unifi/test_sensor.py +++ b/tests/components/unifi/test_sensor.py @@ -44,16 +44,16 @@ async def test_bandwidth_sensors(hass, aioclient_mock, mock_unifi_websocket): "is_wired": True, "mac": "00:00:00:00:00:01", "oui": "Producer", - "wired-rx_bytes": 1234000000, - "wired-tx_bytes": 5678000000, + "wired-rx_bytes-r": 1234000000, + "wired-tx_bytes-r": 5678000000, } wireless_client = { "is_wired": False, "mac": "00:00:00:00:00:02", "name": "Wireless client", "oui": "Producer", - "rx_bytes": 2345000000, - "tx_bytes": 6789000000, + "rx_bytes-r": 2345000000, + "tx_bytes-r": 6789000000, } options = { CONF_ALLOW_BANDWIDTH_SENSORS: True, @@ -84,8 +84,8 @@ async def test_bandwidth_sensors(hass, aioclient_mock, mock_unifi_websocket): # Verify state update - wireless_client["rx_bytes"] = 3456000000 - wireless_client["tx_bytes"] = 7891000000 + wireless_client["rx_bytes-r"] = 3456000000 + wireless_client["tx_bytes-r"] = 7891000000 mock_unifi_websocket( data={