From 7c44581be9bd4778be81b3819008cf70fd68f016 Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Thu, 30 Jul 2020 22:03:39 -0700 Subject: [PATCH 1/3] fix: set default lock state to None If no information is available, the component can return None --- teslajsonpy/homeassistant/lock.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/teslajsonpy/homeassistant/lock.py b/teslajsonpy/homeassistant/lock.py index a678d798..02bd85c8 100644 --- a/teslajsonpy/homeassistant/lock.py +++ b/teslajsonpy/homeassistant/lock.py @@ -34,7 +34,7 @@ def __init__(self, data, controller): """ super().__init__(data, controller) self.__manual_update_time = 0 - self.__lock_state = False + self.__lock_state = None self.type = "door lock" self.hass_type = "lock" From 8250fca9df95315f9f1d4ca8c09e883a81d7aebb Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Thu, 30 Jul 2020 22:07:30 -0700 Subject: [PATCH 2/3] fix: allow sentry mode to return None --- teslajsonpy/homeassistant/sentry_mode.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/teslajsonpy/homeassistant/sentry_mode.py b/teslajsonpy/homeassistant/sentry_mode.py index 981b93d2..1146b59e 100644 --- a/teslajsonpy/homeassistant/sentry_mode.py +++ b/teslajsonpy/homeassistant/sentry_mode.py @@ -65,8 +65,9 @@ def available(self): """Return whether the sentry mode is available.""" return self.sentry_mode_available - def is_on(self): - """Return whether the sentry mode is enabled, always False if sentry mode is not available.""" + """Return whether the sentry mode is enabled, or None if sentry mode is not available.""" + if not self.sentry_mode_available: + return None return self.sentry_mode_available and self.__sentry_mode @staticmethod From 1942205a667496eb4f276badcb73819d5432b654 Mon Sep 17 00:00:00 2001 From: "Alan D. Tse" Date: Thu, 30 Jul 2020 22:08:06 -0700 Subject: [PATCH 3/3] style: add typing hints to sentry mode --- teslajsonpy/homeassistant/sentry_mode.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/teslajsonpy/homeassistant/sentry_mode.py b/teslajsonpy/homeassistant/sentry_mode.py index 1146b59e..360168cc 100644 --- a/teslajsonpy/homeassistant/sentry_mode.py +++ b/teslajsonpy/homeassistant/sentry_mode.py @@ -6,6 +6,7 @@ https://github.com/zabuldon/teslajsonpy """ import time +from typing import Optional from teslajsonpy.homeassistant.vehicle import VehicleDevice @@ -61,21 +62,22 @@ def refresh(self) -> None: else: self.__sentry_mode = False - def available(self): + def available(self) -> bool: """Return whether the sentry mode is available.""" return self.sentry_mode_available + def is_on(self) -> Optional[bool]: """Return whether the sentry mode is enabled, or None if sentry mode is not available.""" if not self.sentry_mode_available: return None return self.sentry_mode_available and self.__sentry_mode @staticmethod - def has_battery(): + def has_battery() -> bool: """Return whether the device has a battery.""" return False - async def enable_sentry_mode(self): + async def enable_sentry_mode(self) -> None: """Enable the sentry mode.""" if self.sentry_mode_available and not self.__sentry_mode: data = await self._controller.command( @@ -85,7 +87,7 @@ async def enable_sentry_mode(self): self.__sentry_mode = True self.__manual_update_time = time.time() - async def disable_sentry_mode(self): + async def disable_sentry_mode(self) -> None: """Disable the sentry mode.""" if self.sentry_mode_available and self.__sentry_mode: data = await self._controller.command(