-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
37 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
random_fail: | ||
name: Random fail | ||
description: A call to this service will randomly fail. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
"""Spook - Not your homey.""" | ||
import random | ||
|
||
from homeassistant.core import HomeAssistant, ServiceCall, callback | ||
from homeassistant.exceptions import HomeAssistantError | ||
from homeassistant.backports.enum import StrEnum | ||
|
||
from ..const import DOMAIN | ||
|
||
|
||
class SpookServices(StrEnum): | ||
"""Spook services.""" | ||
|
||
RANDOM_FAIL = "random_fail" | ||
|
||
|
||
@callback | ||
def async_setup_services(hass: HomeAssistant) -> None: | ||
"""Set up Spook services.""" | ||
|
||
async def _async_random_fail(_: ServiceCall) -> None: | ||
"""Randomly let this service call fail.""" | ||
if random.choice([True, False]): | ||
raise HomeAssistantError("Spooked!") | ||
|
||
hass.services.async_register( | ||
DOMAIN, | ||
SpookServices.RANDOM_FAIL, | ||
_async_random_fail, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters