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

Disable morning/evening brightness adjust #100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 10 additions & 0 deletions custom_components/circadian_lighting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,16 @@ def calc_percent(self):
_LOGGER.debug("a: " + str(a))
_LOGGER.debug("percentage: " + str(percentage))

if 'percent' in self.data:
if percentage > self.data['percent']:
self.data['direction'] = 1
elif percentage < self.data['percent']:
self.data['direction'] = -1
else:
self.data['direction'] = 0
else:
self.data['direction'] = 0

return percentage

def calc_colortemp(self):
Expand Down
2 changes: 2 additions & 0 deletions custom_components/circadian_lighting/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def __init__(self, hass, cl):
self._attributes['colortemp'] = self._cl.data['colortemp']
self._attributes['rgb_color'] = self._cl.data['rgb_color']
self._attributes['xy_color'] = self._cl.data['xy_color']
self._attributes['direction'] = self._cl.data['direction']

"""Register callbacks."""
dispatcher_connect(hass, CIRCADIAN_LIGHTING_UPDATE_TOPIC, self.update_sensor)
Expand Down Expand Up @@ -101,4 +102,5 @@ def update_sensor(self):
self._attributes['colortemp'] = self._cl.data['colortemp']
self._attributes['rgb_color'] = self._cl.data['rgb_color']
self._attributes['xy_color'] = self._cl.data['xy_color']
self._attributes['direction'] = self._cl.data['direction']
_LOGGER.debug("Circadian Lighting Sensor Updated")
18 changes: 16 additions & 2 deletions custom_components/circadian_lighting/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
CONF_LIGHTS_XY = 'lights_xy'
CONF_LIGHTS_BRIGHT = 'lights_brightness'
CONF_DISABLE_BRIGHTNESS_ADJUST = 'disable_brightness_adjust'
CONF_DISABLE_BRIGHTNESS_ADJUST_MORNING = 'disable_brightness_adjust_morning'
CONF_DISABLE_BRIGHTNESS_ADJUST_EVENING = 'disable_brightness_adjust_evening'
CONF_MIN_BRIGHT = 'min_brightness'
DEFAULT_MIN_BRIGHT = 1
CONF_MAX_BRIGHT = 'max_brightness'
Expand All @@ -61,6 +63,8 @@
vol.Optional(CONF_LIGHTS_XY): cv.entity_ids,
vol.Optional(CONF_LIGHTS_BRIGHT): cv.entity_ids,
vol.Optional(CONF_DISABLE_BRIGHTNESS_ADJUST, default=False): cv.boolean,
vol.Optional(CONF_DISABLE_BRIGHTNESS_ADJUST_MORNING, default=False): cv.boolean,
vol.Optional(CONF_DISABLE_BRIGHTNESS_ADJUST_EVENING, default=False): cv.boolean,
vol.Optional(CONF_MIN_BRIGHT, default=DEFAULT_MIN_BRIGHT):
vol.All(vol.Coerce(int), vol.Range(min=1, max=100)),
vol.Optional(CONF_MAX_BRIGHT, default=DEFAULT_MAX_BRIGHT):
Expand All @@ -86,6 +90,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
lights_xy = config.get(CONF_LIGHTS_XY)
lights_brightness = config.get(CONF_LIGHTS_BRIGHT)
disable_brightness_adjust = config.get(CONF_DISABLE_BRIGHTNESS_ADJUST)
disable_brightness_adjust_morning = config.get(CONF_DISABLE_BRIGHTNESS_ADJUST_MORNING)
disable_brightness_adjust_evening = config.get(CONF_DISABLE_BRIGHTNESS_ADJUST_EVENING)
name = config.get(CONF_NAME)
min_brightness = config.get(CONF_MIN_BRIGHT)
max_brightness = config.get(CONF_MAX_BRIGHT)
Expand All @@ -97,7 +103,8 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
disable_state = config.get(CONF_DISABLE_STATE)
initial_transition = config.get(CONF_INITIAL_TRANSITION)
cs = CircadianSwitch(hass, cl, name, lights_ct, lights_rgb, lights_xy, lights_brightness,
disable_brightness_adjust, min_brightness, max_brightness,
disable_brightness_adjust, disable_brightness_adjust_morning,
disable_brightness_adjust_evening, min_brightness, max_brightness,
sleep_entity, sleep_state, sleep_colortemp, sleep_brightness,
disable_entity, disable_state, initial_transition)
add_devices([cs])
Expand All @@ -114,7 +121,8 @@ class CircadianSwitch(SwitchEntity, RestoreEntity):
"""Representation of a Circadian Lighting switch."""

def __init__(self, hass, cl, name, lights_ct, lights_rgb, lights_xy, lights_brightness,
disable_brightness_adjust, min_brightness, max_brightness,
disable_brightness_adjust, disable_brightness_adjust_morning,
disable_brightness_adjust_evening, min_brightness, max_brightness,
sleep_entity, sleep_state, sleep_colortemp, sleep_brightness,
disable_entity, disable_state, initial_transition):
"""Initialize the Circadian Lighting switch."""
Expand All @@ -130,6 +138,8 @@ def __init__(self, hass, cl, name, lights_ct, lights_rgb, lights_xy, lights_brig
self._lights_xy = lights_xy
self._lights_brightness = lights_brightness
self._disable_brightness_adjust = disable_brightness_adjust
self._disable_brightness_adjust_morning = disable_brightness_adjust_morning
self._disable_brightness_adjust_evening = disable_brightness_adjust_evening
self._min_brightness = min_brightness
self._max_brightness = max_brightness
self._sleep_entity = sleep_entity
Expand Down Expand Up @@ -243,6 +253,10 @@ def calc_hs(self):
def calc_brightness(self):
if self._disable_brightness_adjust is True:
return None
elif self._disable_brightness_adjust_morning is True and self._cl.data['direction'] == 1:
return None
elif self._disable_brightness_adjust_evening is True and self._cl.data['direction'] == -1:
return None
else:
if self.is_sleep():
_LOGGER.debug(self._name + " in Sleep mode")
Expand Down