diff --git a/homeassistant/components/nissan_leaf/binary_sensor.py b/homeassistant/components/nissan_leaf/binary_sensor.py index a46b418e917..ba4bc62d7bd 100644 --- a/homeassistant/components/nissan_leaf/binary_sensor.py +++ b/homeassistant/components/nissan_leaf/binary_sensor.py @@ -3,6 +3,8 @@ from __future__ import annotations import logging +from pycarwings2.pycarwings2 import Leaf + from homeassistant.components.binary_sensor import ( BinarySensorDeviceClass, BinarySensorEntity, @@ -40,6 +42,11 @@ class LeafPluggedInSensor(LeafEntity, BinarySensorEntity): _attr_device_class = BinarySensorDeviceClass.PLUG + def __init__(self, car: Leaf) -> None: + """Set up plug status sensor.""" + super().__init__(car) + self._attr_unique_id = f"{self.car.leaf.vin.lower()}_plugstatus" + @property def name(self) -> str: """Sensor name.""" @@ -61,6 +68,11 @@ class LeafChargingSensor(LeafEntity, BinarySensorEntity): _attr_device_class = BinarySensorDeviceClass.BATTERY_CHARGING + def __init__(self, car: Leaf) -> None: + """Set up charging status sensor.""" + super().__init__(car) + self._attr_unique_id = f"{self.car.leaf.vin.lower()}_chargingstatus" + @property def name(self) -> str: """Sensor name.""" diff --git a/homeassistant/components/nissan_leaf/sensor.py b/homeassistant/components/nissan_leaf/sensor.py index 3d1ad088fa0..746776979bc 100644 --- a/homeassistant/components/nissan_leaf/sensor.py +++ b/homeassistant/components/nissan_leaf/sensor.py @@ -52,6 +52,11 @@ def setup_platform( class LeafBatterySensor(LeafEntity, SensorEntity): """Nissan Leaf Battery Sensor.""" + def __init__(self, car: Leaf) -> None: + """Set up battery sensor.""" + super().__init__(car) + self._attr_unique_id = f"{self.car.leaf.vin.lower()}_soc" + @property def name(self) -> str: """Sensor Name.""" @@ -88,6 +93,10 @@ class LeafRangeSensor(LeafEntity, SensorEntity): """Set up range sensor. Store if AC on.""" self._ac_on = ac_on super().__init__(car) + if ac_on: + self._attr_unique_id = f"{self.car.leaf.vin.lower()}_range_ac" + else: + self._attr_unique_id = f"{self.car.leaf.vin.lower()}_range" @property def name(self) -> str: diff --git a/homeassistant/components/nissan_leaf/switch.py b/homeassistant/components/nissan_leaf/switch.py index de4ee2dc043..40b4885b206 100644 --- a/homeassistant/components/nissan_leaf/switch.py +++ b/homeassistant/components/nissan_leaf/switch.py @@ -4,6 +4,8 @@ from __future__ import annotations import logging from typing import Any +from pycarwings2.pycarwings2 import Leaf + from homeassistant.core import HomeAssistant from homeassistant.helpers.entity import ToggleEntity from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -35,6 +37,11 @@ def setup_platform( class LeafClimateSwitch(LeafEntity, ToggleEntity): """Nissan Leaf Climate Control switch.""" + def __init__(self, car: Leaf) -> None: + """Set up climate control switch.""" + super().__init__(car) + self._attr_unique_id = f"{self.car.leaf.vin.lower()}_climatecontrol" + @property def name(self) -> str: """Switch name."""