dmamontov / esphome-blekeyboard

ESPHome BLE Keyboard
https://community.home-assistant.io/t/esphome-ble-keyboard/
84 stars 16 forks source link

Option to not advertise upon startup #27

Open Rudd-O opened 1 year ago

Rudd-O commented 1 year ago

With some devices, it is preferable simply not to advertise at all the return of the ESP keyboard once it restarts.

This option enables users to choose that.

They can create a switch to turn advertisements off in this way:

globals:
  - id: keyboard_enabled
    type: bool
    restore_value: no
    initial_value: "false"

switch:
  - platform: template
    name: Enabled
    icon: mdi:power
    lambda: |-
      if (id(keyboard_enabled)) {
        return true;
      } else {
        return false;
      }
    turn_on_action:
      - ble_keyboard.start: le_keyboard
      - lambda: |-
          id(keyboard_enabled) = true;
      - logger.log:
          format: "The keyboard has been enabled."
          level: INFO
    turn_off_action:
      - ble_keyboard.stop: le_keyboard
      - lambda: |-
          id(keyboard_enabled) = false;
      - logger.log:
          format: "The keyboard has been disabled."
          level: INFO
sourcery-ai[bot] commented 1 year ago

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.38%.

Quality metrics Before After Change
Complexity 1.38 ⭐ 1.37 ⭐ -0.01 👍
Method Length 177.62 😞 179.08 😞 1.46 👎
Working memory 12.84 😞 13.03 😞 0.19 👎
Quality 63.71% 🙂 63.33% 🙂 -0.38% 👎
Other metrics Before After Change
Lines 1044 1048 4
Changed files Quality Before Quality After Quality Change
components/ble_keyboard/__init__.py 74.47% 🙂 74.34% 🙂 -0.13% 👎
components/ble_keyboard/const.py 35.25% 😞 35.25% 😞 0.00%

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
components/ble_keyboard/__init__.py ble_keyboard_press_to_code 2 ⭐ 125 😞 8 🙂 68.04% 🙂 Try splitting into smaller methods
components/ble_keyboard/__init__.py ble_keyboard_combination_to_code 0 ⭐ 132 😞 8 🙂 69.20% 🙂 Try splitting into smaller methods

Legend and Explanation

The emojis denote the absolute quality of the code:

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Rudd-O commented 1 year ago

hello?

Rudd-O commented 6 months ago

Thanks for the review! Your changes have been committed.