mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-24 10:54:19 +02:00
use uv, fix devcontainer, and drop support for HA ≤2023.6 (#1151)
* Update .devcontainer * Drop support for ≤2023.6 * Add .vscode/settings.json * Use async_process_ha_core_config * Fix for HA ≤2023.10 * pop normalized_name * Add comments * use . instead of source * set pytest args * set country * use py3.13 for dev branch of core * set country in test_adaptive_lighting_time_zones_with_default_settings * Add comment
This commit is contained in:
parent
60d07ecd02
commit
f8719994a6
8 changed files with 72 additions and 46 deletions
|
|
@ -1,6 +1,5 @@
|
|||
"""Test Adaptive Lighting config flow."""
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components.adaptive_lighting.const import (
|
||||
CONF_SUNRISE_TIME,
|
||||
CONF_SUNSET_TIME,
|
||||
|
|
@ -11,6 +10,7 @@ from homeassistant.components.adaptive_lighting.const import (
|
|||
)
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import CONF_NAME
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ async def test_flow_manual_configuration(hass):
|
|||
context={"source": "user"},
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||
assert result["type"] == FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["handler"] == "adaptive_lighting"
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ async def test_flow_manual_configuration(hass):
|
|||
result["flow_id"],
|
||||
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"
|
||||
|
||||
|
||||
|
|
@ -46,7 +46,7 @@ async def test_import_success(hass):
|
|||
data=data,
|
||||
)
|
||||
|
||||
assert result["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == DEFAULT_NAME
|
||||
for key, value in data.items():
|
||||
assert result["data"][key] == value
|
||||
|
|
@ -65,7 +65,7 @@ async def test_options(hass):
|
|||
await hass.config_entries.async_setup(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"
|
||||
|
||||
data = DEFAULT_DATA.copy()
|
||||
|
|
@ -75,7 +75,7 @@ async def test_options(hass):
|
|||
result["flow_id"],
|
||||
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():
|
||||
assert result["data"][key] == value
|
||||
|
||||
|
|
@ -114,6 +114,9 @@ async def test_import_twice(hass):
|
|||
)
|
||||
|
||||
|
||||
# TODO: Fix, broken for all supported versions
|
||||
# But in ≤2024.5 it gives homeassistant.config_entries.UnknownEntry: cd69dbda65bd3f86e9a32d974cdfa23f
|
||||
# and ≥2024.6 it times out
|
||||
async def test_changing_options_when_using_yaml(hass):
|
||||
"""Test changing options when using YAML."""
|
||||
entry = MockConfigEntry(
|
||||
|
|
@ -125,6 +128,7 @@ async def test_changing_options_when_using_yaml(hass):
|
|||
)
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
await hass.block_till_done()
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
|
||||
result = await hass.config_entries.options.async_init(entry.entry_id)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ from random import randint
|
|||
from typing import Any
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
import homeassistant.config as config_util
|
||||
import homeassistant.util.dt as dt_util
|
||||
import pytest
|
||||
import ulid_transform
|
||||
|
|
@ -362,6 +361,19 @@ async def test_adaptive_lighting_switches(hass):
|
|||
assert len(data.keys()) == 5
|
||||
|
||||
|
||||
def async_process_ha_core_config(hass, config):
|
||||
"""Set up the Home Assistant configuration."""
|
||||
try:
|
||||
# ha >= "2023.11.0"
|
||||
from homeassistant.core_config import async_process_ha_core_config
|
||||
|
||||
return async_process_ha_core_config(hass, config)
|
||||
except ModuleNotFoundError:
|
||||
import homeassistant.config as config_util
|
||||
|
||||
return config_util.async_process_ha_core_config(hass, config)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("lat", "long", "timezone"), LAT_LONG_TZS)
|
||||
async def test_adaptive_lighting_time_zones_with_default_settings(
|
||||
hass,
|
||||
|
|
@ -371,9 +383,9 @@ async def test_adaptive_lighting_time_zones_with_default_settings(
|
|||
reset_time_zone, # pylint: disable=redefined-outer-name
|
||||
):
|
||||
"""Test setting up the Adaptive Lighting switches with different timezones."""
|
||||
await config_util.async_process_ha_core_config(
|
||||
await async_process_ha_core_config(
|
||||
hass,
|
||||
{"latitude": lat, "longitude": long, "time_zone": timezone},
|
||||
{"latitude": lat, "longitude": long, "time_zone": timezone, "country": "US"},
|
||||
)
|
||||
_, switch = await setup_switch(hass, {})
|
||||
# Shouldn't raise an exception ever
|
||||
|
|
@ -394,9 +406,9 @@ async def test_adaptive_lighting_time_zones_and_sun_settings(
|
|||
|
||||
Also test the (sleep) brightness and color temperature settings.
|
||||
"""
|
||||
await config_util.async_process_ha_core_config(
|
||||
await async_process_ha_core_config(
|
||||
hass,
|
||||
{"latitude": lat, "longitude": long, "time_zone": timezone},
|
||||
{"latitude": lat, "longitude": long, "time_zone": timezone, "country": "US"},
|
||||
)
|
||||
_, switch = await setup_switch(
|
||||
hass,
|
||||
|
|
@ -1359,6 +1371,8 @@ def mock_area_registry(
|
|||
area_kwargs["icon"] = None
|
||||
if dt >= datetime.date(2024, 3, 1):
|
||||
area_kwargs["floor_id"] = "test-floor"
|
||||
if dt >= datetime.date(2024, 11, 1):
|
||||
area_kwargs.pop("normalized_name")
|
||||
|
||||
# This mess... 🤯
|
||||
if dt >= datetime.date(2024, 2, 1) and dt != datetime.date(2024, 4, 1):
|
||||
|
|
@ -1588,6 +1602,7 @@ async def test_proactive_adaptation(hass):
|
|||
assert state.attributes[ATTR_COLOR_TEMP_KELVIN] == 3448
|
||||
|
||||
|
||||
# TODO: Breaks since 2024.5.0!
|
||||
async def test_proactive_adaptation_with_separate_commands(hass):
|
||||
"""Validate that a split proactive adaptation yields one additional service call."""
|
||||
switch, _ = await setup_lights_and_switch(
|
||||
|
|
@ -1927,9 +1942,9 @@ async def test_adapt_until_sleep_and_rgb_colors(hass):
|
|||
Also test the (sleep) brightness and color temperature settings.
|
||||
"""
|
||||
lat, long, timezone = (32.87336, -117.22743, "US/Pacific")
|
||||
await config_util.async_process_ha_core_config(
|
||||
await async_process_ha_core_config(
|
||||
hass,
|
||||
{"latitude": lat, "longitude": long, "time_zone": timezone},
|
||||
{"latitude": lat, "longitude": long, "time_zone": timezone, "country": "US"},
|
||||
)
|
||||
switch, lights = await setup_lights_and_switch(
|
||||
hass,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue