Skip to content

Commit

Permalink
feat: add trigger homelink button (disabled by default) (#168)
Browse files Browse the repository at this point in the history
Homelink button is disabled by default because homelink is an optional accessory.
  • Loading branch information
carleeno authored and alandtse committed Mar 27, 2022
1 parent d13f828 commit 0a39370
Show file tree
Hide file tree
Showing 3 changed files with 36 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 platforms:
- Locks - Door lock, rear trunk lock, front trunk (frunk) lock and charger door lock. Enables you to control Tesla's door, trunks and charger door lock.
- Climate - HVAC control. Allow you to control (turn on/off, set target temperature) your Tesla's HVAC system. Also enables preset modes to enable or disable max defrost mode `defrost` or `normal` operation mode. **NOTE:** Set `state` to `heat_cool` or `off` to enable/disable your Tesla's climate system via a scene.
- Switches - Charger and max range switch allow you to start/stop charging and set max range charging. Polling switch allows you to disable polling of vehicles to conserve battery. Sentry mode switch enables or disable Sentry mode.
- Buttons - Horn and Flash lights
- Buttons - Horn, Flash lights, and Trigger homelink. **Note:** The homelink button is disabled by default as many vehicles don't have the homelink option. Enable via configuration/entities if desired.

The following sensors provide all available vehicle data as attributes. These sensors are disabled by default and need to be enabled in HASS first. It is also recommended to exclude these sensors from [recorder](https://www.home-assistant.io/integrations/recorder/).

Expand Down
34 changes: 34 additions & 0 deletions custom_components/tesla_custom/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
_LOGGER = logging.getLogger(__name__)

from homeassistant.components.button import ButtonEntity
from teslajsonpy.exceptions import HomelinkError

from . import DOMAIN as TESLA_DOMAIN
from .tesla_device import TeslaDevice
Expand All @@ -19,6 +20,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
entities.append(Horn(device, coordinator))
elif device.type == "flash lights":
entities.append(FlashLights(device, coordinator))
elif device.type == "trigger homelink":
entities.append(TriggerHomelink(device, coordinator))
async_add_entities(entities, True)


Expand Down Expand Up @@ -50,3 +53,34 @@ async def async_press(self, **kwargs):
"""Send the command."""
_LOGGER.debug("Flash lights: %s", self.name)
await self.tesla_device.flash_lights()


class TriggerHomelink(TeslaDevice, ButtonEntity):
"""Representation of a Tesla Homelink button."""

def __init__(self, tesla_device, coordinator):
"""Initialise the button."""
super().__init__(tesla_device, coordinator)
self.controller = coordinator.controller
self.__waiting = False

@property
def available(self) -> bool:
"""Return True if entity is available."""
return (
super().available and self.tesla_device.available() and not self.__waiting
)

@TeslaDevice.Decorators.check_for_reauth
async def async_press(self, **kwargs):
"""Send the command."""
_LOGGER.debug("Trigger homelink: %s", self.name)
self.__waiting = True
self.async_write_ha_state()
try:
await self.tesla_device.trigger_homelink()
except HomelinkError as ex:
_LOGGER.error("%s", ex.message)
finally:
self.__waiting = False
self.async_write_ha_state()
1 change: 1 addition & 0 deletions custom_components/tesla_custom/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"sentry mode switch": "mdi:shield-car",
"horn": "mdi:bullhorn",
"flash lights": "mdi:car-light-high",
"trigger homelink": "mdi:garage",
"solar panel": "mdi:solar-panel",
}
AUTH_CALLBACK_PATH = "/auth/tesla/callback"
Expand Down

0 comments on commit 0a39370

Please sign in to comment.