Skip to content

Commit

Permalink
fix #46, disabled_entities wrongly parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
benleb committed Aug 3, 2020
1 parent 18a1dc5 commit d5b7a35
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions apps/automoli/automoli.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ async def initialize(self) -> None:
}

# on/off switch via input.boolean
self.disable_switch_entities: Set[str] = self.args.get("disable_switch_entities", set())
self.disable_switch_entities: Set[str] = set()
if disable_switch_entities := self.args.get("disable_switch_entities"):
if isinstance(disable_switch_entities, str):
disable_switch_entities = [disable_switch_entities]
self.disable_switch_entities = set(disable_switch_entities)

# stay compatible to the old setting
if disable_switch_entity := self.args.get("disable_switch_entity"):
self.disable_switch_entities.add(disable_switch_entity)
Expand Down Expand Up @@ -165,7 +170,7 @@ async def initialize(self) -> None:

await self.refresh_timer()

self.args.update({"lights": self.lights, "sensors": self.sensors, "room": self.room.capitalize()})
self.args.update({"lights": self.lights, "sensors": self.sensors, "room": self.room.capitalize(), "disable_switch_entities": self.disable_switch_entities})

# show parsed config
self.show_info(self.args)
Expand Down Expand Up @@ -202,14 +207,14 @@ async def motion_cleared(self, entity: str, attribute: str, old: str, new: str,
await self.refresh_timer()
else:
# cancel scheduled callbacks
_ = [await self.cancel_timer(handle) for handle in self.handles]
_ = [await self.cancel_timer(handle) for handle in self.handles.copy()]
self.handles.clear()

async def motion_detected(self, entity: str, attribute: str, old: str, new: str, kwargs: Dict[str, Any]) -> None:
# wrapper function

# cancel scheduled callbacks
_ = [await self.cancel_timer(handle) for handle in self.handles]
_ = [await self.cancel_timer(handle) for handle in self.handles.copy()]
self.handles.clear()

# calling motion event handler
Expand Down Expand Up @@ -241,7 +246,7 @@ async def refresh_timer(self) -> Optional[Set[str]]:
"""Refresh delay timer."""

# cancel scheduled callbacks
_ = [await self.cancel_timer(handle) for handle in self.handles]
_ = [await self.cancel_timer(handle) for handle in self.handles.copy()]
self.handles.clear()

if self.active["delay"] != 0:
Expand Down Expand Up @@ -355,7 +360,7 @@ async def lights_off(self, kwargs: Dict[str, Any]) -> None:
f"{hl(self.thresholds['humidity'])}%RH"
)
else:
_ = [await self.cancel_timer(handle) for handle in self.handles]
_ = [await self.cancel_timer(handle) for handle in self.handles.copy()]
self.handles.clear()

if any([await self.get_state(entity) == "on" for entity in self.lights]):
Expand Down

0 comments on commit d5b7a35

Please sign in to comment.