From ab7db5fbd0c7261fbd1b2e7feeceaeea0c1b4f3a Mon Sep 17 00:00:00 2001 From: Robert Svensson Date: Sun, 11 Aug 2019 22:40:44 +0200 Subject: [PATCH] UniFi - Use state to know if device is online (#25876) --- homeassistant/components/unifi/device_tracker.py | 13 ++++++++----- homeassistant/components/unifi/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/unifi/test_device_tracker.py | 2 ++ 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/unifi/device_tracker.py b/homeassistant/components/unifi/device_tracker.py index d9f90de7888..42a6f496a2a 100644 --- a/homeassistant/components/unifi/device_tracker.py +++ b/homeassistant/components/unifi/device_tracker.py @@ -294,7 +294,7 @@ class UniFiDeviceTracker(ScannerEntity): CONF_DETECTION_TIME, DEFAULT_DETECTION_TIME ) - if self.device.last_seen and ( + if self.device.state == 1 and ( dt_util.utcnow() - dt_util.utc_from_timestamp(float(self.device.last_seen)) < detection_time ): @@ -339,15 +339,18 @@ class UniFiDeviceTracker(ScannerEntity): @property def device_state_attributes(self): """Return the device state attributes.""" - if not self.device.last_seen: + if self.device.state == 0: return {} attributes = {} - attributes["upgradable"] = self.device.upgradable - attributes["overheating"] = self.device.overheating - if self.device.has_fan: attributes["fan_level"] = self.device.fan_level + if self.device.overheating: + attributes["overheating"] = self.device.overheating + + if self.device.upgradable: + attributes["upgradable"] = self.device.upgradable + return attributes diff --git a/homeassistant/components/unifi/manifest.json b/homeassistant/components/unifi/manifest.json index bcee022e1c4..d182806c4ac 100644 --- a/homeassistant/components/unifi/manifest.json +++ b/homeassistant/components/unifi/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/components/unifi", "requirements": [ - "aiounifi==10" + "aiounifi==11" ], "dependencies": [], "codeowners": [ diff --git a/requirements_all.txt b/requirements_all.txt index d44e5afe2b3..e513dcd6715 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -173,7 +173,7 @@ aiopvapi==1.6.14 aioswitcher==2019.4.26 # homeassistant.components.unifi -aiounifi==10 +aiounifi==11 # homeassistant.components.wwlln aiowwlln==1.0.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index ab6c1bde776..b873eb2e105 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -71,7 +71,7 @@ aionotion==1.1.0 aioswitcher==2019.4.26 # homeassistant.components.unifi -aiounifi==10 +aiounifi==11 # homeassistant.components.wwlln aiowwlln==1.0.0 diff --git a/tests/components/unifi/test_device_tracker.py b/tests/components/unifi/test_device_tracker.py index 0d8d631d8ff..d5783e58818 100644 --- a/tests/components/unifi/test_device_tracker.py +++ b/tests/components/unifi/test_device_tracker.py @@ -69,6 +69,7 @@ DEVICE_1 = { "model": "US16P150", "name": "device_1", "overheating": False, + "state": 1, "type": "usw", "upgradable": False, "version": "4.0.42.10433", @@ -81,6 +82,7 @@ DEVICE_2 = { "mac": "00:00:00:00:01:01", "model": "US16P150", "name": "device_1", + "state": 0, "type": "usw", "version": "4.0.42.10433", }