Skip to content

Commit

Permalink
feat(light_controller): add support for white_value attribute
Browse files Browse the repository at this point in the history
related to #93
  • Loading branch information
xaviml committed Jun 27, 2020
1 parent 2781552 commit 41576b2
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 46 deletions.
8 changes: 8 additions & 0 deletions apps/controllerx/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ class Light:
TOGGLE = "toggle"
RELEASE = "release"
ON_FULL_BRIGHTNESS = "on_full_brightness"
ON_FULL_WHITE_VALUE = "on_full_white_value"
ON_FULL_COLOR_TEMP = "on_full_color_temp"
ON_MIN_BRIGHTNESS = "on_min_brightness"
ON_MIN_WHITE_VALUE = "on_min_white_value"
ON_MIN_COLOR_TEMP = "on_min_color_temp"
SET_HALF_BRIGHTNESS = "set_half_brightness"
SET_HALF_WHITE_VALUE = "set_half_white_value"
SET_HALF_COLOR_TEMP = "set_half_color_temp"
SYNC = "sync"
CLICK_BRIGHTNESS_UP = "click_brightness_up"
CLICK_BRIGHTNESS_DOWN = "click_brightness_down"
CLICK_WHITE_VALUE_UP = "click_white_value_up"
CLICK_WHITE_VALUE_DOWN = "click_white_value_down"
CLICK_COLOR_UP = "click_color_up"
CLICK_COLOR_DOWN = "click_color_down"
CLICK_COLOR_TEMP_UP = "click_colortemp_up"
Expand All @@ -29,6 +34,9 @@ class Light:
HOLD_BRIGHTNESS_UP = "hold_brightness_up"
HOLD_BRIGHTNESS_DOWN = "hold_brightness_down"
HOLD_BRIGHTNESS_TOGGLE = "hold_brightness_toggle"
HOLD_WHITE_VALUE_UP = "hold_white_value_up"
HOLD_WHITE_VALUE_DOWN = "hold_white_value_down"
HOLD_WHITE_VALUE_TOGGLE = "hold_white_value_toggle"
HOLD_COLOR_UP = "hold_color_up"
HOLD_COLOR_DOWN = "hold_color_down"
HOLD_COLOR_TOGGLE = "hold_color_toggle"
Expand Down
50 changes: 50 additions & 0 deletions apps/controllerx/core/type/light_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
DEFAULT_AUTOMATIC_STEPS = 10
DEFAULT_MIN_BRIGHTNESS = 1
DEFAULT_MAX_BRIGHTNESS = 254
DEFAULT_MIN_WHITE_VALUE = 1
DEFAULT_MAX_WHITE_VALUE = 254
DEFAULT_MIN_COLOR_TEMP = 153
DEFAULT_MAX_COLOR_TEMP = 500
DEFAULT_TRANSITION = 300
Expand All @@ -37,6 +39,7 @@ class LightController(TypeController, ReleaseHoldController):
"""

ATTRIBUTE_BRIGHTNESS = "brightness"
ATTRIBUTE_WHITE_VALUE = "white_value"
# With the following attribute, it will select color_temp or xy_color, depending on the light.
ATTRIBUTE_COLOR = "color"
ATTRIBUTE_COLOR_TEMP = "color_temp"
Expand Down Expand Up @@ -81,6 +84,8 @@ async def initialize(self) -> None:
automatic_steps = self.args.get("automatic_steps", DEFAULT_AUTOMATIC_STEPS)
self.min_brightness = self.args.get("min_brightness", DEFAULT_MIN_BRIGHTNESS)
self.max_brightness = self.args.get("max_brightness", DEFAULT_MAX_BRIGHTNESS)
self.min_white_value = self.args.get("min_white_value", DEFAULT_MIN_WHITE_VALUE)
self.max_white_value = self.args.get("max_white_value", DEFAULT_MAX_WHITE_VALUE)
self.min_color_temp = self.args.get("min_color_temp", DEFAULT_MIN_COLOR_TEMP)
self.max_color_temp = self.args.get("max_color_temp", DEFAULT_MAX_COLOR_TEMP)
self.transition = self.args.get("transition", DEFAULT_TRANSITION)
Expand All @@ -89,6 +94,9 @@ async def initialize(self) -> None:
LightController.ATTRIBUTE_BRIGHTNESS: MinMaxStepper(
self.min_brightness, self.max_brightness, manual_steps
),
LightController.ATTRIBUTE_WHITE_VALUE: MinMaxStepper(
self.min_white_value, self.max_white_value, manual_steps
),
LightController.ATTRIBUTE_COLOR_TEMP: MinMaxStepper(
self.min_color_temp, self.max_color_temp, manual_steps
),
Expand All @@ -98,6 +106,9 @@ async def initialize(self) -> None:
LightController.ATTRIBUTE_BRIGHTNESS: MinMaxStepper(
self.min_brightness, self.max_brightness, automatic_steps
),
LightController.ATTRIBUTE_WHITE_VALUE: MinMaxStepper(
self.min_white_value, self.max_white_value, automatic_steps
),
LightController.ATTRIBUTE_COLOR_TEMP: MinMaxStepper(
self.min_color_temp, self.max_color_temp, automatic_steps
),
Expand Down Expand Up @@ -127,6 +138,10 @@ def get_type_actions_mapping(self,) -> TypeActionsMapping:
self.on_full,
LightController.ATTRIBUTE_BRIGHTNESS,
),
Light.ON_FULL_WHITE_VALUE: (
self.on_full,
LightController.ATTRIBUTE_WHITE_VALUE,
),
Light.ON_FULL_COLOR_TEMP: (
self.on_full,
LightController.ATTRIBUTE_COLOR_TEMP,
Expand All @@ -135,6 +150,10 @@ def get_type_actions_mapping(self,) -> TypeActionsMapping:
self.on_min,
LightController.ATTRIBUTE_BRIGHTNESS,
),
Light.ON_MIN_WHITE_VALUE: (
self.on_min,
LightController.ATTRIBUTE_WHITE_VALUE,
),
Light.ON_MIN_COLOR_TEMP: (
self.on_min,
LightController.ATTRIBUTE_COLOR_TEMP,
Expand All @@ -144,6 +163,11 @@ def get_type_actions_mapping(self,) -> TypeActionsMapping:
LightController.ATTRIBUTE_BRIGHTNESS,
0.5,
),
Light.SET_HALF_WHITE_VALUE: (
self.set_value,
LightController.ATTRIBUTE_WHITE_VALUE,
0.5,
),
Light.SET_HALF_COLOR_TEMP: (
self.set_value,
LightController.ATTRIBUTE_COLOR_TEMP,
Expand All @@ -160,6 +184,16 @@ def get_type_actions_mapping(self,) -> TypeActionsMapping:
LightController.ATTRIBUTE_BRIGHTNESS,
Stepper.DOWN,
),
Light.CLICK_WHITE_VALUE_UP: (
self.click,
LightController.ATTRIBUTE_WHITE_VALUE,
Stepper.UP,
),
Light.CLICK_WHITE_VALUE_DOWN: (
self.click,
LightController.ATTRIBUTE_WHITE_VALUE,
Stepper.DOWN,
),
Light.CLICK_COLOR_UP: (
self.click,
LightController.ATTRIBUTE_COLOR,
Expand Down Expand Up @@ -205,6 +239,21 @@ def get_type_actions_mapping(self,) -> TypeActionsMapping:
LightController.ATTRIBUTE_BRIGHTNESS,
Stepper.TOGGLE,
),
Light.HOLD_WHITE_VALUE_UP: (
self.hold,
LightController.ATTRIBUTE_WHITE_VALUE,
Stepper.UP,
),
Light.HOLD_WHITE_VALUE_DOWN: (
self.hold,
LightController.ATTRIBUTE_WHITE_VALUE,
Stepper.DOWN,
),
Light.HOLD_WHITE_VALUE_TOGGLE: (
self.hold,
LightController.ATTRIBUTE_WHITE_VALUE,
Stepper.TOGGLE,
),
Light.HOLD_COLOR_UP: (
self.hold,
LightController.ATTRIBUTE_COLOR,
Expand Down Expand Up @@ -359,6 +408,7 @@ async def get_value_attribute(
return 0
elif (
attribute == LightController.ATTRIBUTE_BRIGHTNESS
or attribute == LightController.ATTRIBUTE_WHITE_VALUE
or attribute == LightController.ATTRIBUTE_COLOR_TEMP
):
value = await self.get_entity_state(self.light["name"], attribute)
Expand Down
74 changes: 41 additions & 33 deletions docs/others/custom-controllers.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,47 @@ Class: `CustomLightController`

This controller lets you map controller events with predefined light actions. This is a [Light controller](/controllerx/start/type-configuration#light-controller), so it inheritance all its parameters. This is the list of predefined actions that can be mapped as a value in the key-value map from the `mapping` attribute.

| value | description |
| ------------------------ | --------------------------------------------------------------------------------------------------------------------------- |
| `on` | It turns on the light |
| `off` | It turns off the light |
| `toggle` | It toggles the light |
| `release` | It stops `hold` actions |
| `on_full_brightness` | It puts the brightness to the maximum value |
| `on_full_color_temp` | It puts the color temp to the maximum value |
| `on_min_brightness` | It puts the brightness to the minimum value |
| `on_min_color_temp` | It puts the color temp to the minimum value |
| `set_half_brightness` | It sets the brightness to 50% |
| `set_half_color_temp` | It sets the color temp to 50% |
| `sync` | It syncs the light(s) to full brightness and white colour or 2700K (370 mireds) |
| `click_brightness_up` | It brights up accordingly with the `manual_steps` attribute |
| `click_brightness_down` | It brights down accordingly with the `manual_steps` attribute |
| `click_color_up` | It turns the color up accordingly with the `manual_steps` attribute |
| `click_color_down` | It turns the color down accordingly with the `manual_steps` attribute |
| `click_colortemp_up` | It turns the color temp up accordingly with the `manual_steps` attribute |
| `click_colortemp_down` | It turns the color temp down accordingly with the `manual_steps` attribute |
| `click_xycolor_up` | It turns the xy color up accordingly with the `manual_steps` attribute |
| `click_xycolor_down` | It turns the xy color down accordingly with the `manual_steps` attribute |
| `hold_brightness_up` | It brights up until release accordingly with the `automatic_steps` attribute |
| `hold_brightness_down` | It brights down until release accordingly with the `automatic_steps` attribute |
| `hold_brightness_toggle` | It brights up/down until release accordingly with the `automatic_steps` attribute and alternates in each click |
| `hold_color_up` | It turns the color up until release accordingly with the `automatic_steps` attribute |
| `hold_color_down` | It turns the color down until release accordingly with the `automatic_steps` attribute |
| `hold_color_toggle` | It turns the color up/down until release accordingly with the `automatic_steps` attribute and alternates in each click |
| `hold_colortemp_up` | It turns the color temp up until release accordingly with the `automatic_steps` attribute |
| `hold_colortemp_down` | It turns the color temp down until release accordingly with the `automatic_steps` attribute |
| `hold_colortemp_toggle` | It turns the color temp up/down until release accordingly with the `automatic_steps` attribute and alternates in each click |
| `hold_xycolor_up` | It turns the xy color up until release accordingly with the `automatic_steps` attribute |
| `hold_xycolor_down` | It turns the xy color down until release accordingly with the `automatic_steps` attribute |
| `hold_xycolor_toggle` | It turns the xy color up/down until release accordingly with the `automatic_steps` attribute and alternates in each click |
| value | description |
| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------- |
| `on` | It turns on the light |
| `off` | It turns off the light |
| `toggle` | It toggles the light |
| `release` | It stops `hold` actions |
| `on_full_brightness` | It puts the brightness to the maximum value |
| `on_full_white_value` | It puts the white value to the maximum value |
| `on_full_color_temp` | It puts the color temp to the maximum value |
| `on_min_brightness` | It puts the brightness to the minimum value |
| `on_min_white_value` | It puts the white value to the minimum value |
| `on_min_color_temp` | It puts the color temp to the minimum value |
| `set_half_brightness` | It sets the brightness to 50% |
| `set_half_white_value` | It sets the white value to 50% |
| `set_half_color_temp` | It sets the color temp to 50% |
| `sync` | It syncs the light(s) to full brightness and white colour or 2700K (370 mireds) |
| `click_brightness_up` | It brights up accordingly with the `manual_steps` attribute |
| `click_brightness_down` | It brights down accordingly with the `manual_steps` attribute |
| `click_white_value_up` | It turns the white value up accordingly with the `manual_steps` attribute |
| `click_white_value_down` | It turns the white value down accordingly with the `manual_steps` attribute |
| `click_color_up` | It turns the color up accordingly with the `manual_steps` attribute |
| `click_color_down` | It turns the color down accordingly with the `manual_steps` attribute |
| `click_colortemp_up` | It turns the color temp up accordingly with the `manual_steps` attribute |
| `click_colortemp_down` | It turns the color temp down accordingly with the `manual_steps` attribute |
| `click_xycolor_up` | It turns the xy color up accordingly with the `manual_steps` attribute |
| `click_xycolor_down` | It turns the xy color down accordingly with the `manual_steps` attribute |
| `hold_brightness_up` | It brights up until release accordingly with the `automatic_steps` attribute |
| `hold_brightness_down` | It brights down until release accordingly with the `automatic_steps` attribute |
| `hold_brightness_toggle` | It brights up/down until release accordingly with the `automatic_steps` attribute and alternates in each click |
| `hold_white_value_up` | It turns the white value up until release accordingly with the `automatic_steps` attribute |
| `hold_white_value_down` | It turns the white value down until release accordingly with the `automatic_steps` attribute |
| `hold_white_value_toggle` | It turns the white value up/down until release accordingly with the `automatic_steps` attribute and alternates in each click |
| `hold_color_up` | It turns the color up until release accordingly with the `automatic_steps` attribute |
| `hold_color_down` | It turns the color down until release accordingly with the `automatic_steps` attribute |
| `hold_color_toggle` | It turns the color up/down until release accordingly with the `automatic_steps` attribute and alternates in each click |
| `hold_colortemp_up` | It turns the color temp up until release accordingly with the `automatic_steps` attribute |
| `hold_colortemp_down` | It turns the color temp down until release accordingly with the `automatic_steps` attribute |
| `hold_colortemp_toggle` | It turns the color temp up/down until release accordingly with the `automatic_steps` attribute and alternates in each click |
| `hold_xycolor_up` | It turns the xy color up until release accordingly with the `automatic_steps` attribute |
| `hold_xycolor_down` | It turns the xy color down until release accordingly with the `automatic_steps` attribute |
| `hold_xycolor_toggle` | It turns the xy color up/down until release accordingly with the `automatic_steps` attribute and alternates in each click |

#### Example of CustomLightController

Expand Down
Loading

0 comments on commit 41576b2

Please sign in to comment.