From fe5f8e041b01554ef06a892e8e9175561b276b4e Mon Sep 17 00:00:00 2001
From: Justin Berstler <jberstler@salesforce.com>
Date: Fri, 3 Jul 2020 19:36:26 -0400
Subject: [PATCH] Use a more detailed battery icon for Tesla cars (#37154)

Use the icon_for_battery_level helper to select a battery icon that indicates charge level and whether or not the battery is actively charging.
---
 homeassistant/components/tesla/__init__.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/homeassistant/components/tesla/__init__.py b/homeassistant/components/tesla/__init__.py
index d2b5f091021..5cf5eb4fc5d 100644
--- a/homeassistant/components/tesla/__init__.py
+++ b/homeassistant/components/tesla/__init__.py
@@ -19,6 +19,7 @@ from homeassistant.const import (
 from homeassistant.core import callback
 from homeassistant.helpers import aiohttp_client, config_validation as cv
 from homeassistant.helpers.entity import Entity
+from homeassistant.helpers.icon import icon_for_battery_level
 from homeassistant.util import slugify
 
 from .config_flow import (
@@ -221,6 +222,12 @@ class TeslaDevice(Entity):
     @property
     def icon(self):
         """Return the icon of the sensor."""
+        if self.tesla_device.has_battery():
+            return icon_for_battery_level(
+                battery_level=self.tesla_device.battery_level(),
+                charging=self.tesla_device.battery_charging(),
+            )
+
         return self._icon
 
     @property
-- 
GitLab