From 166044074a58e010ed1244b47247ad09e5930a3c Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Mon, 29 Aug 2022 09:22:35 -0700 Subject: [PATCH 1/2] Add pre-commit CI --- .github/workflows/pre-commit.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 .github/workflows/pre-commit.yaml diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 00000000..f46e01d4 --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,14 @@ +name: pre-commit + +on: + pull_request: + push: + branches: [master] + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v3 + - uses: pre-commit/action@v3.0.0 From 6b3686696b0bd47036fcfc1d8f84855957c27022 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Mon, 29 Aug 2022 09:25:10 -0700 Subject: [PATCH 2/2] Fix pre-commit issues --- custom_components/adaptive_lighting/switch.py | 4 +++- tests/test_switch.py | 2 -- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index bf064f73..59c110f6 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -169,12 +169,14 @@ BRIGHTNESS_ATTRS = { # Keep a short domain version for the context instances (which can only be 36 chars) _DOMAIN_SHORT = "adapt_lgt" + def _int_to_bytes(i: int, signed: bool = False) -> bytes: bits = i.bit_length() if signed: # Make room for the sign bit. bits += 1 - return i.to_bytes((bits + 7) // 8, 'little', signed=signed) + return i.to_bytes((bits + 7) // 8, "little", signed=signed) + def _short_hash(string: str, length: int = 4) -> str: """Create a hash of 'string' with length 'length'.""" diff --git a/tests/test_switch.py b/tests/test_switch.py index 6773c2d1..2038fe8d 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -33,13 +33,11 @@ from homeassistant.components.adaptive_lighting.const import ( ) from homeassistant.components.adaptive_lighting.switch import ( _attributes_have_changed, - _expand_light_groups, color_difference_redmean, create_context, is_our_context, ) from homeassistant.components.demo.light import DemoLight -from homeassistant.components.group import DOMAIN as GROUP_DOMAIN from homeassistant.components.light import ( ATTR_BRIGHTNESS, ATTR_BRIGHTNESS_PCT,