Skip to content

Commit

Permalink
fix(play_pause being called twice)
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviml committed Jan 11, 2020
1 parent 1b0e9d2 commit 5628d4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ bedroom_speaker:

These are the generic app parameters for all type of controllers. You can see the rest in [here](https://github.com/xaviml/z2m_ikea_controller/wiki/Controller-types)

| key | optional | type | default | example | description |
| --------- | -------- | -------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `module` | False | string | - | `z2m_ikea_controller` | The Python module |
| `class` | False | string | - | `E1810Controller` | The Python class. Check the classes for each controller on the [supported controllers](https://github.com/xaviml/z2m_ikea_controller/wiki/Supported-controllers) page. |
| `sensor` | False | string \| list | - | `sensor.livingroom_controller_action` or `sensor.livingroom_controller_action1, sensor.livingroom_controller_action2` | The sensor(s) entity id from HA. Note that for IKEA E1524/E1810 it finishes with "\_action" by default and for IKEA E1743 with "\_click". This can be also sent as list on the YAML (using "-") |
| `actions` | True | list | All actions | | This is a list of actions to be included and controlled by the app. To see which actions has each controller check the [supported controllers](https://github.com/xaviml/z2m_ikea_controller/wiki/Supported-controllers) page |
| key | optional | type | default | example | description |
| -------------- | -------- | -------------- | ----------- | --------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `module` | False | string | - | `z2m_ikea_controller` | The Python module |
| `class` | False | string | - | `E1810Controller` | The Python class. Check the classes for each controller on the [supported controllers](https://github.com/xaviml/z2m_ikea_controller/wiki/Supported-controllers) page. |
| `sensor` | False | string \| list | - | `sensor.livingroom_controller_action` or `sensor.livingroom_controller_action1, sensor.livingroom_controller_action2` | The sensor(s) entity id from HA. Note that for IKEA E1524/E1810 it finishes with "\_action" by default and for IKEA E1743 with "\_click". This can be also sent as list on the YAML (using "-") |
| `actions` | True | list | All actions | | This is a list of actions to be included and controlled by the app. To see which actions has each controller check the [supported controllers](https://github.com/xaviml/z2m_ikea_controller/wiki/Supported-controllers) page |
| `action_delta` | True | int | 300 | | This is the threshold time between the previous action and the next one (being the same action). If the time difference between the two actions is less than this attribute, then the action won't be called. I recommend changing this if you see the same action being called twice. |

_TODO_ list:

Expand Down
7 changes: 4 additions & 3 deletions apps/z2m_ikea_controller/z2m_ikea_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
DEFAULT_MANUAL_STEPS = 10
DEFAULT_AUTOMATIC_STEPS = 10
DEFAULT_DELAY = 350 # In milliseconds
DEFAULT_TIME_BETWEEN_ACTIONS = 400 # In milliseconds
DEFAULT_ACTION_DELTA = 300 # In milliseconds


def action(method):
Expand Down Expand Up @@ -57,6 +57,7 @@ def initialize(self):
for key, value in self.actions_mapping.items()
if key in included_actions
}
self.action_delta = self.args.get("action_delta", DEFAULT_ACTION_DELTA)
self.action_times = defaultdict(lambda: 0)
self.sensors = self.get_list(self.args["sensor"])
for sensor in self.sensors:
Expand All @@ -74,8 +75,8 @@ def state(self, entity, attribute, old, new, kwargs):
previous_call_time = self.action_times[new]
now = time.time() * 1000
self.action_times[new] = now
if now - previous_call_time > DEFAULT_TIME_BETWEEN_ACTIONS:
self.log(f"Button pressed: {new}", level="INFO")
if now - previous_call_time > self.action_delta:
self.log(f"Button pressed: {new}", level="DEBUG")
action = self.actions_mapping[new]
action()

Expand Down

0 comments on commit 5628d4e

Please sign in to comment.