Skip to content

Commit

Permalink
Remove Jewish calendar deprecation and update path to config flow
Browse files Browse the repository at this point in the history
  • Loading branch information
tsvi authored Oct 31, 2024
1 parent 60d3c93 commit 5e362ba
Showing 1 changed file with 2 additions and 86 deletions.
88 changes: 2 additions & 86 deletions homeassistant/components/jewish_calendar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from hdate import Location
import voluptuous as vol

from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import (
CONF_ELEVATION,
CONF_LANGUAGE,
Expand All @@ -18,13 +18,10 @@
CONF_TIME_ZONE,
Platform,
)
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback
from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
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 (
CONF_CANDLE_LIGHT_MINUTES,
CONF_DIASPORA,
Expand All @@ -36,7 +33,6 @@
DEFAULT_NAME,
DOMAIN,
)
from .sensor import INFO_SENSORS, TIME_SENSORS

PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR]

Expand Down Expand Up @@ -67,56 +63,8 @@
)


def get_unique_prefix(
location: Location,
language: str,
candle_lighting_offset: int | None,
havdalah_offset: int | None,
) -> str:
"""Create a prefix for unique ids."""
# location.altitude was unset before 2024.6 when this method
# was used to create the unique id. As such it would always
# use the default altitude of 754.
config_properties = [
location.latitude,
location.longitude,
location.timezone,
754,
location.diaspora,
language,
candle_lighting_offset,
havdalah_offset,
]
prefix = "_".join(map(str, config_properties))
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


Expand Down Expand Up @@ -151,16 +99,6 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
CONF_HAVDALAH_OFFSET_MINUTES: havdalah_offset,
}

# Update unique ID to be unrelated to user defined options
old_prefix = get_unique_prefix(
location, language, candle_lighting_offset, havdalah_offset
)

ent_reg = er.async_get(hass)
entries = er.async_entries_for_config_entry(ent_reg, config_entry.entry_id)
if not entries or any(entry.unique_id.startswith(old_prefix) for entry in entries):
async_update_unique_ids(ent_reg, config_entry.entry_id, old_prefix)

await hass.config_entries.async_forward_entry_setups(config_entry, PLATFORMS)

async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
Expand All @@ -181,25 +119,3 @@ async def async_unload_entry(hass: HomeAssistant, config_entry: ConfigEntry) ->
hass.data[DOMAIN].pop(config_entry.entry_id)

return unload_ok


@callback
def async_update_unique_ids(
ent_reg: er.EntityRegistry, new_prefix: str, old_prefix: str
) -> None:
"""Update unique ID to be unrelated to user defined options.
Introduced with release 2024.6
"""
platform_descriptions = {
Platform.BINARY_SENSOR: BINARY_SENSORS,
Platform.SENSOR: (*INFO_SENSORS, *TIME_SENSORS),
}
for platform, descriptions in platform_descriptions.items():
for description in descriptions:
new_unique_id = f"{new_prefix}-{description.key}"
old_unique_id = f"{old_prefix}_{description.key}"
if entity_id := ent_reg.async_get_entity_id(
platform, DOMAIN, old_unique_id
):
ent_reg.async_update_entity(entity_id, new_unique_id=new_unique_id)

0 comments on commit 5e362ba

Please sign in to comment.