Skip to content

Commit

Permalink
style: add typing to binary_sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Aug 8, 2020
1 parent d5901c7 commit 3272bd6
Showing 1 changed file with 32 additions and 30 deletions.
62 changes: 32 additions & 30 deletions teslajsonpy/homeassistant/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,31 @@ def __init__(self, data: Dict, controller):
"""
super().__init__(data, controller)
self.__state = None
self.__state: Optional[bool] = None

self.type = "binary sensor"
self.hass_type = "binary_sensor"
self._sensor_type = None
self.name = self._name()
self.uniq_name = self._uniq_name()
self.type: Text = "binary sensor"
self.hass_type: Text = "binary_sensor"
# this will be returned to HA as a device_class
# https://developers.home-assistant.io/docs/core/entity/binary-sensor
self._sensor_type: Optional[Text] = None
self.name: Text = self._name()
self.uniq_name: Text = self._uniq_name()

async def async_update(self, wake_if_asleep=False, force=False) -> None:
"""Update the binary sensor."""
await super().async_update(wake_if_asleep=wake_if_asleep)

def get_value(self):
def get_value(self) -> Optional[bool]:
"""Return whether binary sensor is true."""
return self.__state

@property
def sensor_type(self):
def sensor_type(self) -> Optional[Text]:
"""Return the sensor_type for use by HA as a device_class."""
return self._sensor_type

@staticmethod
def has_battery():
def has_battery() -> bool:
"""Return whether the device has a battery."""
return False

Expand Down Expand Up @@ -84,12 +86,12 @@ def __init__(self, data: Dict, controller):
"""
super().__init__(data, controller)
self.__state = None
self.type = "parking brake sensor"
self.hass_type = "binary_sensor"
self._sensor_type = None
self.name = self._name()
self.uniq_name = self._uniq_name()
self.__state: Optional[bool] = None
self.type: Text = "parking brake sensor"
self.hass_type: Text = "binary_sensor"
self._sensor_type: Optional[Text] = None
self.name: Text = self._name()
self.uniq_name: Text = self._uniq_name()

async def async_update(self, wake_if_asleep=False, force=False) -> None:
"""Update the parking brake sensor."""
Expand All @@ -112,7 +114,7 @@ def refresh(self) -> None:
else:
self.__state = False

def get_value(self):
def get_value(self) -> Optional[bool]:
"""Return whether parking brake engaged."""
return self.__state

Expand Down Expand Up @@ -140,12 +142,12 @@ def __init__(self, data, controller):
"""
super().__init__(data, controller)
self.__state = None
self.type = "charger sensor"
self.hass_type = "binary_sensor"
self._sensor_type = None
self.name = self._name()
self.uniq_name = self._uniq_name()
self.__state: Optional[bool] = None
self.type: Text = "charger sensor"
self.hass_type: Text = "binary_sensor"
self._sensor_type: Optional[Text] = None
self.name: Text = self._name()
self.uniq_name: Text = self._uniq_name()

async def async_update(self, wake_if_asleep=False, force=False) -> None:
"""Update the charger connection sensor."""
Expand All @@ -170,7 +172,7 @@ def refresh(self) -> None:
else:
self.__state = True

def get_value(self):
def get_value(self) -> Optional[bool]:
"""Return whether the charger cable is connected."""
return self.__state

Expand All @@ -190,10 +192,10 @@ def __init__(self, data: Dict, controller) -> None:
super().__init__(data, controller)
self.__online_state: Optional[bool] = None
self.type: Text = "online sensor"
self.hass_type = "binary_sensor"
self._sensor_type = "connectivity"
self.name = self._name()
self.uniq_name = self._uniq_name()
self.hass_type: Text = "binary_sensor"
self._sensor_type: Optional[Text] = "connectivity"
self.name: Text = self._name()
self.uniq_name: Text = self._uniq_name()

async def async_update(self, wake_if_asleep=False, force=False) -> None:
"""Update the battery state."""
Expand Down Expand Up @@ -228,9 +230,9 @@ def __init__(self, data: Dict, controller) -> None:
"""
super().__init__(data, controller)
self.type: Text = "update available sensor"
self._sensor_type = None
self.name = self._name()
self.uniq_name = self._uniq_name()
self._sensor_type: Optional[Text] = None
self.name: Text = self._name()
self.uniq_name: Text = self._uniq_name()

async def async_update(self, wake_if_asleep=False, force=False) -> None:
"""Update the battery state."""
Expand Down

0 comments on commit 3272bd6

Please sign in to comment.