Skip to content

Commit

Permalink
add custom disable states, idea by @thundergreen
Browse files Browse the repository at this point in the history
  • Loading branch information
benleb committed Aug 11, 2020
1 parent 5c2fb27 commit c854581
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ key | optional | type | default | description
`module` | False | string | automoli | The module name of the app.
`class` | False | string | AutoMoLi | The name of the Class.
`room` | False | string | | The "room" used to find matching sensors/light
~~`disable_switch_entity`~~ | ~~True~~ | ~~string~~ | | **replaced by `disable_switch_entities`**
`disable_switch_entities` | True | list/string | | One or more Home Assistant Entities as switch for AutoMoLi. If the state of **any** entity is *off*, AutoMoLi is *deactivated*. (Use an *input_boolean* for example)
`disable_switch_states` | True | list/string | ["off"] | Custom states for `disable_switch_entities`. If the state of **any** entity is *in this list*, AutoMoLi is *deactivated*. Can be used to disable with `media_players` in `playing` state for example.
`disable_hue_groups` | False | boolean | | Disable the use of Hue Groups/Scenes
`delay` | True | integer | 150 | Seconds without motion until lights will switched off. Can be disabled (lights stay always on) with `0`
~~`motion_event`~~ | ~~True~~ | ~~string~~ | | **replaced by `motion_state_on/off`**
Expand Down
5 changes: 4 additions & 1 deletion apps/automoli/automoli.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ async def initialize(self) -> None:

# on/off switch via input.boolean
self.disable_switch_entities: Set[str] = self.listr(self.args.pop("disable_switch_entities", set()))
self.disable_switch_states: Set[str] = self.listr(self.args.pop("disable_switch_states", set(["off"])))

self.disable_hue_groups: bool = self.args.pop("disable_hue_groups", False)

# eol of the old option name
Expand Down Expand Up @@ -224,6 +226,7 @@ async def initialize(self) -> None:

if self.disable_switch_entities:
self.args.update({"disable_switch_entities": self.disable_switch_entities})
self.args.update({"disable_switch_states": self.disable_switch_states})

# show parsed config
self.show_info(self.args)
Expand Down Expand Up @@ -316,7 +319,7 @@ async def refresh_timer(self) -> None:
async def is_disabled(self) -> bool:
"""check if automoli is disabled via home assistant entity"""
for entity in self.disable_switch_entities:
if (state := await self.get_state(entity, copy=False)) and state == "off":
if (state := await self.get_state(entity, copy=False)) and state in self.disable_switch_states:
self.lg(f"{APP_NAME} disabled by {entity}",)
return True

Expand Down

0 comments on commit c854581

Please sign in to comment.