Skip to content

Commit

Permalink
feat: Add possibility to manually enable blocked state
Browse files Browse the repository at this point in the history
Add possibility to manually enable blocked state
  • Loading branch information
danobot authored Nov 8, 2022
2 parents 9ebff7d + 8e919f9 commit 6c6d827
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions custom_components/entity_controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,9 @@ async def async_setup(hass, config):
# When block is disabled, "control" will reset the active timer
machine.add_transition(trigger="control", source="active_timer",
dest=None, after="_reset_timer", conditions=["is_state_entities_on"], unless="is_block_enabled")
# Manually enable blocked state
machine.add_transition(trigger="block_enable", source="active_timer",
dest="blocked", conditions=["is_state_entities_on", "is_block_enabled"])

# machine.add_transition(trigger='sensor_off', source='active_stay_on', dest=None)
# machine.add_transition(trigger="timer_expires", source="active_stay_on", dest=None)
Expand Down Expand Up @@ -378,6 +381,7 @@ class EntityController(entity.Entity):
from .entity_services import (
async_entity_service_activate as async_activate,
async_entity_service_clear_block as async_clear_block,
async_entity_service_enable_block as async_enable_block,
async_entity_service_enable_stay_mode as async_enable_stay_mode,
async_entity_service_disable_stay_mode as async_disable_stay_mode,
async_entity_service_set_night_mode as async_set_night_mode,
Expand Down
1 change: 1 addition & 0 deletions custom_components/entity_controller/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# services
SERVICE_ACTIVATE = "activate"
SERVICE_CLEAR_BLOCK = "clear_block"
SERVICE_ENABLE_BLOCK = "enable_block"
SERVICE_ENABLE_STAY_MODE = "enable_stay_mode"
SERVICE_DISABLE_STAY_MODE = "disable_stay_mode"
SERVICE_SET_NIGHT_MODE = "set_night_mode"
Expand Down
11 changes: 11 additions & 0 deletions custom_components/entity_controller/entity_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
from .const import (
SERVICE_ACTIVATE,
SERVICE_CLEAR_BLOCK,
SERVICE_ENABLE_BLOCK,
SERVICE_ENABLE_STAY_MODE,
SERVICE_DISABLE_STAY_MODE,
SERVICE_SET_NIGHT_MODE,
Expand All @@ -51,6 +52,7 @@ def async_setup_entity_services(component: EntityComponent):
component.logger.debug("Setting up entity services")
component.async_register_entity_service(SERVICE_ACTIVATE, {}, "async_activate")
component.async_register_entity_service(SERVICE_CLEAR_BLOCK, {}, "async_clear_block")
component.async_register_entity_service(SERVICE_ENABLE_BLOCK, {}, "async_enable_block")
component.async_register_entity_service(SERVICE_ENABLE_STAY_MODE, {}, "async_enable_stay_mode")
component.async_register_entity_service(SERVICE_DISABLE_STAY_MODE, {}, "async_disable_stay_mode")
component.async_register_entity_service(
Expand Down Expand Up @@ -78,6 +80,15 @@ def async_entity_service_clear_block(self):
self.model.log.debug("Clearing Blocked state")
self.model.block_timer_expires()

def async_entity_service_enable_block(self):
""" Enable the block property, if timer is active"""

if(self.model is None or self.model.state != 'active_timer'):
return

self.model.log.debug("Enabling Blocked state")
self.model.block_enable()

def async_entity_service_enable_stay_mode(self):
self.model.log.debug("Enable stay mode - Control entities will remain on until manually turned off")
self.model.stay = True
Expand Down
7 changes: 7 additions & 0 deletions custom_components/entity_controller/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ clear_block:
description: Name(s) of entities to change.
example: 'entity_controller.motion_light'

enable_block:
description: Enables the blocked state of an Entity Controller, if timer is active
fields:
entity_id:
description: Name(s) of entities to change.
example: 'entity_controller.motion_light'

set_stay_on:
description: Change the stay to on
fields:
Expand Down

0 comments on commit 6c6d827

Please sign in to comment.