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.
pull/37446/head
Justin Berstler 2020-07-03 19:36:26 -04:00 committed by GitHub
parent 13f634fa16
commit fe5f8e041b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 0 deletions

View File

@ -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