Add entity translations to Tesla Wall Connector (#96242)

pull/96866/head
Joost Lekkerkerker 2023-07-18 21:53:54 +02:00 committed by GitHub
parent c2d66cc14a
commit 3681816a43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 56 additions and 20 deletions

View File

@ -122,11 +122,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
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:
"""Get a unique entity name."""
return f"{serial_number}-{key}"
@ -135,6 +130,8 @@ def get_unique_id(serial_number: str, key: str) -> str:
class WallConnectorEntity(CoordinatorEntity):
"""Base class for Wall Connector entities."""
_attr_has_entity_name = True
def __init__(self, wall_connector_data: WallConnectorData) -> None:
"""Initialize WallConnector Entity."""
self.wall_connector_data = wall_connector_data

View File

@ -16,7 +16,6 @@ from . import (
WallConnectorData,
WallConnectorEntity,
WallConnectorLambdaValueGetterMixin,
prefix_entity_name,
)
from .const import DOMAIN, WALLCONNECTOR_DATA_VITALS
@ -33,14 +32,14 @@ class WallConnectorBinarySensorDescription(
WALL_CONNECTOR_SENSORS = [
WallConnectorBinarySensorDescription(
key="vehicle_connected",
name=prefix_entity_name("Vehicle connected"),
translation_key="vehicle_connected",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].vehicle_connected,
device_class=BinarySensorDeviceClass.PLUG,
),
WallConnectorBinarySensorDescription(
key="contactor_closed",
name=prefix_entity_name("Contactor closed"),
translation_key="contactor_closed",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].contactor_closed,
device_class=BinarySensorDeviceClass.BATTERY_CHARGING,

View File

@ -24,7 +24,6 @@ from . import (
WallConnectorData,
WallConnectorEntity,
WallConnectorLambdaValueGetterMixin,
prefix_entity_name,
)
from .const import DOMAIN, WALLCONNECTOR_DATA_LIFETIME, WALLCONNECTOR_DATA_VITALS
@ -41,13 +40,13 @@ class WallConnectorSensorDescription(
WALL_CONNECTOR_SENSORS = [
WallConnectorSensorDescription(
key="evse_state",
name=prefix_entity_name("State"),
translation_key="evse_state",
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].evse_state,
),
WallConnectorSensorDescription(
key="handle_temp_c",
name=prefix_entity_name("Handle Temperature"),
translation_key="handle_temp_c",
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
value_fn=lambda data: round(data[WALLCONNECTOR_DATA_VITALS].handle_temp_c, 1),
device_class=SensorDeviceClass.TEMPERATURE,
@ -56,7 +55,7 @@ WALL_CONNECTOR_SENSORS = [
),
WallConnectorSensorDescription(
key="grid_v",
name=prefix_entity_name("Grid Voltage"),
translation_key="grid_v",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
value_fn=lambda data: round(data[WALLCONNECTOR_DATA_VITALS].grid_v, 1),
device_class=SensorDeviceClass.VOLTAGE,
@ -65,7 +64,7 @@ WALL_CONNECTOR_SENSORS = [
),
WallConnectorSensorDescription(
key="grid_hz",
name=prefix_entity_name("Grid Frequency"),
translation_key="grid_hz",
native_unit_of_measurement=UnitOfFrequency.HERTZ,
value_fn=lambda data: round(data[WALLCONNECTOR_DATA_VITALS].grid_hz, 3),
device_class=SensorDeviceClass.FREQUENCY,
@ -74,7 +73,7 @@ WALL_CONNECTOR_SENSORS = [
),
WallConnectorSensorDescription(
key="current_a_a",
name=prefix_entity_name("Phase A Current"),
translation_key="current_a_a",
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].currentA_a,
device_class=SensorDeviceClass.CURRENT,
@ -83,7 +82,7 @@ WALL_CONNECTOR_SENSORS = [
),
WallConnectorSensorDescription(
key="current_b_a",
name=prefix_entity_name("Phase B Current"),
translation_key="current_b_a",
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].currentB_a,
device_class=SensorDeviceClass.CURRENT,
@ -92,7 +91,7 @@ WALL_CONNECTOR_SENSORS = [
),
WallConnectorSensorDescription(
key="current_c_a",
name=prefix_entity_name("Phase C Current"),
translation_key="current_c_a",
native_unit_of_measurement=UnitOfElectricCurrent.AMPERE,
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].currentC_a,
device_class=SensorDeviceClass.CURRENT,
@ -101,7 +100,7 @@ WALL_CONNECTOR_SENSORS = [
),
WallConnectorSensorDescription(
key="voltage_a_v",
name=prefix_entity_name("Phase A Voltage"),
translation_key="voltage_a_v",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].voltageA_v,
device_class=SensorDeviceClass.VOLTAGE,
@ -110,7 +109,7 @@ WALL_CONNECTOR_SENSORS = [
),
WallConnectorSensorDescription(
key="voltage_b_v",
name=prefix_entity_name("Phase B Voltage"),
translation_key="voltage_b_v",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].voltageB_v,
device_class=SensorDeviceClass.VOLTAGE,
@ -119,7 +118,7 @@ WALL_CONNECTOR_SENSORS = [
),
WallConnectorSensorDescription(
key="voltage_c_v",
name=prefix_entity_name("Phase C Voltage"),
translation_key="voltage_c_v",
native_unit_of_measurement=UnitOfElectricPotential.VOLT,
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].voltageC_v,
device_class=SensorDeviceClass.VOLTAGE,
@ -128,7 +127,6 @@ WALL_CONNECTOR_SENSORS = [
),
WallConnectorSensorDescription(
key="energy_kWh",
name=prefix_entity_name("Energy"),
native_unit_of_measurement=UnitOfEnergy.WATT_HOUR,
value_fn=lambda data: data[WALLCONNECTOR_DATA_LIFETIME].energy_wh,
device_class=SensorDeviceClass.ENERGY,

View File

@ -16,5 +16,47 @@
"abort": {
"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"
}
}
}
}