mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 04:07:08 +00:00
Fix Nissan Leaf default states (#59866)
* Fix default states and add device_class. Car data is initialised to zero, which means that graphs have an ugly drop to zero in them when HA is restarted. We should report "None" when the state is unknown. We need to use availability to signal whether binary_sensors have sensible data or not. We can remove the custom icons and use the defaults provided by using appropriate device_class. * Make isort happy. * Explicitly return None * Remove feature from bugfix PR.
This commit is contained in:
parent
b13e4e9953
commit
9ab8622d72
@ -213,12 +213,12 @@ class LeafDataStore:
|
||||
self.car_config = car_config
|
||||
self.force_miles = car_config[CONF_FORCE_MILES]
|
||||
self.data = {}
|
||||
self.data[DATA_CLIMATE] = False
|
||||
self.data[DATA_BATTERY] = 0
|
||||
self.data[DATA_CHARGING] = False
|
||||
self.data[DATA_RANGE_AC] = 0
|
||||
self.data[DATA_RANGE_AC_OFF] = 0
|
||||
self.data[DATA_PLUGGED_IN] = False
|
||||
self.data[DATA_CLIMATE] = None
|
||||
self.data[DATA_BATTERY] = None
|
||||
self.data[DATA_CHARGING] = None
|
||||
self.data[DATA_RANGE_AC] = None
|
||||
self.data[DATA_RANGE_AC_OFF] = None
|
||||
self.data[DATA_PLUGGED_IN] = None
|
||||
self.next_update = None
|
||||
self.last_check = None
|
||||
self.request_in_progress = False
|
||||
|
@ -30,6 +30,11 @@ class LeafPluggedInSensor(LeafEntity, BinarySensorEntity):
|
||||
"""Sensor name."""
|
||||
return f"{self.car.leaf.nickname} Plug Status"
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Sensor availability."""
|
||||
return self.car.data[DATA_PLUGGED_IN] is not None
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if plugged in."""
|
||||
@ -51,6 +56,11 @@ class LeafChargingSensor(LeafEntity, BinarySensorEntity):
|
||||
"""Sensor name."""
|
||||
return f"{self.car.leaf.nickname} Charging Status"
|
||||
|
||||
@property
|
||||
def available(self):
|
||||
"""Sensor availability."""
|
||||
return self.car.data[DATA_CHARGING] is not None
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
"""Return true if charging."""
|
||||
|
@ -52,6 +52,8 @@ class LeafBatterySensor(LeafEntity, SensorEntity):
|
||||
@property
|
||||
def native_value(self):
|
||||
"""Battery state percentage."""
|
||||
if self.car.data[DATA_BATTERY] is None:
|
||||
return None
|
||||
return round(self.car.data[DATA_BATTERY])
|
||||
|
||||
@property
|
||||
@ -96,6 +98,9 @@ class LeafRangeSensor(LeafEntity, SensorEntity):
|
||||
else:
|
||||
ret = self.car.data[DATA_RANGE_AC_OFF]
|
||||
|
||||
if ret is None:
|
||||
return None
|
||||
|
||||
if not self.car.hass.config.units.is_metric or self.car.force_miles:
|
||||
ret = IMPERIAL_SYSTEM.length(ret, METRIC_SYSTEM.length_unit)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user