|
18 | 18 | callback, |
19 | 19 | ) |
20 | 20 | from homeassistant.helpers import entity_registry as er |
21 | | -from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback |
| 21 | +from homeassistant.helpers.entity_platform import ( |
| 22 | + AddConfigEntryEntitiesCallback, |
| 23 | + async_get_current_platform, |
| 24 | +) |
22 | 25 | from homeassistant.helpers.event import ( |
23 | 26 | async_call_later, |
24 | 27 | async_track_state_change_event, |
|
33 | 36 | CONF_IMMEDIATE_ON, |
34 | 37 | CONF_WASP_ID, |
35 | 38 | LOGGER, |
| 39 | + SERVICE_RESET, |
36 | 40 | ) |
37 | 41 |
|
38 | 42 |
|
@@ -64,6 +68,14 @@ async def async_setup_entry( |
64 | 68 | ] |
65 | 69 | ) |
66 | 70 |
|
| 71 | + # Register entity services |
| 72 | + platform = async_get_current_platform() |
| 73 | + platform.async_register_entity_service( |
| 74 | + SERVICE_RESET, |
| 75 | + {}, |
| 76 | + "async_reset", |
| 77 | + ) |
| 78 | + |
67 | 79 | return True |
68 | 80 |
|
69 | 81 |
|
@@ -356,3 +368,20 @@ def async_calculate_state(self) -> None: |
356 | 368 | self._motion_was_detected = motion_detected |
357 | 369 |
|
358 | 370 | self.async_write_ha_state() |
| 371 | + |
| 372 | + async def async_reset(self) -> None: |
| 373 | + """Reset the occupancy sensor to off.""" |
| 374 | + |
| 375 | + # Cancel any pending timers |
| 376 | + if self._door_closed_delay_timer is not None: |
| 377 | + self._door_closed_delay_timer() |
| 378 | + self._door_closed_delay_timer = None |
| 379 | + |
| 380 | + if self._door_open_timeout_timer is not None: |
| 381 | + self._door_open_timeout_timer() |
| 382 | + self._door_open_timeout_timer = None |
| 383 | + |
| 384 | + # Reset internal state |
| 385 | + self._motion_was_detected = False |
| 386 | + self._state = STATE_OFF |
| 387 | + self.async_write_ha_state() |
0 commit comments