Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Heated Steering Wheel and Seats #188

Merged
merged 16 commits into from
Apr 24, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions custom_components/tesla_custom/switch.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
"""Support for Tesla charger switches."""
from custom_components.tesla_custom.const import ICONS
import logging
import asyncio
import async_timeout

from homeassistant.components.switch import SwitchEntity

from .climate import HVAC_MODE_HEAT_COOL

from . import DOMAIN as TESLA_DOMAIN
from .tesla_device import TeslaDevice

Expand Down Expand Up @@ -34,6 +38,7 @@ class HeatedSteeringWheelSwitch(TeslaDevice, SwitchEntity):
async def async_turn_on(self, **kwargs):
"""Send the on command."""
_LOGGER.debug("Turn on Heating Steering Wheel: %s", self.name)
await self.wait_for_climate()
await self.tesla_device.set_steering_wheel_heat(True)
self.async_write_ha_state()

Expand All @@ -49,6 +54,32 @@ def is_on(self):
"""Get whether the switch is in on state."""
return self.tesla_device.get_steering_wheel_heat()

async def wait_for_climate(self):
"""Wait for Aircon."""

entry_data = self.hass.data[TESLA_DOMAIN][self.config_entry_id]
climate_devices = entry_data["devices"].get("climate", [])

if len(climate_devices) > 0:
climate_device = climate_devices[0]
else:
return False

async with async_timeout.timeout(30):
while True:
hvac_mode = climate_device.is_hvac_enabled()

if hvac_mode is True:
_LOGGER.debug("HVAC Enabled")
return True
else:
_LOGGER.info("Enabing Climate to activate Heated Steering Wheel")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean it will repeatedly send the climate on command every second for up to 30s?
Wouldn't you rather send it once and wait? Or is it sometimes flaky, and the 30 retries be potentially useful?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is probably not the best way to implement because it will spam the api. Thinking about this more, it's probably much cleaner to have a single api command that sends the hvac start command, checks ever few seconds to see if it's been enabled, and then issues the second command.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really feels like the wakeup decorator. Instead of waking up the car, it instead is enabling the hvac.

await climate_device.set_status(True)

await asyncio.sleep(1)

return False


class ChargerSwitch(TeslaDevice, SwitchEntity):
"""Representation of a Tesla charger switch."""
Expand Down