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
3 changed files with 18 additions and 5 deletions
|
@ -24,7 +24,8 @@ SENSORS = [
|
|||
"mdi:speedometer"),
|
||||
EVSensorConfig("Charged By", "estimatedFullChargeBy"),
|
||||
EVSensorConfig("Charge Mode", "chargeMode"),
|
||||
EVSensorConfig("Battery Level", BATTERY_SENSOR, "%", "mdi:battery")
|
||||
EVSensorConfig("Battery Level", BATTERY_SENSOR, "%", "mdi:battery",
|
||||
["charging"])
|
||||
]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -117,9 +118,11 @@ class EVSensor(Entity):
|
|||
self._conn = connection
|
||||
self._name = config.name
|
||||
self._attr = config.attr
|
||||
self._extra_attrs = config.extra_attrs
|
||||
self._unit_of_measurement = config.unit_of_measurement
|
||||
self._icon = config.icon
|
||||
self._state = None
|
||||
self._state_attributes = {}
|
||||
self._car_vid = car_vid
|
||||
|
||||
self.entity_id = ENTITY_ID_FORMAT.format(
|
||||
|
@ -141,7 +144,8 @@ class EVSensor(Entity):
|
|||
def icon(self):
|
||||
"""Return the icon."""
|
||||
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
|
||||
|
||||
@property
|
||||
|
@ -154,6 +158,8 @@ class EVSensor(Entity):
|
|||
"""Update state."""
|
||||
if self._car is not 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()
|
||||
|
||||
@property
|
||||
|
@ -161,6 +167,11 @@ class EVSensor(Entity):
|
|||
"""Return the state."""
|
||||
return self._state
|
||||
|
||||
@property
|
||||
def device_state_attributes(self):
|
||||
"""Return all the state attributes."""
|
||||
return self._state_attributes
|
||||
|
||||
@property
|
||||
def unit_of_measurement(self):
|
||||
"""Return the unit of measurement the state is expressed in."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue