Skip to content

Commit

Permalink
fix #50 setting a humidity_threshold prevented switching of the lights
Browse files Browse the repository at this point in the history
  • Loading branch information
benleb committed Aug 12, 2020
1 parent c5cab7b commit 2304de2
Showing 1 changed file with 20 additions and 21 deletions.
41 changes: 20 additions & 21 deletions apps/automoli/automoli.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ async def lights_off(self, kwargs: Dict[str, Any]) -> None:
for sensor in self.sensors["humidity"]:
try:
current_humidity = float(await self.get_state(sensor))
except ValueError:
except ValueError as error:
self.lg(f"self.get_state(sensor) raised a ValueError: {error}", level="ERROR")
continue

if current_humidity >= humidity_threshold:
Expand All @@ -425,30 +426,28 @@ async def lights_off(self, kwargs: Dict[str, Any]) -> None:
)
return

else:
# cancel scheduled callbacks
await self.clear_handles(deepcopy(self.handles))

# cancel scheduled callbacks
await self.clear_handles(deepcopy(self.handles))
if any([await self.get_state(entity) == "on" for entity in self.lights]):
for entity in self.lights:
await self.call_service("homeassistant/turn_off", entity_id=entity)
self.lg(
f"no motion in {hl(self.room.capitalize())} since "
f"{hl(self.active['delay'])}sec → turned {hl(f'off')}",
icon=OFF_ICON,
)

if any([await self.get_state(entity) == "on" for entity in self.lights]):
for entity in self.lights:
await self.call_service("homeassistant/turn_off", entity_id=entity)
self.lg(
f"no motion in {hl(self.room.capitalize())} since "
f"{hl(self.active['delay'])}sec → turned {hl(f'off')}",
icon=OFF_ICON,
# experimental | reset for xiaomi "super motion" sensors | idea from @wernerhp
# app: https://github.com/wernerhp/appdaemon_aqara_motion_sensors
# mod: https://community.smartthings.com/t/making-xiaomi-motion-sensor-a-super-motion-sensor/139806
for sensor in self.sensors["motion"]:
await self.set_state(
sensor,
state="off",
attributes=(await self.get_state(sensor, attribute="all")).get("attributes", {}),
)

# experimental | reset for xiaomi "super motion" sensors | idea from @wernerhp
# app: https://github.com/wernerhp/appdaemon_aqara_motion_sensors
# mod: https://community.smartthings.com/t/making-xiaomi-motion-sensor-a-super-motion-sensor/139806
for sensor in self.sensors["motion"]:
await self.set_state(
sensor,
state="off",
attributes=(await self.get_state(sensor, attribute="all")).get("attributes", {}),
)

async def find_sensors(self, keyword: str) -> List[str]:
"""Find sensors by looking for a keyword in the friendly_name."""
return [
Expand Down

0 comments on commit 2304de2

Please sign in to comment.