mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Remove jewish_calendar yaml support after 6 months of deprecation (#130291)
This commit is contained in:
parent
ae1203336d
commit
ee41725b53
@ -5,23 +5,17 @@ from __future__ import annotations
|
||||
from functools import partial
|
||||
|
||||
from hdate import Location
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.config_entries import SOURCE_IMPORT
|
||||
from homeassistant.const import (
|
||||
CONF_ELEVATION,
|
||||
CONF_LANGUAGE,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_NAME,
|
||||
CONF_TIME_ZONE,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
import homeassistant.helpers.entity_registry as er
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .binary_sensor import BINARY_SENSORS
|
||||
from .const import (
|
||||
@ -32,7 +26,6 @@ from .const import (
|
||||
DEFAULT_DIASPORA,
|
||||
DEFAULT_HAVDALAH_OFFSET_MINUTES,
|
||||
DEFAULT_LANGUAGE,
|
||||
DEFAULT_NAME,
|
||||
DOMAIN,
|
||||
)
|
||||
from .entity import JewishCalendarConfigEntry, JewishCalendarData
|
||||
@ -40,32 +33,6 @@ from .sensor import INFO_SENSORS, TIME_SENSORS
|
||||
|
||||
PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR]
|
||||
|
||||
CONFIG_SCHEMA = vol.Schema(
|
||||
{
|
||||
DOMAIN: vol.All(
|
||||
cv.deprecated(DOMAIN),
|
||||
{
|
||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
||||
vol.Optional(CONF_DIASPORA, default=DEFAULT_DIASPORA): cv.boolean,
|
||||
vol.Inclusive(CONF_LATITUDE, "coordinates"): cv.latitude,
|
||||
vol.Inclusive(CONF_LONGITUDE, "coordinates"): cv.longitude,
|
||||
vol.Optional(CONF_LANGUAGE, default=DEFAULT_LANGUAGE): vol.In(
|
||||
["hebrew", "english"]
|
||||
),
|
||||
vol.Optional(
|
||||
CONF_CANDLE_LIGHT_MINUTES, default=DEFAULT_CANDLE_LIGHT
|
||||
): int,
|
||||
# Default of 0 means use 8.5 degrees / 'three_stars' time.
|
||||
vol.Optional(
|
||||
CONF_HAVDALAH_OFFSET_MINUTES,
|
||||
default=DEFAULT_HAVDALAH_OFFSET_MINUTES,
|
||||
): int,
|
||||
},
|
||||
)
|
||||
},
|
||||
extra=vol.ALLOW_EXTRA,
|
||||
)
|
||||
|
||||
|
||||
def get_unique_prefix(
|
||||
location: Location,
|
||||
@ -91,35 +58,6 @@ def get_unique_prefix(
|
||||
return f"{prefix}"
|
||||
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Jewish Calendar component."""
|
||||
if DOMAIN not in config:
|
||||
return True
|
||||
|
||||
async_create_issue(
|
||||
hass,
|
||||
HOMEASSISTANT_DOMAIN,
|
||||
f"deprecated_yaml_{DOMAIN}",
|
||||
is_fixable=False,
|
||||
issue_domain=DOMAIN,
|
||||
breaks_in_ha_version="2024.12.0",
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_yaml",
|
||||
translation_placeholders={
|
||||
"domain": DOMAIN,
|
||||
"integration_title": DEFAULT_NAME,
|
||||
},
|
||||
)
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config[DOMAIN]
|
||||
)
|
||||
)
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, config_entry: JewishCalendarConfigEntry
|
||||
) -> bool:
|
||||
|
@ -101,23 +101,10 @@ class JewishCalendarConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
) -> ConfigFlowResult:
|
||||
"""Handle the initial step."""
|
||||
if user_input is not None:
|
||||
_options = {}
|
||||
if CONF_CANDLE_LIGHT_MINUTES in user_input:
|
||||
_options[CONF_CANDLE_LIGHT_MINUTES] = user_input[
|
||||
CONF_CANDLE_LIGHT_MINUTES
|
||||
]
|
||||
del user_input[CONF_CANDLE_LIGHT_MINUTES]
|
||||
if CONF_HAVDALAH_OFFSET_MINUTES in user_input:
|
||||
_options[CONF_HAVDALAH_OFFSET_MINUTES] = user_input[
|
||||
CONF_HAVDALAH_OFFSET_MINUTES
|
||||
]
|
||||
del user_input[CONF_HAVDALAH_OFFSET_MINUTES]
|
||||
if CONF_LOCATION in user_input:
|
||||
user_input[CONF_LATITUDE] = user_input[CONF_LOCATION][CONF_LATITUDE]
|
||||
user_input[CONF_LONGITUDE] = user_input[CONF_LOCATION][CONF_LONGITUDE]
|
||||
return self.async_create_entry(
|
||||
title=DEFAULT_NAME, data=user_input, options=_options
|
||||
)
|
||||
return self.async_create_entry(title=DEFAULT_NAME, data=user_input)
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="user",
|
||||
@ -126,10 +113,6 @@ class JewishCalendarConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
),
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
|
||||
"""Import a config entry from configuration.yaml."""
|
||||
return await self.async_step_user(import_data)
|
||||
|
||||
async def async_step_reconfigure(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
from unittest.mock import AsyncMock
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries, setup
|
||||
from homeassistant.components.jewish_calendar.const import (
|
||||
CONF_CANDLE_LIGHT_MINUTES,
|
||||
@ -20,12 +18,10 @@ from homeassistant.const import (
|
||||
CONF_LANGUAGE,
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_NAME,
|
||||
CONF_TIME_ZONE,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
@ -59,51 +55,6 @@ async def test_step_user(hass: HomeAssistant, mock_setup_entry: AsyncMock) -> No
|
||||
assert entries[0].data[CONF_TIME_ZONE] == hass.config.time_zone
|
||||
|
||||
|
||||
@pytest.mark.parametrize("diaspora", [True, False])
|
||||
@pytest.mark.parametrize("language", ["hebrew", "english"])
|
||||
async def test_import_no_options(hass: HomeAssistant, language, diaspora) -> None:
|
||||
"""Test that the import step works."""
|
||||
conf = {
|
||||
DOMAIN: {CONF_NAME: "test", CONF_LANGUAGE: language, CONF_DIASPORA: diaspora}
|
||||
}
|
||||
|
||||
assert await async_setup_component(hass, DOMAIN, conf.copy())
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entries = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(entries) == 1
|
||||
assert CONF_LANGUAGE in entries[0].data
|
||||
assert CONF_DIASPORA in entries[0].data
|
||||
for entry_key, entry_val in entries[0].data.items():
|
||||
assert entry_val == conf[DOMAIN][entry_key]
|
||||
|
||||
|
||||
async def test_import_with_options(hass: HomeAssistant) -> None:
|
||||
"""Test that the import step works."""
|
||||
conf = {
|
||||
DOMAIN: {
|
||||
CONF_NAME: "test",
|
||||
CONF_DIASPORA: DEFAULT_DIASPORA,
|
||||
CONF_LANGUAGE: DEFAULT_LANGUAGE,
|
||||
CONF_CANDLE_LIGHT_MINUTES: 20,
|
||||
CONF_HAVDALAH_OFFSET_MINUTES: 50,
|
||||
CONF_LATITUDE: 31.76,
|
||||
CONF_LONGITUDE: 35.235,
|
||||
}
|
||||
}
|
||||
|
||||
# Simulate HomeAssistant setting up the component
|
||||
assert await async_setup_component(hass, DOMAIN, conf.copy())
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entries = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(entries) == 1
|
||||
for entry_key, entry_val in entries[0].data.items():
|
||||
assert entry_val == conf[DOMAIN][entry_key]
|
||||
for entry_key, entry_val in entries[0].options.items():
|
||||
assert entry_val == conf[DOMAIN][entry_key]
|
||||
|
||||
|
||||
async def test_single_instance_allowed(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
|
@ -1,76 +1 @@
|
||||
"""Tests for the Jewish Calendar component's init."""
|
||||
|
||||
from hdate import Location
|
||||
|
||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSORS
|
||||
from homeassistant.components.jewish_calendar import get_unique_prefix
|
||||
from homeassistant.components.jewish_calendar.const import (
|
||||
CONF_CANDLE_LIGHT_MINUTES,
|
||||
CONF_DIASPORA,
|
||||
CONF_HAVDALAH_OFFSET_MINUTES,
|
||||
DEFAULT_DIASPORA,
|
||||
DEFAULT_LANGUAGE,
|
||||
DOMAIN,
|
||||
)
|
||||
from homeassistant.const import CONF_LANGUAGE, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
|
||||
async def test_import_unique_id_migration(hass: HomeAssistant) -> None:
|
||||
"""Test unique_id migration."""
|
||||
yaml_conf = {
|
||||
DOMAIN: {
|
||||
CONF_NAME: "test",
|
||||
CONF_DIASPORA: DEFAULT_DIASPORA,
|
||||
CONF_LANGUAGE: DEFAULT_LANGUAGE,
|
||||
CONF_CANDLE_LIGHT_MINUTES: 20,
|
||||
CONF_HAVDALAH_OFFSET_MINUTES: 50,
|
||||
CONF_LATITUDE: 31.76,
|
||||
CONF_LONGITUDE: 35.235,
|
||||
}
|
||||
}
|
||||
|
||||
# Create an entry in the entity registry with the data from conf
|
||||
ent_reg = er.async_get(hass)
|
||||
location = Location(
|
||||
latitude=yaml_conf[DOMAIN][CONF_LATITUDE],
|
||||
longitude=yaml_conf[DOMAIN][CONF_LONGITUDE],
|
||||
timezone=hass.config.time_zone,
|
||||
diaspora=DEFAULT_DIASPORA,
|
||||
)
|
||||
old_prefix = get_unique_prefix(location, DEFAULT_LANGUAGE, 20, 50)
|
||||
sample_entity = ent_reg.async_get_or_create(
|
||||
BINARY_SENSORS,
|
||||
DOMAIN,
|
||||
unique_id=f"{old_prefix}_erev_shabbat_hag",
|
||||
suggested_object_id=f"{DOMAIN}_erev_shabbat_hag",
|
||||
)
|
||||
# Save the existing unique_id, DEFAULT_LANGUAGE should be part of it
|
||||
old_unique_id = sample_entity.unique_id
|
||||
assert DEFAULT_LANGUAGE in old_unique_id
|
||||
|
||||
# Simulate HomeAssistant setting up the component
|
||||
assert await async_setup_component(hass, DOMAIN, yaml_conf.copy())
|
||||
await hass.async_block_till_done()
|
||||
|
||||
entries = hass.config_entries.async_entries(DOMAIN)
|
||||
assert len(entries) == 1
|
||||
for entry_key, entry_val in entries[0].data.items():
|
||||
assert entry_val == yaml_conf[DOMAIN][entry_key]
|
||||
for entry_key, entry_val in entries[0].options.items():
|
||||
assert entry_val == yaml_conf[DOMAIN][entry_key]
|
||||
|
||||
# Assert that the unique_id was updated
|
||||
new_unique_id = ent_reg.async_get(sample_entity.entity_id).unique_id
|
||||
assert new_unique_id != old_unique_id
|
||||
assert DEFAULT_LANGUAGE not in new_unique_id
|
||||
|
||||
# Confirm that when the component is reloaded, the unique_id is not changed
|
||||
assert ent_reg.async_get(sample_entity.entity_id).unique_id == new_unique_id
|
||||
|
||||
# Confirm that all the unique_ids are prefixed correctly
|
||||
await hass.config_entries.async_reload(entries[0].entry_id)
|
||||
er_entries = er.async_entries_for_config_entry(ent_reg, entries[0].entry_id)
|
||||
assert all(entry.unique_id.startswith(entries[0].entry_id) for entry in er_entries)
|
||||
|
Loading…
x
Reference in New Issue
Block a user