Skip to content

Commit 38156e2

Browse files
Merge pull request #15 from andrew-codechimp/reset-action
Reset action
2 parents 3373f88 + 022ffff commit 38156e2

6 files changed

Lines changed: 57 additions & 1 deletion

File tree

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ Control when the helper transitions to "occupied":
4343
- **On** - Helper becomes occupied immediately when the door is opened or motion is detected (good for lighting automation)
4444
- **Off** - Helper becomes occupied after the door closes, motion is detected, and the delay period expires (good for fan automation)
4545

46+
**Reset action**
47+
A reset action is provided that will set the state to unoccupied and cancel any timers.
48+
4649

4750
_Please :star: this repo if you find it useful_
4851

@@ -100,6 +103,8 @@ for:
100103

101104
- For advanced automations the state of the motion and door sensors are exposed as attributes within the binary sensor.
102105

106+
- A reset action is provided if you wish to reset the Wasp in a Box sensor to unoccupied.
107+
103108
---
104109

105110
[commits-shield]: https://img.shields.io/github/commit-activity/y/andrew-codechimp/HA-Wasp-In-A-Box.svg?style=for-the-badge

custom_components/wasp_in_a_box/binary_sensor.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
callback,
1919
)
2020
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+
)
2225
from homeassistant.helpers.event import (
2326
async_call_later,
2427
async_track_state_change_event,
@@ -33,6 +36,7 @@
3336
CONF_IMMEDIATE_ON,
3437
CONF_WASP_ID,
3538
LOGGER,
39+
SERVICE_RESET,
3640
)
3741

3842

@@ -64,6 +68,14 @@ async def async_setup_entry(
6468
]
6569
)
6670

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+
6779
return True
6880

6981

@@ -356,3 +368,20 @@ def async_calculate_state(self) -> None:
356368
self._motion_was_detected = motion_detected
357369

358370
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()

custom_components/wasp_in_a_box/const.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@
2424

2525
ATTR_MOTION_SENSOR_STATE = "motion_sensor_state"
2626
ATTR_DOOR_SENSOR_STATE = "door_sensor_state"
27+
SERVICE_RESET = "reset"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"services": {
3+
"reset": {
4+
"service": "mdi:refresh"
5+
}
6+
}
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Services for Wasp in a Box integration
2+
reset:
3+
name: Reset
4+
description: Reset the occupancy sensor to off and clear any pending timers.
5+
target:
6+
entity:
7+
integration: wasp_in_a_box
8+
domain: binary_sensor

custom_components/wasp_in_a_box/translations/en.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,11 @@
6565
}
6666
}
6767
}
68+
},
69+
"services": {
70+
"reset": {
71+
"name": "Reset",
72+
"description": "Reset the occupancy sensor to off and clear any pending timers."
73+
}
6874
}
6975
}

0 commit comments

Comments
 (0)