mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add unique id to nissanleaf entities (#62824)
Co-authored-by: Chris Talkington <chris@talkingtontech.com> Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
946544b08f
commit
469a1cae85
@ -3,6 +3,8 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from pycarwings2.pycarwings2 import Leaf
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import (
|
from homeassistant.components.binary_sensor import (
|
||||||
BinarySensorDeviceClass,
|
BinarySensorDeviceClass,
|
||||||
BinarySensorEntity,
|
BinarySensorEntity,
|
||||||
@ -40,6 +42,11 @@ class LeafPluggedInSensor(LeafEntity, BinarySensorEntity):
|
|||||||
|
|
||||||
_attr_device_class = BinarySensorDeviceClass.PLUG
|
_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
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Sensor name."""
|
"""Sensor name."""
|
||||||
@ -61,6 +68,11 @@ class LeafChargingSensor(LeafEntity, BinarySensorEntity):
|
|||||||
|
|
||||||
_attr_device_class = BinarySensorDeviceClass.BATTERY_CHARGING
|
_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
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Sensor name."""
|
"""Sensor name."""
|
||||||
|
@ -52,6 +52,11 @@ def setup_platform(
|
|||||||
class LeafBatterySensor(LeafEntity, SensorEntity):
|
class LeafBatterySensor(LeafEntity, SensorEntity):
|
||||||
"""Nissan Leaf Battery Sensor."""
|
"""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
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Sensor Name."""
|
"""Sensor Name."""
|
||||||
@ -88,6 +93,10 @@ class LeafRangeSensor(LeafEntity, SensorEntity):
|
|||||||
"""Set up range sensor. Store if AC on."""
|
"""Set up range sensor. Store if AC on."""
|
||||||
self._ac_on = ac_on
|
self._ac_on = ac_on
|
||||||
super().__init__(car)
|
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
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
|
@ -4,6 +4,8 @@ from __future__ import annotations
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from pycarwings2.pycarwings2 import Leaf
|
||||||
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity import ToggleEntity
|
from homeassistant.helpers.entity import ToggleEntity
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
@ -35,6 +37,11 @@ def setup_platform(
|
|||||||
class LeafClimateSwitch(LeafEntity, ToggleEntity):
|
class LeafClimateSwitch(LeafEntity, ToggleEntity):
|
||||||
"""Nissan Leaf Climate Control switch."""
|
"""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
|
@property
|
||||||
def name(self) -> str:
|
def name(self) -> str:
|
||||||
"""Switch name."""
|
"""Switch name."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user