mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add entity translations to Tesla Wall Connector (#96242)
This commit is contained in:
parent
c2d66cc14a
commit
3681816a43
@ -122,11 +122,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
return unload_ok
|
return unload_ok
|
||||||
|
|
||||||
|
|
||||||
def prefix_entity_name(name: str) -> str:
|
|
||||||
"""Prefixes entity name."""
|
|
||||||
return f"{WALLCONNECTOR_DEVICE_NAME} {name}"
|
|
||||||
|
|
||||||
|
|
||||||
def get_unique_id(serial_number: str, key: str) -> str:
|
def get_unique_id(serial_number: str, key: str) -> str:
|
||||||
"""Get a unique entity name."""
|
"""Get a unique entity name."""
|
||||||
return f"{serial_number}-{key}"
|
return f"{serial_number}-{key}"
|
||||||
@ -135,6 +130,8 @@ def get_unique_id(serial_number: str, key: str) -> str:
|
|||||||
class WallConnectorEntity(CoordinatorEntity):
|
class WallConnectorEntity(CoordinatorEntity):
|
||||||
"""Base class for Wall Connector entities."""
|
"""Base class for Wall Connector entities."""
|
||||||
|
|
||||||
|
_attr_has_entity_name = True
|
||||||
|
|
||||||
def __init__(self, wall_connector_data: WallConnectorData) -> None:
|
def __init__(self, wall_connector_data: WallConnectorData) -> None:
|
||||||
"""Initialize WallConnector Entity."""
|
"""Initialize WallConnector Entity."""
|
||||||
self.wall_connector_data = wall_connector_data
|
self.wall_connector_data = wall_connector_data
|
||||||
|
@ -16,7 +16,6 @@ from . import (
|
|||||||
WallConnectorData,
|
WallConnectorData,
|
||||||
WallConnectorEntity,
|
WallConnectorEntity,
|
||||||
WallConnectorLambdaValueGetterMixin,
|
WallConnectorLambdaValueGetterMixin,
|
||||||
prefix_entity_name,
|
|
||||||
)
|
)
|
||||||
from .const import DOMAIN, WALLCONNECTOR_DATA_VITALS
|
from .const import DOMAIN, WALLCONNECTOR_DATA_VITALS
|
||||||
|
|
||||||
@ -33,14 +32,14 @@ class WallConnectorBinarySensorDescription(
|
|||||||
WALL_CONNECTOR_SENSORS = [
|
WALL_CONNECTOR_SENSORS = [
|
||||||
WallConnectorBinarySensorDescription(
|
WallConnectorBinarySensorDescription(
|
||||||
key="vehicle_connected",
|
key="vehicle_connected",
|
||||||
name=prefix_entity_name("Vehicle connected"),
|
translation_key="vehicle_connected",
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].vehicle_connected,
|
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].vehicle_connected,
|
||||||
device_class=BinarySensorDeviceClass.PLUG,
|
device_class=BinarySensorDeviceClass.PLUG,
|
||||||
),
|
),
|
||||||
WallConnectorBinarySensorDescription(
|
WallConnectorBinarySensorDescription(
|
||||||
key="contactor_closed",
|
key="contactor_closed",
|
||||||
name=prefix_entity_name("Contactor closed"),
|
translation_key="contactor_closed",
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].contactor_closed,
|
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].contactor_closed,
|
||||||
device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
|
device_class=BinarySensorDeviceClass.BATTERY_CHARGING,
|
||||||
|
@ -24,7 +24,6 @@ from . import (
|
|||||||
WallConnectorData,
|
WallConnectorData,
|
||||||
WallConnectorEntity,
|
WallConnectorEntity,
|
||||||
WallConnectorLambdaValueGetterMixin,
|
WallConnectorLambdaValueGetterMixin,
|
||||||
prefix_entity_name,
|
|
||||||
)
|
)
|
||||||
from .const import DOMAIN, WALLCONNECTOR_DATA_LIFETIME, WALLCONNECTOR_DATA_VITALS
|
from .const import DOMAIN, WALLCONNECTOR_DATA_LIFETIME, WALLCONNECTOR_DATA_VITALS
|
||||||
|
|
||||||
@ -41,13 +40,13 @@ class WallConnectorSensorDescription(
|
|||||||
WALL_CONNECTOR_SENSORS = [
|
WALL_CONNECTOR_SENSORS = [
|
||||||
WallConnectorSensorDescription(
|
WallConnectorSensorDescription(
|
||||||
key="evse_state",
|
key="evse_state",
|
||||||
name=prefix_entity_name("State"),
|
translation_key="evse_state",
|
||||||
entity_category=EntityCategory.DIAGNOSTIC,
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].evse_state,
|
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].evse_state,
|
||||||
),
|
),
|
||||||
WallConnectorSensorDescription(
|
WallConnectorSensorDescription(
|
||||||
key="handle_temp_c",
|
key="handle_temp_c",
|
||||||
name=prefix_entity_name("Handle Temperature"),
|
translation_key="handle_temp_c",
|
||||||
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
value_fn=lambda data: round(data[WALLCONNECTOR_DATA_VITALS].handle_temp_c, 1),
|
value_fn=lambda data: round(data[WALLCONNECTOR_DATA_VITALS].handle_temp_c, 1),
|
||||||
device_class=SensorDeviceClass.TEMPERATURE,
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
@ -56,7 +55,7 @@ WALL_CONNECTOR_SENSORS = [
|
|||||||
),
|
),
|
||||||
WallConnectorSensorDescription(
|
WallConnectorSensorDescription(
|
||||||
key="grid_v",
|
key="grid_v",
|
||||||
name=prefix_entity_name("Grid Voltage"),
|
translation_key="grid_v",
|
||||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||||
value_fn=lambda data: round(data[WALLCONNECTOR_DATA_VITALS].grid_v, 1),
|
value_fn=lambda data: round(data[WALLCONNECTOR_DATA_VITALS].grid_v, 1),
|
||||||
device_class=SensorDeviceClass.VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
@ -65,7 +64,7 @@ WALL_CONNECTOR_SENSORS = [
|
|||||||
),
|
),
|
||||||
WallConnectorSensorDescription(
|
WallConnectorSensorDescription(
|
||||||
key="grid_hz",
|
key="grid_hz",
|
||||||
name=prefix_entity_name("Grid Frequency"),
|
translation_key="grid_hz",
|
||||||
native_unit_of_measurement=UnitOfFrequency.HERTZ,
|
native_unit_of_measurement=UnitOfFrequency.HERTZ,
|
||||||
value_fn=lambda data: round(data[WALLCONNECTOR_DATA_VITALS].grid_hz, 3),
|
value_fn=lambda data: round(data[WALLCONNECTOR_DATA_VITALS].grid_hz, 3),
|
||||||
device_class=SensorDeviceClass.FREQUENCY,
|
device_class=SensorDeviceClass.FREQUENCY,
|
||||||
@ -74,7 +73,7 @@ WALL_CONNECTOR_SENSORS = [
|
|||||||
),
|
),
|
||||||
WallConnectorSensorDescription(
|
WallConnectorSensorDescription(
|
||||||
key="current_a_a",
|
key="current_a_a",
|
||||||
name=prefix_entity_name("Phase A Current"),
|
translation_key="current_a_a",
|
||||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].currentA_a,
|
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].currentA_a,
|
||||||
device_class=SensorDeviceClass.CURRENT,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
@ -83,7 +82,7 @@ WALL_CONNECTOR_SENSORS = [
|
|||||||
),
|
),
|
||||||
WallConnectorSensorDescription(
|
WallConnectorSensorDescription(
|
||||||
key="current_b_a",
|
key="current_b_a",
|
||||||
name=prefix_entity_name("Phase B Current"),
|
translation_key="current_b_a",
|
||||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].currentB_a,
|
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].currentB_a,
|
||||||
device_class=SensorDeviceClass.CURRENT,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
@ -92,7 +91,7 @@ WALL_CONNECTOR_SENSORS = [
|
|||||||
),
|
),
|
||||||
WallConnectorSensorDescription(
|
WallConnectorSensorDescription(
|
||||||
key="current_c_a",
|
key="current_c_a",
|
||||||
name=prefix_entity_name("Phase C Current"),
|
translation_key="current_c_a",
|
||||||
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
|
||||||
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].currentC_a,
|
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].currentC_a,
|
||||||
device_class=SensorDeviceClass.CURRENT,
|
device_class=SensorDeviceClass.CURRENT,
|
||||||
@ -101,7 +100,7 @@ WALL_CONNECTOR_SENSORS = [
|
|||||||
),
|
),
|
||||||
WallConnectorSensorDescription(
|
WallConnectorSensorDescription(
|
||||||
key="voltage_a_v",
|
key="voltage_a_v",
|
||||||
name=prefix_entity_name("Phase A Voltage"),
|
translation_key="voltage_a_v",
|
||||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||||
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].voltageA_v,
|
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].voltageA_v,
|
||||||
device_class=SensorDeviceClass.VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
@ -110,7 +109,7 @@ WALL_CONNECTOR_SENSORS = [
|
|||||||
),
|
),
|
||||||
WallConnectorSensorDescription(
|
WallConnectorSensorDescription(
|
||||||
key="voltage_b_v",
|
key="voltage_b_v",
|
||||||
name=prefix_entity_name("Phase B Voltage"),
|
translation_key="voltage_b_v",
|
||||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||||
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].voltageB_v,
|
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].voltageB_v,
|
||||||
device_class=SensorDeviceClass.VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
@ -119,7 +118,7 @@ WALL_CONNECTOR_SENSORS = [
|
|||||||
),
|
),
|
||||||
WallConnectorSensorDescription(
|
WallConnectorSensorDescription(
|
||||||
key="voltage_c_v",
|
key="voltage_c_v",
|
||||||
name=prefix_entity_name("Phase C Voltage"),
|
translation_key="voltage_c_v",
|
||||||
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
|
||||||
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].voltageC_v,
|
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].voltageC_v,
|
||||||
device_class=SensorDeviceClass.VOLTAGE,
|
device_class=SensorDeviceClass.VOLTAGE,
|
||||||
@ -128,7 +127,6 @@ WALL_CONNECTOR_SENSORS = [
|
|||||||
),
|
),
|
||||||
WallConnectorSensorDescription(
|
WallConnectorSensorDescription(
|
||||||
key="energy_kWh",
|
key="energy_kWh",
|
||||||
name=prefix_entity_name("Energy"),
|
|
||||||
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
|
||||||
value_fn=lambda data: data[WALLCONNECTOR_DATA_LIFETIME].energy_wh,
|
value_fn=lambda data: data[WALLCONNECTOR_DATA_LIFETIME].energy_wh,
|
||||||
device_class=SensorDeviceClass.ENERGY,
|
device_class=SensorDeviceClass.ENERGY,
|
||||||
|
@ -16,5 +16,47 @@
|
|||||||
"abort": {
|
"abort": {
|
||||||
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
"already_configured": "[%key:common::config_flow::abort::already_configured_device%]"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"entity": {
|
||||||
|
"binary_sensor": {
|
||||||
|
"vehicle_connected": {
|
||||||
|
"name": "Vehicle connected"
|
||||||
|
},
|
||||||
|
"contactor_closed": {
|
||||||
|
"name": "Contactor closed"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sensor": {
|
||||||
|
"evse_state": {
|
||||||
|
"name": "State"
|
||||||
|
},
|
||||||
|
"handle_temp_c": {
|
||||||
|
"name": "Handle temperature"
|
||||||
|
},
|
||||||
|
"grid_v": {
|
||||||
|
"name": "Grid voltage"
|
||||||
|
},
|
||||||
|
"grid_hz": {
|
||||||
|
"name": "Grid frequency"
|
||||||
|
},
|
||||||
|
"current_a_a": {
|
||||||
|
"name": "Phase A current"
|
||||||
|
},
|
||||||
|
"current_b_a": {
|
||||||
|
"name": "Phase B current"
|
||||||
|
},
|
||||||
|
"current_c_a": {
|
||||||
|
"name": "Phase C current"
|
||||||
|
},
|
||||||
|
"voltage_a_v": {
|
||||||
|
"name": "Phase A voltage"
|
||||||
|
},
|
||||||
|
"voltage_b_v": {
|
||||||
|
"name": "Phase B voltage"
|
||||||
|
},
|
||||||
|
"voltage_c_v": {
|
||||||
|
"name": "Phase C voltage"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user