Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where light doesn't turn off after crossing light threshold #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 39 additions & 27 deletions apps/automoli/automoli.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,11 @@ async def motion_event(
if await self.is_disabled():
return

# If light already on we need to check if we have crossed the illuminance
# threshhold here so we don't reset the timer
if await self.is_too_bright():
return

# turn on the lights if not already
if self.dimming or not any(
[await self.get_state(light) == "on" for light in self.lights]
Expand Down Expand Up @@ -722,6 +727,38 @@ async def is_blocked(self) -> bool:

return False

async def is_too_bright(self) -> bool:

if illuminance_threshold := self.thresholds.get(EntityType.ILLUMINANCE.idx):

# the "eco mode" check
for sensor in self.sensors[EntityType.ILLUMINANCE.idx]:
self.lg(
f"{stack()[0][3]}: {self.thresholds.get(EntityType.ILLUMINANCE.idx) = } | "
f"{float(await self.get_state(sensor)) = }", # type:ignore
level=logging.DEBUG,
)
try:
if (
illuminance := float(
await self.get_state(sensor) # type:ignore
) # type:ignore
) >= illuminance_threshold:
self.lg(
f"According to {hl(sensor)} its already bright enough ¯\\_(ツ)_/¯"
f" | {illuminance} >= {illuminance_threshold}"
)
return True

except ValueError as error:
self.lg(
f"could not parse illuminance '{await self.get_state(sensor)}' "
f"from '{sensor}': {error}"
)
return False
return False


async def dim_lights(self, _: Any) -> None:

message: str = ""
Expand Down Expand Up @@ -828,33 +865,8 @@ async def lights_on(self, force: bool = False) -> None:

force = bool(force or self.dimming)

if illuminance_threshold := self.thresholds.get(EntityType.ILLUMINANCE.idx):

# the "eco mode" check
for sensor in self.sensors[EntityType.ILLUMINANCE.idx]:
self.lg(
f"{stack()[0][3]}: {self.thresholds.get(EntityType.ILLUMINANCE.idx) = } | "
f"{float(await self.get_state(sensor)) = }", # type:ignore
level=logging.DEBUG,
)
try:
if (
illuminance := float(
await self.get_state(sensor) # type:ignore
) # type:ignore
) >= illuminance_threshold:
self.lg(
f"According to {hl(sensor)} its already bright enough ¯\\_(ツ)_/¯"
f" | {illuminance} >= {illuminance_threshold}"
)
return

except ValueError as error:
self.lg(
f"could not parse illuminance '{await self.get_state(sensor)}' "
f"from '{sensor}': {error}"
)
return
if await self.is_too_bright():
return

light_setting = (
self.active.get("light_setting")
Expand Down