Skip to content

Commit

Permalink
Merge 4a85d61 into 6421aef
Browse files Browse the repository at this point in the history
  • Loading branch information
bramstroker committed Apr 19, 2024
2 parents 6421aef + 4a85d61 commit 73662ae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions custom_components/powercalc/strategy/playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import homeassistant.helpers.config_validation as cv
import voluptuous as vol
from homeassistant.const import STATE_OFF
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, State, callback
from homeassistant.helpers.event import async_track_point_in_time
from homeassistant.helpers.typing import ConfigType
Expand Down Expand Up @@ -186,6 +187,9 @@ async def _load_playbook(self, playbook_id: str) -> Playbook:

return self._loaded_playbooks[playbook_id]

def can_calculate_standby(self) -> bool:
return bool(self._states_trigger and STATE_OFF in self._states_trigger)


class PlaybookQueue:
def __init__(self, items: list[PlaybookEntry]) -> None:
Expand Down
7 changes: 7 additions & 0 deletions tests/strategy/test_playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,12 @@ async def test_state_trigger(hass: HomeAssistant) -> None:
CONF_NAME: "Test",
CONF_PLAYBOOK: {
CONF_PLAYBOOKS: {
"off": "states_mapping/off.csv",
"idle": "states_mapping/idle.csv",
"paused": "states_mapping/paused.csv",
},
CONF_STATE_TRIGGER: {
STATE_OFF: "off",
STATE_IDLE: "idle",
STATE_PAUSED: "paused",
},
Expand All @@ -334,6 +336,11 @@ async def test_state_trigger(hass: HomeAssistant) -> None:

await elapse_and_assert_power(hass, 2, "5.00")

hass.states.async_set("media_player.sonos", STATE_OFF)
await hass.async_block_till_done()

await elapse_and_assert_power(hass, 1, "0.10")


async def elapse_and_assert_power(
hass: HomeAssistant,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1,0.1
2,0.2
3,0.3

0 comments on commit 73662ae

Please sign in to comment.