Skip to content

Commit

Permalink
fix: turn climate on when turning seat heater on (#406)
Browse files Browse the repository at this point in the history
closes #392
  • Loading branch information
InTheDaylight14 committed Dec 5, 2022
1 parent d80fd10 commit 78e90e4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ This integration provides the following entities for vehicles:
- Device tracker - car location<sup>1</sup>.
- Locks - door lock, and charge port latch lock.
**Note:** Set `state` to `heat_cool` or `off` to enable/disable your Tesla's climate system via a scene.
- Selects - seat heaters and cabin overheat protection<sup>2</sup>.
- Selects - seat heaters and cabin overheat protection<sup>2</sup>. **Note:** Turning on a heated seat will cause the climate to turn on.
- Sensors - battery level, charge rate, energy added, inside/outside temperature, odometer and estimated range.
- Switches - heated steering wheel, charger, sentry mode and polling<sup>1</sup>.
- Update - software update<sup>2</sup>
Expand Down
3 changes: 3 additions & 0 deletions custom_components/tesla_custom/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ async def async_select_option(self, option: str, **kwargs):
"""Change the selected option."""
level: int = HEATER_OPTIONS.index(option)

if not self._car.is_climate_on and level > 0:
await self._car.set_hvac_mode("on")

_LOGGER.debug("Setting %s to %s", self.name, level)
await self._car.remote_seat_heater_request(level, SEAT_ID_MAP[self._seat_name])

Expand Down
10 changes: 10 additions & 0 deletions tests/test_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ async def test_car_heated_seat_select(hass: HomeAssistant) -> None:
)
mock_remote_seat_heater_request.assert_awaited_with(3, 0)

with patch("teslajsonpy.car.TeslaCar.set_hvac_mode") as mock_set_hvac_mode:
# Test selecting "Low"
assert await hass.services.async_call(
SELECT_DOMAIN,
SERVICE_SELECT_OPTION,
{ATTR_ENTITY_ID: "select.my_model_s_heated_seat_left", "option": "Low"},
blocking=True,
)
mock_set_hvac_mode.assert_awaited_with("on")


async def test_cabin_overheat_protection(hass: HomeAssistant) -> None:
"""Tests car cabin overheat protection select."""
Expand Down

0 comments on commit 78e90e4

Please sign in to comment.