mirror of
https://github.com/home-assistant/core.git
synced 2026-10-07 06:50:41 -04:00
Fix Teslemetry target temperature for right-hand drive streaming vehicles (#183421)
This commit is contained in:
@@ -72,7 +72,10 @@ async def async_setup_entry(
|
||||
)
|
||||
if vehicle.poll or not firmware_at_least(vehicle.firmware, "2024.44.25")
|
||||
else TeslemetryStreamingClimateEntity(
|
||||
vehicle, TeslemetryClimateSide.DRIVER, entry.runtime_data.scopes
|
||||
vehicle,
|
||||
TeslemetryClimateSide.DRIVER,
|
||||
entry.runtime_data.scopes,
|
||||
vehicles_metadata[vehicle.vin].get("config", {}).get("rhd", False),
|
||||
)
|
||||
for vehicle in entry.runtime_data.vehicles
|
||||
),
|
||||
@@ -260,6 +263,7 @@ class TeslemetryStreamingClimateEntity(
|
||||
data: TeslemetryVehicleData,
|
||||
side: TeslemetryClimateSide,
|
||||
scopes: list[Scope],
|
||||
rhd: bool,
|
||||
) -> None:
|
||||
"""Initialize the climate."""
|
||||
|
||||
@@ -287,7 +291,7 @@ class TeslemetryStreamingClimateEntity(
|
||||
float,
|
||||
data.coordinator.data.get("climate_state_max_avail_temp", DEFAULT_MAX_TEMP),
|
||||
)
|
||||
self.rhd: bool = data.coordinator.data.get("vehicle_config_rhd", False)
|
||||
self.rhd = rhd
|
||||
|
||||
@override
|
||||
async def async_added_to_hass(self) -> None:
|
||||
@@ -320,9 +324,6 @@ class TeslemetryStreamingClimateEntity(
|
||||
self._async_handle_climate_keeper_mode
|
||||
)
|
||||
)
|
||||
self.async_on_remove(
|
||||
self.vehicle.stream_vehicle.listen_RightHandDrive(self._async_handle_rhd)
|
||||
)
|
||||
|
||||
if self.side == TeslemetryClimateSide.DRIVER:
|
||||
if self.rhd:
|
||||
@@ -373,10 +374,6 @@ class TeslemetryStreamingClimateEntity(
|
||||
self._attr_target_temperature = data
|
||||
self.async_write_ha_state()
|
||||
|
||||
def _async_handle_rhd(self, data: bool | None) -> None:
|
||||
if data is not None:
|
||||
self.rhd = data
|
||||
|
||||
|
||||
COP_MODES = {
|
||||
"Off": HVACMode.OFF,
|
||||
|
||||
@@ -449,7 +449,7 @@
|
||||
'camp',
|
||||
]),
|
||||
<EntityStateAttribute.SUPPORTED_FEATURES: 'supported_features'>: <ClimateEntityFeature: 401>,
|
||||
<ClimateEntityStateAttribute.TARGET_TEMPERATURE: 'temperature'>: 21.0,
|
||||
<ClimateEntityStateAttribute.TARGET_TEMPERATURE: 'temperature'>: 22.0,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'climate.test_climate',
|
||||
@@ -478,7 +478,7 @@
|
||||
'camp',
|
||||
]),
|
||||
<EntityStateAttribute.SUPPORTED_FEATURES: 'supported_features'>: <ClimateEntityFeature: 401>,
|
||||
<ClimateEntityStateAttribute.TARGET_TEMPERATURE: 'temperature'>: 21.0,
|
||||
<ClimateEntityStateAttribute.TARGET_TEMPERATURE: 'temperature'>: 22.0,
|
||||
}),
|
||||
'context': <ANY>,
|
||||
'entity_id': 'climate.test_climate',
|
||||
|
||||
@@ -42,6 +42,8 @@ from .const import (
|
||||
VEHICLE_DATA_ALT,
|
||||
)
|
||||
|
||||
VIN = "LRW3F7EK4NC700000"
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_climate(
|
||||
@@ -449,3 +451,41 @@ async def test_cabin_overheat_protection_streaming_set_temperature(
|
||||
)
|
||||
mock_set_cop_temp.assert_called_once_with(CabinOverheatProtectionTemp.MEDIUM)
|
||||
assert hass.states.get(entity_id).attributes[ATTR_TEMPERATURE] == 35
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("rhd", "target_temperature"),
|
||||
[
|
||||
pytest.param(True, 21, id="rhd"),
|
||||
pytest.param(False, 22, id="lhd"),
|
||||
],
|
||||
)
|
||||
async def test_climate_streaming_drive_side(
|
||||
hass: HomeAssistant,
|
||||
mock_metadata: AsyncMock,
|
||||
mock_add_listener: AsyncMock,
|
||||
rhd: bool,
|
||||
target_temperature: float,
|
||||
) -> None:
|
||||
"""Test the streaming target temperature follows the driver side from metadata."""
|
||||
|
||||
metadata = deepcopy(METADATA)
|
||||
metadata["vehicles"][VIN]["config"] = {"rhd": rhd}
|
||||
mock_metadata.return_value = metadata
|
||||
|
||||
await setup_platform(hass, [Platform.CLIMATE])
|
||||
|
||||
mock_add_listener.send(
|
||||
{
|
||||
"vin": VIN,
|
||||
"data": {
|
||||
Signal.HVAC_LEFT_TEMPERATURE_REQUEST: 22,
|
||||
Signal.HVAC_RIGHT_TEMPERATURE_REQUEST: 21,
|
||||
},
|
||||
"createdAt": "2024-10-04T10:45:17.537Z",
|
||||
}
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
state = hass.states.get("climate.test_climate")
|
||||
assert state.attributes[ATTR_TEMPERATURE] == target_temperature
|
||||
|
||||
Reference in New Issue
Block a user