diff --git a/homeassistant/components/tesla/const.py b/homeassistant/components/tesla/const.py index d7930c01fe89acffd2c4e8f4e54c91b92bad6b25..2b8485c76164ef379ca3413f709467259e1e0682 100644 --- a/homeassistant/components/tesla/const.py +++ b/homeassistant/components/tesla/const.py @@ -25,4 +25,5 @@ ICONS = { "temperature sensor": "mdi:thermometer", "location tracker": "mdi:crosshairs-gps", "charging rate sensor": "mdi:speedometer", + "sentry mode switch": "mdi:shield-car", } diff --git a/homeassistant/components/tesla/manifest.json b/homeassistant/components/tesla/manifest.json index 950a860b308f68e6567e35499f5b6c26006e8bed..1bba8436312ddca6652e281342e7b43f9cd2251c 100644 --- a/homeassistant/components/tesla/manifest.json +++ b/homeassistant/components/tesla/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/tesla", "requirements": [ - "teslajsonpy==0.5.1" + "teslajsonpy==0.6.0" ], "dependencies": [], "codeowners": [ diff --git a/homeassistant/components/tesla/switch.py b/homeassistant/components/tesla/switch.py index 331f6bd812609d491c5ca1335f5a485d01568f32..716836821c4247b0824479b5dad24e30cf68f765 100644 --- a/homeassistant/components/tesla/switch.py +++ b/homeassistant/components/tesla/switch.py @@ -19,6 +19,8 @@ async def async_setup_entry(hass, config_entry, async_add_entities): entities.append(UpdateSwitch(device, controller, config_entry)) elif device.type == "maxrange switch": entities.append(RangeSwitch(device, controller, config_entry)) + elif device.type == "sentry mode switch": + entities.append(SentryModeSwitch(device, controller, config_entry)) async_add_entities(entities, True) @@ -114,3 +116,32 @@ class UpdateSwitch(TeslaDevice, SwitchDevice): _LOGGER.debug("Updating state for: %s %s", self._name, car_id) await super().async_update() self._state = bool(self.controller.get_updates(car_id)) + + +class SentryModeSwitch(TeslaDevice, SwitchDevice): + """Representation of a Tesla sentry mode switch.""" + + async def async_turn_on(self, **kwargs): + """Send the on command.""" + _LOGGER.debug("Enable sentry mode: %s", self._name) + await self.tesla_device.enable_sentry_mode() + + async def async_turn_off(self, **kwargs): + """Send the off command.""" + _LOGGER.debug("Disable sentry mode: %s", self._name) + await self.tesla_device.disable_sentry_mode() + + @property + def is_on(self): + """Get whether the switch is in on state.""" + return self.tesla_device.is_on() + + @property + def available(self): + """Indicate if Home Assistant is able to read the state and control the underlying device.""" + return self.tesla_device.available() + + async def async_update(self): + """Update the state of the switch.""" + _LOGGER.debug("Updating state for: %s", self._name) + await super().async_update() diff --git a/requirements_all.txt b/requirements_all.txt index e2f81dbcf202b44801c3dcb5ac60b430a83a69da..44422771b13478df0c66882742ca22963019f608 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -2000,7 +2000,7 @@ temperusb==1.5.3 tesla-powerwall==0.1.1 # homeassistant.components.tesla -teslajsonpy==0.5.1 +teslajsonpy==0.6.0 # homeassistant.components.thermoworks_smoke thermoworks_smoke==0.1.8 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index d5b56f9c14c52b6b08a273e29463205cc206d509..f8ed63bf8b378416616d71935000f92c2f713a52 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -719,7 +719,7 @@ tellduslive==0.10.10 tesla-powerwall==0.1.1 # homeassistant.components.tesla -teslajsonpy==0.5.1 +teslajsonpy==0.6.0 # homeassistant.components.toon toonapilib==3.2.4