Compare commits

...

7 commits

Author SHA1 Message Date
Bas Nijholt
b4078b72db Update .devcontainer 2025-01-01 15:12:08 -08:00
Bas Nijholt
7c422f6a3a more 2025-01-01 12:42:11 -08:00
github-actions[bot]
142cd7b214 Update README.md, strings.json, and services.yaml 2025-01-01 20:33:03 +00:00
Bas Nijholt
9687ac0f55
Merge 5152bf86b5 into 66561058ec 2025-01-01 20:28:31 +00:00
Bas Nijholt
5152bf86b5 await hass.async_block_till_done() 2025-01-01 12:28:23 -08:00
Bas Nijholt
c85254bfed Merge remote-tracking branch 'origin/main' into fix-async 2025-01-01 12:19:58 -08:00
Bas Nijholt
7372cb2551 Fix #1020 2024-08-25 16:35:50 -07:00
9 changed files with 32 additions and 32 deletions

View file

@ -1,7 +1,7 @@
{ {
"name": "basnijholt/adaptive_lighting", "name": "basnijholt/adaptive_lighting",
"image": "mcr.microsoft.com/vscode/devcontainers/python:3.12", "image": "mcr.microsoft.com/devcontainers/python:1-3.13",
"postCreateCommand": "scripts/setup-devcontainer", "postCreateCommand": "./scripts/setup-devcontainer && source .venv/bin/activate",
"forwardPorts": [ "forwardPorts": [
8123 8123
], ],
@ -36,7 +36,5 @@
} }
}, },
"remoteUser": "vscode", "remoteUser": "vscode",
"features": { "features": {}
"ghcr.io/devcontainers/features/rust:1": {}
}
} }

View file

@ -132,7 +132,7 @@ The YAML and frontend configuration methods support all of the options listed be
| `brightness_mode_time_dark` | (Ignored if `brightness_mode='default'`) The duration in seconds to ramp up/down the brightness before/after sunrise/sunset. 📈📉 | `900` | `int` | | `brightness_mode_time_dark` | (Ignored if `brightness_mode='default'`) The duration in seconds to ramp up/down the brightness before/after sunrise/sunset. 📈📉 | `900` | `int` |
| `brightness_mode_time_light` | (Ignored if `brightness_mode='default'`) The duration in seconds to ramp up/down the brightness after/before sunrise/sunset. 📈📉. | `3600` | `int` | | `brightness_mode_time_light` | (Ignored if `brightness_mode='default'`) The duration in seconds to ramp up/down the brightness after/before sunrise/sunset. 📈📉. | `3600` | `int` |
| `take_over_control` | Disable Adaptive Lighting if another source calls `light.turn_on` while lights are on and being adapted. Note that this calls `homeassistant.update_entity` every `interval`! 🔒 | `True` | `bool` | | `take_over_control` | Disable Adaptive Lighting if another source calls `light.turn_on` while lights are on and being adapted. Note that this calls `homeassistant.update_entity` every `interval`! 🔒 | `True` | `bool` |
| `detect_non_ha_changes` | Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵️ Caution: ⚠️ Some lights might falsely indicate an 'on' state, which could result in lights turning on unexpectedly. Disable this feature if you encounter such issues. | `False` | `bool` | | `detect_non_ha_changes` | Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵Caution: ⚠️ Some lights might falsely indicate an 'on' state, which could result in lights turning on unexpectedly. Disable this feature if you encounter such issues. | `False` | `bool` |
| `autoreset_control_seconds` | Automatically reset the manual control after a number of seconds. Set to 0 to disable. ⏲️ | `0` | `int` 0-31536000 | | `autoreset_control_seconds` | Automatically reset the manual control after a number of seconds. Set to 0 to disable. ⏲️ | `0` | `int` 0-31536000 |
| `only_once` | Adapt lights only when they are turned on (`true`) or keep adapting them (`false`). 🔄 | `False` | `bool` | | `only_once` | Adapt lights only when they are turned on (`true`) or keep adapting them (`false`). 🔄 | `False` | `bool` |
| `adapt_only_on_bare_turn_on` | When turning lights on initially. If set to `true`, AL adapts only if `light.turn_on` is invoked without specifying color or brightness. ❌🌈 This e.g., prevents adaptation when activating a scene. If `false`, AL adapts regardless of the presence of color or brightness in the initial `service_data`. Needs `take_over_control` enabled. 🕵️ | `False` | `bool` | | `adapt_only_on_bare_turn_on` | When turning lights on initially. If set to `true`, AL adapts only if `light.turn_on` is invoked without specifying color or brightness. ❌🌈 This e.g., prevents adaptation when activating a scene. If `false`, AL adapts regardless of the presence of color or brightness in the initial `service_data`. Needs `take_over_control` enabled. 🕵️ | `False` | `bool` |

