Fix bug related to possibly missing task ID in Notion API data (#43330)

* Fix bug related to possibly missing task ID in Notion API data

* Calculate unique ID once

* Code review

* Simplify

* Code review
This commit is contained in:
Aaron Bach 2020-11-22 20:15:38 -07:00 committed by GitHub
parent 492ef81069
commit a4f7b7d784
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 9 deletions

View file

@ -77,7 +77,7 @@ class NotionBinarySensor(NotionEntity, BinarySensorEntity):
@callback
def _async_update_from_latest_data(self) -> None:
"""Fetch new state data for the sensor."""
task = self.coordinator.data["tasks"][self._task_id]
task = self.coordinator.data["tasks"][self.task_id]
if "value" in task["status"]:
self._state = task["status"]["value"]
@ -87,7 +87,7 @@ class NotionBinarySensor(NotionEntity, BinarySensorEntity):
@property
def is_on(self) -> bool:
"""Return whether the sensor is on or off."""
task = self.coordinator.data["tasks"][self._task_id]
task = self.coordinator.data["tasks"][self.task_id]
if task["task_type"] == SENSOR_BATTERY:
return self._state == "critical"