mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Provide charging indicator for mychevy (#19348)
* Provide charging indicator for mychevy This expands the mychevy sensor for the battery level to also know if the system is currently charging to get the correct icon. * address review feedback
This commit is contained in:
parent
57ccd8283d
commit
e9c19462d6
@ -16,7 +16,7 @@ from homeassistant.helpers import config_validation as cv
|
|||||||
from homeassistant.helpers import discovery
|
from homeassistant.helpers import discovery
|
||||||
from homeassistant.util import Throttle
|
from homeassistant.util import Throttle
|
||||||
|
|
||||||
REQUIREMENTS = ["mychevy==1.0.1"]
|
REQUIREMENTS = ["mychevy==1.1.0"]
|
||||||
|
|
||||||
DOMAIN = 'mychevy'
|
DOMAIN = 'mychevy'
|
||||||
UPDATE_TOPIC = DOMAIN
|
UPDATE_TOPIC = DOMAIN
|
||||||
@ -44,10 +44,12 @@ CONFIG_SCHEMA = vol.Schema({
|
|||||||
class EVSensorConfig:
|
class EVSensorConfig:
|
||||||
"""The EV sensor configuration."""
|
"""The EV sensor configuration."""
|
||||||
|
|
||||||
def __init__(self, name, attr, unit_of_measurement=None, icon=None):
|
def __init__(self, name, attr, unit_of_measurement=None, icon=None,
|
||||||
|
extra_attrs=None):
|
||||||
"""Create new sensor configuration."""
|
"""Create new sensor configuration."""
|
||||||
self.name = name
|
self.name = name
|
||||||
self.attr = attr
|
self.attr = attr
|
||||||
|
self.extra_attrs = extra_attrs or []
|
||||||
self.unit_of_measurement = unit_of_measurement
|
self.unit_of_measurement = unit_of_measurement
|
||||||
self.icon = icon
|
self.icon = icon
|
||||||
|
|
||||||
|
@ -24,7 +24,8 @@ SENSORS = [
|
|||||||
"mdi:speedometer"),
|
"mdi:speedometer"),
|
||||||
EVSensorConfig("Charged By", "estimatedFullChargeBy"),
|
EVSensorConfig("Charged By", "estimatedFullChargeBy"),
|
||||||
EVSensorConfig("Charge Mode", "chargeMode"),
|
EVSensorConfig("Charge Mode", "chargeMode"),
|
||||||
EVSensorConfig("Battery Level", BATTERY_SENSOR, "%", "mdi:battery")
|
EVSensorConfig("Battery Level", BATTERY_SENSOR, "%", "mdi:battery",
|
||||||
|
["charging"])
|
||||||
]
|
]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -117,9 +118,11 @@ class EVSensor(Entity):
|
|||||||
self._conn = connection
|
self._conn = connection
|
||||||
self._name = config.name
|
self._name = config.name
|
||||||
self._attr = config.attr
|
self._attr = config.attr
|
||||||
|
self._extra_attrs = config.extra_attrs
|
||||||
self._unit_of_measurement = config.unit_of_measurement
|
self._unit_of_measurement = config.unit_of_measurement
|
||||||
self._icon = config.icon
|
self._icon = config.icon
|
||||||
self._state = None
|
self._state = None
|
||||||
|
self._state_attributes = {}
|
||||||
self._car_vid = car_vid
|
self._car_vid = car_vid
|
||||||
|
|
||||||
self.entity_id = ENTITY_ID_FORMAT.format(
|
self.entity_id = ENTITY_ID_FORMAT.format(
|
||||||
@ -141,7 +144,8 @@ class EVSensor(Entity):
|
|||||||
def icon(self):
|
def icon(self):
|
||||||
"""Return the icon."""
|
"""Return the icon."""
|
||||||
if self._attr == BATTERY_SENSOR:
|
if self._attr == BATTERY_SENSOR:
|
||||||
return icon_for_battery_level(self.state)
|
charging = self.state_attributes.get("charging", False)
|
||||||
|
return icon_for_battery_level(self.state, charging)
|
||||||
return self._icon
|
return self._icon
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -154,6 +158,8 @@ class EVSensor(Entity):
|
|||||||
"""Update state."""
|
"""Update state."""
|
||||||
if self._car is not None:
|
if self._car is not None:
|
||||||
self._state = getattr(self._car, self._attr, None)
|
self._state = getattr(self._car, self._attr, None)
|
||||||
|
for attr in self._extra_attrs:
|
||||||
|
self._state_attributes[attr] = getattr(self._car, attr)
|
||||||
self.async_schedule_update_ha_state()
|
self.async_schedule_update_ha_state()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -161,6 +167,11 @@ class EVSensor(Entity):
|
|||||||
"""Return the state."""
|
"""Return the state."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
"""Return all the state attributes."""
|
||||||
|
return self._state_attributes
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement the state is expressed in."""
|
"""Return the unit of measurement the state is expressed in."""
|
||||||
|
@ -669,7 +669,7 @@ motorparts==1.0.2
|
|||||||
mutagen==1.41.1
|
mutagen==1.41.1
|
||||||
|
|
||||||
# homeassistant.components.mychevy
|
# homeassistant.components.mychevy
|
||||||
mychevy==1.0.1
|
mychevy==1.1.0
|
||||||
|
|
||||||
# homeassistant.components.mycroft
|
# homeassistant.components.mycroft
|
||||||
mycroftapi==2.0
|
mycroftapi==2.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user