Skip to content

Commit

Permalink
feat(release_hold_controller): add max_loops attribute to control f…
Browse files Browse the repository at this point in the history
…rom user configuration
  • Loading branch information
xaviml committed Jun 28, 2020
1 parent d83bca4 commit a174d53
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions apps/controllerx/cx_core/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,14 @@ async def get_entity_state(self, entity: str, attribute: str = None) -> Any:


class ReleaseHoldController(Controller, abc.ABC):
MAX_LOOPS = 20
DEFAULT_MAX_LOOPS = 50

async def initialize(self):
self.on_hold = False
self.delay = self.args.get("delay", self.default_delay())
self.max_loops = self.args.get(
"max_loops", ReleaseHoldController.DEFAULT_MAX_LOOPS
)
await super().initialize()

@action
Expand All @@ -277,7 +280,7 @@ async def hold(self, *args) -> None:
stop = await self.hold_loop(*args)
# Stop the iteration if we either stop from the hold_loop
# or we reached the max loop number
stop = stop or loops >= ReleaseHoldController.MAX_LOOPS
stop = stop or loops >= self.max_loops
await self.sleep(self.delay / 1000)
loops += 1

Expand Down
4 changes: 3 additions & 1 deletion docs/start/type-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ This controller allows the devices to control light or group of lights. This all
| `min_color_temp` | int | 153 | The minimum color temperature to set to the light. |
| `max_color_temp` | int | 500 | The maximum color temperature to set to the light. |
| `smooth_power_on` | boolean | False | If `True` the associated light will be set to minimum brightness when brightness up is clicked or hold ad light is off. |
| `delay` | int | [Controller specific](/controllerx/controllers) | Delay in milliseconds that takes between sending the instructions to the light (for the smooth functionality). Note that the maximum value is 1000 and if leaving to 0, you might get uncommon behavior. |
| `delay` | int | [Controller specific](/controllerx/controllers) | Delay in milliseconds that takes between sending the instructions to the light (for the smooth functionality). Note that if leaving to 0, you might get uncommon behavior. |
| `max_loops` | int | 50 | Maximum number of loops when holding. The loop will stop either with a release action or reaching the `max_loops` value. |
| `transition` | int | 300 | Time in milliseconds that takes the light to transition from one state to another one. |
| `add_transition` | boolean | True | If `true` adds transition if supported, otherwise it does not adds the `transition` attribute. |
| `add_transition_turn_toggle` | boolean | True | If `false` does not add transition when turning on/off or toggling, otherwise it adds the `transition` attribute to the call. See [FAQ #6](/controllerx/faq#6-light-is-not-turning-on-to-the-previous-brightness) for a further explanation on the use of this parameter. |
Expand All @@ -54,6 +55,7 @@ This allows you to control media players. It supports volume, play/pause and ski
| `media_player`\* | string | `group.livingroom_speakers` or `media_player.bedroom_speaker` | The media player (or group of media players) you want to control |
| `volume_steps` | int | 10 | Number of steps to go from min to max when clicking or holding. If the value is 2 with one click you will set the volume to 50% and with another one to 100%. |
| `delay` | int | [Controller specific](/controllerx/controllers) | Delay in milliseconds that takes between sending the volume up/down instructions. Note that the maximum value is 1000 and if leaving to 0, you might get uncommon behavior. |
| `max_loops` | int | 50 | Maximum number of loops when holding. The loop will stop either with a release action or reaching the `max_loops` value. |

_\* Required fields_

Expand Down

0 comments on commit a174d53

Please sign in to comment.