Remove redundant property definitions in Notion (#52367)
* Remove redundant property definitions in Notion * Code review
This commit is contained in:
parent
2868fef7d4
commit
60ea219101
3 changed files with 38 additions and 83 deletions
|
@ -77,24 +77,19 @@ 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"]
|
||||
state = task["status"]["value"]
|
||||
elif task["status"].get("insights", {}).get("primary"):
|
||||
self._state = task["status"]["insights"]["primary"]["to_state"]
|
||||
state = task["status"]["insights"]["primary"]["to_state"]
|
||||
else:
|
||||
LOGGER.warning("Unknown data payload: %s", task["status"])
|
||||
self._state = None
|
||||
|
||||
@property
|
||||
def is_on(self) -> bool:
|
||||
"""Return whether the sensor is on or off."""
|
||||
task = self.coordinator.data["tasks"][self.task_id]
|
||||
state = None
|
||||
|
||||
if task["task_type"] == SENSOR_BATTERY:
|
||||
return self._state == "critical"
|
||||
if task["task_type"] in (
|
||||
self._attr_is_on = state == "critical"
|
||||
elif task["task_type"] in (
|
||||
SENSOR_DOOR,
|
||||
SENSOR_GARAGE_DOOR,
|
||||
SENSOR_SAFE,
|
||||
|
@ -102,10 +97,10 @@ class NotionBinarySensor(NotionEntity, BinarySensorEntity):
|
|||
SENSOR_WINDOW_HINGED_HORIZONTAL,
|
||||
SENSOR_WINDOW_HINGED_VERTICAL,
|
||||
):
|
||||
return self._state != "closed"
|
||||
if task["task_type"] == SENSOR_LEAK:
|
||||
return self._state != "no_leak"
|
||||
if task["task_type"] == SENSOR_MISSING:
|
||||
return self._state == "not_missing"
|
||||
if task["task_type"] == SENSOR_SMOKE_CO:
|
||||
return self._state != "no_alarm"
|
||||
self._attr_is_on = state != "closed"
|
||||
elif task["task_type"] == SENSOR_LEAK:
|
||||
self._attr_is_on = state != "no_leak"
|
||||
elif task["task_type"] == SENSOR_MISSING:
|
||||
self._attr_is_on = state == "not_missing"
|
||||
elif task["task_type"] == SENSOR_SMOKE_CO:
|
||||
self._attr_is_on = state != "no_alarm"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue