Skip to content

Commit

Permalink
feat: add state attributes for binary sensors
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Jan 25, 2020
1 parent b2e74d1 commit 46e89be
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions teslajsonpy/binary_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,16 @@ def __init__(self, data: Dict, controller):

self.uniq_name = self._uniq_name()
self.bin_type = 0x1
self.attrs: Dict[Text, Text] = {}

async def async_update(self):
"""Update the parking brake sensor."""
await super().async_update()
data = self._controller.get_drive_params(self._id)
if data:
self.attrs["shift_state"] = (
data["shift_state"] if data["shift_state"] else "P"
)
if not data["shift_state"] or data["shift_state"] == "P":
self.__state = True
else:
Expand Down Expand Up @@ -96,12 +100,14 @@ def __init__(self, data, controller):

self.uniq_name = self._uniq_name()
self.bin_type = 0x2
self.attrs: Dict[Text, Text] = {}

async def async_update(self):
"""Update the charger connection sensor."""
await super().async_update()
data = self._controller.get_charging_params(self._id)
if data:
self.attrs["charging_state"] = data["charging_state"]
if data["charging_state"] in ["Disconnected"]:
self.__state = False
else:
Expand Down

0 comments on commit 46e89be

Please sign in to comment.