fix: when motion goes idle, also clear region

pull/106/head
Jeff Culverhouse 3 months ago
parent 24d87d63ac
commit ec3f096246

@ -34,19 +34,25 @@ class EventsMixin:
# if one of our known sensors # if one of our known sensors
if event in ["motion", "human", "doorbell", "recording", "privacy_mode"]: if event in ["motion", "human", "doorbell", "recording", "privacy_mode"]:
if event == "recording" and payload["file"].endswith(".jpg"): if event == "recording":
image = self.get_recorded_file(device_id, payload["file"]) if payload["file"].endswith(".jpg"):
if image: image = self.get_recorded_file(device_id, payload["file"])
self.upsert_state(device_id, camera={"eventshot": image}, sensor={"event_time": datetime.now(timezone.utc).isoformat()}) if image:
self.upsert_state(
device_id,
camera={"eventshot": image},
sensor={"event_time": datetime.now(timezone.utc).isoformat()},
)
else: else:
# only log details if not a recording self.logger.info(f"Got event for {self.get_device_name(device_id)}: {event} - {payload}")
if event != "recording":
self.logger.info(f"Got event for {self.get_device_name(device_id)}: {event} - {payload}")
if event == "motion": if event == "motion":
self.upsert_state( self.upsert_state(
device_id, device_id,
binary_sensor={"motion": payload["state"]}, binary_sensor={"motion": payload["state"]},
sensor={"motion_region": payload["region"], "event_time": datetime.now(timezone.utc).isoformat()}, sensor={
"motion_region": payload["region"] if payload["state"] != "off" else "",
"event_time": datetime.now(timezone.utc).isoformat(),
},
) )
else: else:
self.upsert_state(device_id, sensor={event: payload}) self.upsert_state(device_id, sensor={event: payload})

Loading…
Cancel
Save