Skip to content

Commit

Permalink
Merge pull request #278 from danobot/develop
Browse files Browse the repository at this point in the history
feat: added 'disable_block' option for users who always want their en…
  • Loading branch information
danobot authored Jul 16, 2022
2 parents f69e5d7 + b78f0ab commit 6c9b83b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:
head: develop
- uses: actions/checkout@v1
- name: Push to master
uses: ad-m/github-push-action@v0.5.0
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- name: Merge back to develop
uses: ad-m/github-push-action@v0.5.0
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: develop
Expand Down
31 changes: 24 additions & 7 deletions custom_components/entity_controller/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
CONF_STATE_ENTITIES,
CONF_DELAY,
CONF_BLOCK_TIMEOUT,
CONF_DISABLE_BLOCK,
CONF_SENSOR_TYPE_DURATION,
CONF_SENSOR_TYPE,
CONF_SENSOR_RESETS_TIMER,
Expand Down Expand Up @@ -145,6 +146,7 @@
vol.Optional(CONF_TRIGGER_ON_DEACTIVATE, default=None): cv.entity_ids,
vol.Optional(CONF_STATE_ENTITIES, default=[]): cv.entity_ids,
vol.Optional(CONF_BLOCK_TIMEOUT, default=None): cv.positive_int,
vol.Optional(CONF_DISABLE_BLOCK, default=False): cv.boolean,
# vol.Optional(CONF_IGNORE_STATE_CHANGES_UNTIL, default=None): cv.positive_int,
vol.Optional(CONF_NIGHT_MODE, default=None): MODE_SCHEMA,
vol.Optional(CONF_STATE_ATTRIBUTES_IGNORE, default=[]): cv.ensure_list,
Expand Down Expand Up @@ -213,15 +215,22 @@ async def async_setup(hass, config):
machine.add_transition(
trigger="sensor_on",
source="idle",
dest="blocked",
dest="active",
conditions=["is_state_entities_on"],
unless="is_block_enabled"
)
machine.add_transition(
trigger="sensor_on",
source="idle",
dest="blocked",
conditions=["is_state_entities_on", "is_block_enabled"],
)
machine.add_transition(trigger="enable", source="idle", dest=None, conditions=["is_state_entities_off"])

# Blocked
machine.add_transition(trigger="enable", source="blocked", dest="idle", conditions=["is_state_entities_off"])
machine.add_transition(
trigger="sensor_on", source="blocked", dest="blocked"
trigger="sensor_on", source="blocked", dest="blocked", conditions=["is_block_enabled"]
) # re-entering self-transition (on_enter callback executed.)

# Overridden
Expand Down Expand Up @@ -252,7 +261,6 @@ async def async_setup(hass, config):
conditions=["is_state_entities_on", "is_duration_sensor", "is_sensor_off"],
)


machine.add_transition(
trigger="enter", source="active", dest="active_timer", unless="will_stay_on"
)
Expand Down Expand Up @@ -315,8 +323,11 @@ async def async_setup(hass, config):
dest="idle",
conditions=["is_state_entities_off"]
)
machine.add_transition(trigger='control', source='active_timer',
dest='blocked', conditions=['is_state_entities_on'])
machine.add_transition(trigger="control", source="active_timer",
dest="blocked", conditions=["is_state_entities_on", "is_block_enabled"])
# 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")

# 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 All @@ -340,7 +351,7 @@ async def async_setup(hass, config):
conditions=["is_override_state_on"],
)
# Enter blocked state when component is enabled and entity is on
machine.add_transition(trigger="blocked", source="constrained", dest="blocked")
machine.add_transition(trigger="blocked", source="constrained", dest="blocked", conditions=["is_block_enabled"])

for myconfig in config[DOMAIN]:
_LOGGER.info("Domain Configuration: " + str(myconfig))
Expand Down Expand Up @@ -802,6 +813,9 @@ def is_state_entities_off(self):
def is_state_entities_on(self):
return self._state_entity_state() is not None

def is_block_enabled(self):
return self.disable_block is False

def will_stay_on(self):
return self.stay

Expand Down Expand Up @@ -1128,6 +1142,7 @@ def config_other(self, config):
self.config[CONF_SENSOR_RESETS_TIMER] = config.get(CONF_SENSOR_RESETS_TIMER)

self.block_timeout = config.get(CONF_BLOCK_TIMEOUT, None)
self.disable_block = config.get(CONF_DISABLE_BLOCK, False)
self.image_prefix = config.get("image_prefix", "/fsm_diagram_")
self.image_path = config.get("image_path", "/conf/temp")
self.backoff = config.get("backoff", False)
Expand Down Expand Up @@ -1202,9 +1217,11 @@ def start_time_callback(self, evt):

self.update(start_time=parsed_start)

if self.is_state_entities_on():
if self.is_state_entities_on() and self.is_block_enabled():
self.blocked()
else:
# If the entity is on and block is disabled, we just transition from constrained
# to idle and leave the entity on. (Don't start a timer to turn it off.)
self.enable()
self.do_transition_behaviour(CONF_ON_EXIT_CONSTRAINED)

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 @@ -69,6 +69,7 @@
CONF_STATE_ENTITIES = "state_entities"
CONF_DELAY = "delay"
CONF_BLOCK_TIMEOUT = "block_timeout"
CONF_DISABLE_BLOCK = "disable_block"
CONF_SENSOR_TYPE_DURATION = "sensor_type_duration"
CONF_SENSOR_TYPE = "sensor_type"
CONF_SENSOR_RESETS_TIMER = "sensor_resets_timer"
Expand Down

0 comments on commit 6c9b83b

Please sign in to comment.