Fix incorrect Notion battery state calculation (#43108)

* Fix incorrect Notion battery state calculation

* Both cases
This commit is contained in:
Aaron Bach 2020-11-12 10:47:47 -07:00 committed by GitHub
parent 7b7bb0a15f
commit 7921be1b5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,14 +79,10 @@ class NotionBinarySensor(NotionEntity, BinarySensorEntity):
"""Fetch new state data for the sensor."""
task = self.coordinator.data["tasks"][self._task_id]
if task["task_type"] == SENSOR_BATTERY:
self._state = self.coordinator.data["tasks"][self._task_id]["status"][
"data"
]["to_state"]
else:
self._state = self.coordinator.data["tasks"][self._task_id]["status"][
"value"
]
if "value" in task["status"]:
self._state = task["status"]["value"]
elif task["task_type"] == SENSOR_BATTERY:
self._state = task["status"]["data"]["to_state"]
@property
def is_on(self) -> bool:
@ -94,7 +90,7 @@ class NotionBinarySensor(NotionEntity, BinarySensorEntity):
task = self.coordinator.data["tasks"][self._task_id]
if task["task_type"] == SENSOR_BATTERY:
return self._state != "critical"
return self._state == "critical"
if task["task_type"] in (
SENSOR_DOOR,
SENSOR_GARAGE_DOOR,