From 057cbb71e024e04556b337e7130503b39de2e004 Mon Sep 17 00:00:00 2001 From: Vincent Le Bourlot Date: Wed, 1 Feb 2023 09:46:06 +0100 Subject: [PATCH] Only add night_light if True. (#82) * Only add night_light if True. * update pre-commit --- .pre-commit-config.yaml | 6 +++--- custom_components/vesync/diagnostics.py | 4 ---- custom_components/vesync/light.py | 7 ++----- pyproject.toml | 17 ----------------- 4 files changed, 5 insertions(+), 29 deletions(-) delete mode 100644 pyproject.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 51f92c5..8559918 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: pyupgrade args: [--py37-plus] - repo: https://github.com/psf/black - rev: 22.10.0 + rev: 23.1.0 hooks: - id: black additional_dependencies: ['click==8.0.4'] @@ -31,10 +31,10 @@ repos: - pydocstyle==5.1.1 files: ^(custom_components)/.+\.py$ - repo: https://github.com/PyCQA/isort - rev: 5.10.1 + rev: 5.12.0 hooks: - id: isort - repo: https://github.com/adrienverge/yamllint.git - rev: v1.28.0 + rev: v1.29.0 hooks: - id: yamllint diff --git a/custom_components/vesync/diagnostics.py b/custom_components/vesync/diagnostics.py index 89cdaa6..ccaad25 100644 --- a/custom_components/vesync/diagnostics.py +++ b/custom_components/vesync/diagnostics.py @@ -13,10 +13,6 @@ from .const import DOMAIN TO_REDACT = {"cid", "uuid", "mac_id"} -def _if_has_attr_else_none(obj, attr): - return getattr(obj, attr) if hasattr(obj, attr) else None - - async def async_get_config_entry_diagnostics( hass: HomeAssistant, entry: ConfigEntry ) -> dict[str, Any]: diff --git a/custom_components/vesync/light.py b/custom_components/vesync/light.py index b5d8704..61cc635 100644 --- a/custom_components/vesync/light.py +++ b/custom_components/vesync/light.py @@ -50,7 +50,7 @@ def _setup_entities(devices, async_add_entities): entities.append(VeSyncDimmableLightHA(dev)) if DEV_TYPE_TO_HA.get(dev.device_type) in ("bulb-tunable-white",): entities.append(VeSyncTunableWhiteLightHA(dev)) - if hasattr(dev, "night_light"): + if hasattr(dev, "night_light") and dev.night_light: entities.append(VeSyncNightLightHA(dev)) async_add_entities(entities, update_before_add=True) @@ -78,10 +78,7 @@ def _ha_brightness_to_vesync(ha_brightness): brightness = max(1, min(brightness, 255)) # convert to percent that vesync api expects brightness = round((brightness / 255) * 100) - # ensure value between 1-100 - brightness = max(1, min(brightness, 100)) - - return brightness + return max(1, min(brightness, 100)) class VeSyncBaseLight(VeSyncDevice, LightEntity): diff --git a/pyproject.toml b/pyproject.toml deleted file mode 100644 index f71e1a6..0000000 --- a/pyproject.toml +++ /dev/null @@ -1,17 +0,0 @@ -[tool.black] -target-version = ["py38"] -exclude = 'generated' - -[tool.isort] -# https://github.com/PyCQA/isort/wiki/isort-Settings -profile = "black" -# will group `import x` and `from x import` of the same module. -force_sort_within_sections = true -known_first_party = [ - "homeassistant", - "tests", -] -forced_separate = [ - "tests", -] -combine_as_imports = true \ No newline at end of file