View file

@ -65,11 +65,7 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry):
undo_listener = config_entry.add_update_listener(async_update_options) undo_listener = config_entry.add_update_listener(async_update_options)
data[config_entry.entry_id] = {UNDO_UPDATE_LISTENER: undo_listener} data[config_entry.entry_id] = {UNDO_UPDATE_LISTENER: undo_listener}
for platform in PLATFORMS: await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(config_entry, platform),
)
return True return True

View file

@ -226,7 +226,7 @@ change_switch_settings:
selector: selector:
boolean: null boolean: null
detect_non_ha_changes: detect_non_ha_changes:
description: 'Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵️ Caution: ⚠️ Some lights might falsely indicate an ''on'' state, which could result in lights turning on unexpectedly. Disable this feature if you encounter such issues.' description: 'Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵️Caution: ⚠️ Some lights might falsely indicate an ''on'' state, which could result in lights turning on unexpectedly. Disable this feature if you encounter such issues.'
required: false required: false
example: false example: false
selector: selector:

View file

@ -46,7 +46,7 @@
"brightness_mode_time_dark": "brightness_mode_time_dark", "brightness_mode_time_dark": "brightness_mode_time_dark",
"brightness_mode_time_light": "brightness_mode_time_light", "brightness_mode_time_light": "brightness_mode_time_light",
"take_over_control": "take_over_control: Disable Adaptive Lighting if another source calls `light.turn_on` while lights are on and being adapted. Note that this calls `homeassistant.update_entity` every `interval`! 🔒", "take_over_control": "take_over_control: Disable Adaptive Lighting if another source calls `light.turn_on` while lights are on and being adapted. Note that this calls `homeassistant.update_entity` every `interval`! 🔒",
"detect_non_ha_changes": "detect_non_ha_changes: Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵️ Caution: ⚠️ Some lights might falsely indicate an 'on' state, which could result in lights turning on unexpectedly. Disable this feature if you encounter such issues.", "detect_non_ha_changes": "detect_non_ha_changes: Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵️Caution: ⚠️ Some lights might falsely indicate an 'on' state, which could result in lights turning on unexpectedly. Disable this feature if you encounter such issues.",
"autoreset_control_seconds": "autoreset_control_seconds", "autoreset_control_seconds": "autoreset_control_seconds",
"only_once": "only_once: Adapt lights only when they are turned on (`true`) or keep adapting them (`false`). 🔄", "only_once": "only_once: Adapt lights only when they are turned on (`true`) or keep adapting them (`false`). 🔄",
"adapt_only_on_bare_turn_on": "adapt_only_on_bare_turn_on: When turning lights on initially. If set to `true`, AL adapts only if `light.turn_on` is invoked without specifying color or brightness. ❌🌈 This e.g., prevents adaptation when activating a scene. If `false`, AL adapts regardless of the presence of color or brightness in the initial `service_data`. Needs `take_over_control` enabled. 🕵️ ", "adapt_only_on_bare_turn_on": "adapt_only_on_bare_turn_on: When turning lights on initially. If set to `true`, AL adapts only if `light.turn_on` is invoked without specifying color or brightness. ❌🌈 This e.g., prevents adaptation when activating a scene. If `false`, AL adapts regardless of the presence of color or brightness in the initial `service_data`. Needs `take_over_control` enabled. 🕵️ ",
@ -247,7 +247,7 @@
"name": "take_over_control" "name": "take_over_control"
}, },
"detect_non_ha_changes": { "detect_non_ha_changes": {
"description": "Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵️ Caution: ⚠️ Some lights might falsely indicate an 'on' state, which could result in lights turning on unexpectedly. Disable this feature if you encounter such issues.", "description": "Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵️Caution: ⚠️ Some lights might falsely indicate an 'on' state, which could result in lights turning on unexpectedly. Disable this feature if you encounter such issues.",
"name": "detect_non_ha_changes" "name": "detect_non_ha_changes"
}, },
"transition": { "transition": {

View file

@ -47,7 +47,7 @@
"brightness_mode_time_dark": "brightness_mode_time_dark", "brightness_mode_time_dark": "brightness_mode_time_dark",
"brightness_mode_time_light": "brightness_mode_time_light", "brightness_mode_time_light": "brightness_mode_time_light",
"take_over_control": "take_over_control: Disable Adaptive Lighting if another source calls `light.turn_on` while lights are on and being adapted. Note that this calls `homeassistant.update_entity` every `interval`! 🔒", "take_over_control": "take_over_control: Disable Adaptive Lighting if another source calls `light.turn_on` while lights are on and being adapted. Note that this calls `homeassistant.update_entity` every `interval`! 🔒",
"detect_non_ha_changes": "detect_non_ha_changes: Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵️ Caution: ⚠️ Some lights might falsely indicate an 'on' state, which could result in lights turning on unexpectedly. Disable this feature if you encounter such issues.", "detect_non_ha_changes": "detect_non_ha_changes: Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵️Caution: ⚠️ Some lights might falsely indicate an 'on' state, which could result in lights turning on unexpectedly. Disable this feature if you encounter such issues.",
"autoreset_control_seconds": "autoreset_control_seconds", "autoreset_control_seconds": "autoreset_control_seconds",
"only_once": "only_once: Adapt lights only when they are turned on (`true`) or keep adapting them (`false`). 🔄", "only_once": "only_once: Adapt lights only when they are turned on (`true`) or keep adapting them (`false`). 🔄",
"adapt_only_on_bare_turn_on": "adapt_only_on_bare_turn_on: When turning lights on initially. If set to `true`, AL adapts only if `light.turn_on` is invoked without specifying color or brightness. ❌🌈 This e.g., prevents adaptation when activating a scene. If `false`, AL adapts regardless of the presence of color or brightness in the initial `service_data`. Needs `take_over_control` enabled. 🕵️ ", "adapt_only_on_bare_turn_on": "adapt_only_on_bare_turn_on: When turning lights on initially. If set to `true`, AL adapts only if `light.turn_on` is invoked without specifying color or brightness. ❌🌈 This e.g., prevents adaptation when activating a scene. If `false`, AL adapts regardless of the presence of color or brightness in the initial `service_data`. Needs `take_over_control` enabled. 🕵️ ",
@ -248,7 +248,7 @@
"name": "take_over_control" "name": "take_over_control"
}, },
"detect_non_ha_changes": { "detect_non_ha_changes": {
"description": "Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵️ Caution: ⚠️ Some lights might falsely indicate an 'on' state, which could result in lights turning on unexpectedly. Disable this feature if you encounter such issues.", "description": "Detects and halts adaptations for non-`light.turn_on` state changes. Needs `take_over_control` enabled. 🕵️Caution: ⚠️ Some lights might falsely indicate an 'on' state, which could result in lights turning on unexpectedly. Disable this feature if you encounter such issues.",
"name": "detect_non_ha_changes" "name": "detect_non_ha_changes"
}, },
"transition": { "transition": {

View file

@ -2,7 +2,11 @@
set -ex set -ex
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
pip install -r core/requirements.txt pip install uv
uv venv
source .venv/bin/activate
uv pip install -r core/requirements.txt
if grep -q 'codecov' core/requirements_test.txt; then if grep -q 'codecov' core/requirements_test.txt; then
# Older HA versions still have `codecov` in `requirements_test.txt` # Older HA versions still have `codecov` in `requirements_test.txt`
@ -14,8 +18,8 @@ if grep -q 'mypy-dev==1.10.0a3' core/requirements_test.txt; then
# mypy-dev==1.10.0a3 seems to not be available anymore, HA 2024.4 and 2024.5 are affected # mypy-dev==1.10.0a3 seems to not be available anymore, HA 2024.4 and 2024.5 are affected
sed -i 's/mypy-dev==1.10.0a3/mypy-dev==1.10.0b1/' core/requirements_test.txt sed -i 's/mypy-dev==1.10.0a3/mypy-dev==1.10.0b1/' core/requirements_test.txt
fi fi
pip install -r core/requirements_test.txt uv pip install -r core/requirements_test.txt
pip install -e core/ uv pip install -e core/
pip install ulid-transform # this is in Adaptive-lighting's manifest.json uv pip install ulid-transform # this is in Adaptive-lighting's manifest.json
pip install $(python test_dependencies.py) uv pip install $(python test_dependencies.py)

View file

@ -1,5 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -ex
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
# Clone only if the folder doesn't exist # Clone only if the folder doesn't exist
@ -8,10 +8,10 @@ if [[ ! -d "core" ]]; then
fi fi
pip install \ pip install \
colorlog==6.7.0 \ colorlog \
pip>=21.0,<23.2 \ pip \
ruff==0.0.265 ruff
./scripts/setup-dependencies ./scripts/setup-dependencies
./scripts/setup-symlinks ./scripts/setup-symlinks
pre-commit install-hooks uv run pre-commit install-hooks

View file

@ -1,6 +1,5 @@
"""Test Adaptive Lighting config flow.""" """Test Adaptive Lighting config flow."""
from homeassistant import data_entry_flow
from homeassistant.components.adaptive_lighting.const import ( from homeassistant.components.adaptive_lighting.const import (
CONF_SUNRISE_TIME, CONF_SUNRISE_TIME,
CONF_SUNSET_TIME, CONF_SUNSET_TIME,
@ -11,6 +10,7 @@ from homeassistant.components.adaptive_lighting.const import (
) )
from homeassistant.config_entries import SOURCE_IMPORT from homeassistant.config_entries import SOURCE_IMPORT
from homeassistant.const import CONF_NAME from homeassistant.const import CONF_NAME
from homeassistant.data_entry_flow import FlowResultType
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -24,7 +24,7 @@ async def test_flow_manual_configuration(hass):
context={"source": "user"}, context={"source": "user"},
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "user" assert result["step_id"] == "user"
assert result["handler"] == "adaptive_lighting" assert result["handler"] == "adaptive_lighting"
@ -32,7 +32,7 @@ async def test_flow_manual_configuration(hass):
result["flow_id"], result["flow_id"],
user_input={CONF_NAME: "living room"}, user_input={CONF_NAME: "living room"},
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == "living room" assert result["title"] == "living room"
@ -46,7 +46,7 @@ async def test_import_success(hass):
data=data, data=data,
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["type"] == FlowResultType.CREATE_ENTRY
assert result["title"] == DEFAULT_NAME assert result["title"] == DEFAULT_NAME
for key, value in data.items(): for key, value in data.items():
assert result["data"][key] == value assert result["data"][key] == value
@ -65,7 +65,7 @@ async def test_options(hass):
await hass.config_entries.async_setup(entry.entry_id) await hass.config_entries.async_setup(entry.entry_id)
result = await hass.config_entries.options.async_init(entry.entry_id) result = await hass.config_entries.options.async_init(entry.entry_id)
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM assert result["type"] == FlowResultType.FORM
assert result["step_id"] == "init" assert result["step_id"] == "init"
data = DEFAULT_DATA.copy() data = DEFAULT_DATA.copy()
@ -75,7 +75,7 @@ async def test_options(hass):
result["flow_id"], result["flow_id"],
user_input=data, user_input=data,
) )
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY assert result["type"] == FlowResultType.CREATE_ENTRY
for key, value in data.items(): for key, value in data.items():
assert result["data"][key] == value assert result["data"][key] == value
@ -126,8 +126,10 @@ async def test_changing_options_when_using_yaml(hass):
entry.add_to_hass(hass) entry.add_to_hass(hass)
await hass.config_entries.async_setup(entry.entry_id) await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.options.async_init(entry.entry_id) result = await hass.config_entries.options.async_init(entry.entry_id)
await hass.async_block_till_done()
result = await hass.config_entries.options.async_configure( result = await hass.config_entries.options.async_configure(
result["flow_id"], result["flow_id"],
user_input={}, user_input={},