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:
parent
492ef81069
commit
a4f7b7d784
3 changed files with 13 additions and 9 deletions
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue