Add readable state for tesla wall connector (#107909)
* Add readable state for tesla wall connector * Add test * Display raw sensor by default * Use none instead of unknown * Remove old state from tests * Rename raw state to status code * Test unknown * Update homeassistant/components/tesla_wall_connector/strings.json Co-authored-by: Franck Nijhof <git@frenck.dev> --------- Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
ddb56fe20d
commit
c8bfb288a3
3 changed files with 46 additions and 5 deletions
|
@ -29,6 +29,19 @@ from .const import DOMAIN, WALLCONNECTOR_DATA_LIFETIME, WALLCONNECTOR_DATA_VITAL
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
EVSE_STATE = {
|
||||
0: "booting",
|
||||
1: "not_connected",
|
||||
2: "connected",
|
||||
4: "ready",
|
||||
6: "negotiating",
|
||||
7: "error",
|
||||
8: "charging_finished",
|
||||
9: "waiting_car",
|
||||
10: "charging_reduced",
|
||||
11: "charging",
|
||||
}
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class WallConnectorSensorDescription(
|
||||
|
@ -40,9 +53,20 @@ class WallConnectorSensorDescription(
|
|||
WALL_CONNECTOR_SENSORS = [
|
||||
WallConnectorSensorDescription(
|
||||
key="evse_state",
|
||||
translation_key="evse_state",
|
||||
translation_key="status_code",
|
||||
entity_category=EntityCategory.DIAGNOSTIC,
|
||||
value_fn=lambda data: data[WALLCONNECTOR_DATA_VITALS].evse_state,
|
||||
entity_registry_enabled_default=False,
|
||||
),
|
||||
WallConnectorSensorDescription(
|
||||
key="status",
|
||||
translation_key="status",
|
||||
device_class=SensorDeviceClass.ENUM,
|
||||
value_fn=lambda data: EVSE_STATE.get(
|
||||
data[WALLCONNECTOR_DATA_VITALS].evse_state
|
||||
),
|
||||
options=list(EVSE_STATE.values()),
|
||||
icon="mdi:ev-station",
|
||||
),
|
||||
WallConnectorSensorDescription(
|
||||
key="handle_temp_c",
|
||||
|
|
|
@ -30,8 +30,23 @@
|
|||
}
|
||||
},
|
||||
"sensor": {
|
||||
"evse_state": {
|
||||
"name": "State"
|
||||
"status": {
|
||||
"name": "Status",
|
||||
"state": {
|
||||
"booting": "Booting",
|
||||
"not_connected": "Vehicle not connected",
|
||||
"connected": "Vehicle connected",
|
||||
"ready": "Ready to charge",
|
||||
"negociating": "Negociating connection",
|
||||
"error": "Error",
|
||||
"charging_finished": "Charging finished",
|
||||
"waiting_car": "Waiting for car",
|
||||
"charging_reduced": "Charging (reduced)",
|
||||
"charging": "Charging"
|
||||
}
|
||||
},
|
||||
"status_code": {
|
||||
"name": "Status code"
|
||||
},
|
||||
"handle_temp_c": {
|
||||
"name": "Handle temperature"
|
||||
|
|
|
@ -13,7 +13,9 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
|||
"""Test all sensors."""
|
||||
|
||||
entity_and_expected_values = [
|
||||
EntityAndExpectedValues("sensor.tesla_wall_connector_state", "1", "2"),
|
||||
EntityAndExpectedValues(
|
||||
"sensor.tesla_wall_connector_status", "not_connected", "unknown"
|
||||
),
|
||||
EntityAndExpectedValues(
|
||||
"sensor.tesla_wall_connector_handle_temperature", "25.5", "-1.4"
|
||||
),
|
||||
|
@ -63,7 +65,7 @@ async def test_sensors(hass: HomeAssistant) -> None:
|
|||
mock_vitals_first_update.session_energy_wh = 1234.56
|
||||
|
||||
mock_vitals_second_update = get_vitals_mock()
|
||||
mock_vitals_second_update.evse_state = 2
|
||||
mock_vitals_second_update.evse_state = 3
|
||||
mock_vitals_second_update.handle_temp_c = -1.42
|
||||
mock_vitals_second_update.grid_v = 229.21
|
||||
mock_vitals_second_update.grid_hz = 49.981
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue