From 13006cee685111e7de106f369f6ae8b09c250439 Mon Sep 17 00:00:00 2001
From: Paulus Schoutsen <paulus@paulusschoutsen.nl>
Date: Mon, 5 Dec 2016 11:32:17 -0800
Subject: [PATCH] Device tracker attributes (#4753)

---
 .../components/device_tracker/__init__.py     | 21 +++++++++++--------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/homeassistant/components/device_tracker/__init__.py b/homeassistant/components/device_tracker/__init__.py
index e95b556b998..7c4c74708db 100644
--- a/homeassistant/components/device_tracker/__init__.py
+++ b/homeassistant/components/device_tracker/__init__.py
@@ -332,6 +332,7 @@ class Device(Entity):
     gps = None  # type: GPSType
     gps_accuracy = 0
     last_seen = None  # type: dt_util.dt.datetime
+    battery = None  # type: str
     attributes = None  # type: dict
     vendor = None  # type: str
 
@@ -369,6 +370,7 @@ class Device(Entity):
 
         self.away_hide = hide_if_away
         self.vendor = vendor
+        self._attributes = {}
 
     @property
     def name(self):
@@ -395,12 +397,16 @@ class Device(Entity):
             attr[ATTR_LONGITUDE] = self.gps[1]
             attr[ATTR_GPS_ACCURACY] = self.gps_accuracy
 
-        if self.attributes:
-            for key, value in self.attributes.items():
-                attr[key] = value
+        if self.battery:
+            attr[ATTR_BATTERY] = self.battery
 
         return attr
 
+    @property
+    def device_state_attributes(self):
+        """Return device state attributes."""
+        return self._attributes
+
     @property
     def hidden(self):
         """If device should be hidden."""
@@ -415,13 +421,10 @@ class Device(Entity):
         self.host_name = host_name
         self.location_name = location_name
         self.gps_accuracy = gps_accuracy or 0
-        if (battery or attributes) and self.attributes is None:
-            self.attributes = {}
-        if battery:
-            self.attributes[ATTR_BATTERY] = battery
+
         if attributes:
-            for key, value in attributes.items():
-                self.attributes[key] = value
+            self._attributes.update(attributes)
+
         self.gps = None
 
         if gps is not None:
-- 
GitLab