Extracted some functions and fixed reference
This commit is contained in:
parent
63f7484a4a
commit
b46b0d9a07
1 changed files with 30 additions and 11 deletions
|
@ -64,8 +64,7 @@ def count_change(change: int) -> None:
|
||||||
global motion_triggered_lights
|
global motion_triggered_lights
|
||||||
|
|
||||||
# Are lights on at the moment?
|
# Are lights on at the moment?
|
||||||
previous_lights_state = hue.get_group(hue_conf['light_group'])[
|
previous_lights_state = get_light_state()
|
||||||
'state']['any_on']
|
|
||||||
|
|
||||||
# Apply correction
|
# Apply correction
|
||||||
if peopleCount <= 0 and previous_lights_state and not motion_triggered_lights:
|
if peopleCount <= 0 and previous_lights_state and not motion_triggered_lights:
|
||||||
|
@ -89,11 +88,10 @@ def count_change(change: int) -> None:
|
||||||
if previous_lights_state == target_light_state:
|
if previous_lights_state == target_light_state:
|
||||||
if previous_lights_state:
|
if previous_lights_state:
|
||||||
# Signaling that the people count is taking control over the light now
|
# Signaling that the people count is taking control over the light now
|
||||||
motion_triggered = False
|
motion_triggered_lights = False
|
||||||
return
|
return
|
||||||
|
|
||||||
hue.set_group(hue_conf['light_group'], {'on': target_light_state})
|
set_light_state(target_light_state)
|
||||||
logging.debug(f'Light state changed to {target_light_state}')
|
|
||||||
|
|
||||||
|
|
||||||
def trigger_change(triggerState: Dict):
|
def trigger_change(triggerState: Dict):
|
||||||
|
@ -121,19 +119,40 @@ def trigger_change(triggerState: Dict):
|
||||||
if target_light_state == motion_triggered_lights:
|
if target_light_state == motion_triggered_lights:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
set_light_state(target_light_state)
|
||||||
|
|
||||||
|
# Save state
|
||||||
|
motion_triggered_lights = target_light_state
|
||||||
|
|
||||||
|
|
||||||
|
def set_light_state(target_light_state: bool) -> bool:
|
||||||
|
"""Sets the lights to the given state.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
target_light_state (bool): Should lights on the inside be on or off.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
bool: Previous light state.
|
||||||
|
"""
|
||||||
# Are lights on at the moment?
|
# Are lights on at the moment?
|
||||||
previous_lights_state = hue.get_group(hue_conf['light_group'])[
|
previous_lights_state = get_light_state()
|
||||||
'state']['any_on']
|
|
||||||
if target_light_state == previous_lights_state:
|
if target_light_state == previous_lights_state:
|
||||||
return
|
return previous_lights_state
|
||||||
|
|
||||||
# Adjust light as necessary
|
# Adjust light as necessary
|
||||||
hue.set_group(hue_conf['light_group'], {'on': target_light_state})
|
hue.set_group(hue_conf['light_group'], {'on': target_light_state})
|
||||||
logging.debug(
|
logging.debug(
|
||||||
f'Light state changed to {target_light_state} for early light')
|
f'Light state changed to {target_light_state} for early light')
|
||||||
|
|
||||||
# Save state
|
return previous_lights_state
|
||||||
motion_triggered_lights = target_light_state
|
|
||||||
|
|
||||||
|
def get_light_state() -> bool:
|
||||||
|
"""
|
||||||
|
Returns:
|
||||||
|
bool: Current light state.
|
||||||
|
"""
|
||||||
|
return hue.get_group(hue_conf['light_group'])['state']['any_on']
|
||||||
|
|
||||||
|
|
||||||
# Represents callback trigger order
|
# Represents callback trigger order
|
||||||
|
|
Loading…
Reference in a new issue