From 1abb5260c31ec1a86d4c920dafcad562cbe95534 Mon Sep 17 00:00:00 2001 From: hobbe Date: Wed, 18 Mar 2020 14:29:08 +0100 Subject: [PATCH 1/3] Add Tesla sentry mode switch --- homeassistant/components/tesla/const.py | 1 + homeassistant/components/tesla/switch.py | 32 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/homeassistant/components/tesla/const.py b/homeassistant/components/tesla/const.py index 54cb7a2e071b5..9f6f2691b797d 100644 --- a/homeassistant/components/tesla/const.py +++ b/homeassistant/components/tesla/const.py @@ -23,4 +23,5 @@ "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/switch.py b/homeassistant/components/tesla/switch.py index 331f6bd812609..e42ee4936286c 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,33 @@ async def async_update(self): _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.""" + + def __init__(self, tesla_device, controller, config_entry): + """Initialise the switch.""" + self._state = None + super().__init__(tesla_device, controller, config_entry) + + 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._state + + async def async_update(self): + """Update the state of the switch.""" + _LOGGER.debug("Updating state for: %s", self._name) + await super().async_update() + self._state = bool(self.tesla_device.get_value()) From f2449ad1509b916c658d4cc52411e88a17f0abfb Mon Sep 17 00:00:00 2001 From: hobbe Date: Sun, 22 Mar 2020 20:00:43 +0100 Subject: [PATCH 2/3] add available property, fix is_on --- homeassistant/components/tesla/switch.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/tesla/switch.py b/homeassistant/components/tesla/switch.py index e42ee4936286c..716836821c424 100644 --- a/homeassistant/components/tesla/switch.py +++ b/homeassistant/components/tesla/switch.py @@ -121,11 +121,6 @@ async def async_update(self): class SentryModeSwitch(TeslaDevice, SwitchDevice): """Representation of a Tesla sentry mode switch.""" - def __init__(self, tesla_device, controller, config_entry): - """Initialise the switch.""" - self._state = None - super().__init__(tesla_device, controller, config_entry) - async def async_turn_on(self, **kwargs): """Send the on command.""" _LOGGER.debug("Enable sentry mode: %s", self._name) @@ -139,10 +134,14 @@ async def async_turn_off(self, **kwargs): @property def is_on(self): """Get whether the switch is in on state.""" - return self._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() - self._state = bool(self.tesla_device.get_value()) From 48d36ed9b5dd648dd6960ad0f7a6baa61550689e Mon Sep 17 00:00:00 2001 From: hobbe Date: Sun, 22 Mar 2020 21:49:32 +0100 Subject: [PATCH 3/3] bump teslajsonpy to 0.6.0 --- homeassistant/components/tesla/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/tesla/manifest.json b/homeassistant/components/tesla/manifest.json index 950a860b308f6..1bba8436312dd 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/requirements_all.txt b/requirements_all.txt index 962e5d2bc45b7..680bfc5b23341 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1996,7 +1996,7 @@ temperusb==1.5.3 # tensorflow==1.13.2 # 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 297f3d8f1738d..b17d56d0d5878 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -693,7 +693,7 @@ sunwatcher==0.2.1 tellduslive==0.10.10 # homeassistant.components.tesla -teslajsonpy==0.5.1 +teslajsonpy==0.6.0 # homeassistant.components.toon toonapilib==3.2.4