From 11646cab5f481c0439cad554d9dbd1d81332948d Mon Sep 17 00:00:00 2001 From: Tsvi Mostovicz Date: Sun, 26 May 2024 20:23:02 +0300 Subject: [PATCH] Move Jewish calendar constants to const file (#118180) * Move Jewish calendar constants to const file * Add a few missed constants * Move CONF_LANGUAGE to it's correct path --- .../components/jewish_calendar/__init__.py | 20 ++++++++++--------- .../jewish_calendar/binary_sensor.py | 2 +- .../components/jewish_calendar/config_flow.py | 20 ++++++++++--------- .../components/jewish_calendar/const.py | 13 ++++++++++++ .../components/jewish_calendar/sensor.py | 2 +- tests/components/jewish_calendar/conftest.py | 6 +++--- .../jewish_calendar/test_config_flow.py | 4 ++-- .../components/jewish_calendar/test_sensor.py | 16 +++++++-------- 8 files changed, 50 insertions(+), 33 deletions(-) create mode 100644 homeassistant/components/jewish_calendar/const.py diff --git a/homeassistant/components/jewish_calendar/__init__.py b/homeassistant/components/jewish_calendar/__init__.py index e1178851e83..bdecaecdcf6 100644 --- a/homeassistant/components/jewish_calendar/__init__.py +++ b/homeassistant/components/jewish_calendar/__init__.py @@ -20,15 +20,17 @@ import homeassistant.helpers.config_validation as cv from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.helpers.typing import ConfigType -DOMAIN = "jewish_calendar" -CONF_DIASPORA = "diaspora" -CONF_CANDLE_LIGHT_MINUTES = "candle_lighting_minutes_before_sunset" -CONF_HAVDALAH_OFFSET_MINUTES = "havdalah_minutes_after_sunset" -DEFAULT_NAME = "Jewish Calendar" -DEFAULT_CANDLE_LIGHT = 18 -DEFAULT_DIASPORA = False -DEFAULT_HAVDALAH_OFFSET_MINUTES = 0 -DEFAULT_LANGUAGE = "english" +from .const import ( + CONF_CANDLE_LIGHT_MINUTES, + CONF_DIASPORA, + CONF_HAVDALAH_OFFSET_MINUTES, + DEFAULT_CANDLE_LIGHT, + DEFAULT_DIASPORA, + DEFAULT_HAVDALAH_OFFSET_MINUTES, + DEFAULT_LANGUAGE, + DEFAULT_NAME, + DOMAIN, +) PLATFORMS: list[Platform] = [Platform.BINARY_SENSOR, Platform.SENSOR] diff --git a/homeassistant/components/jewish_calendar/binary_sensor.py b/homeassistant/components/jewish_calendar/binary_sensor.py index b01dbc2652e..8516b907749 100644 --- a/homeassistant/components/jewish_calendar/binary_sensor.py +++ b/homeassistant/components/jewish_calendar/binary_sensor.py @@ -22,7 +22,7 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType import homeassistant.util.dt as dt_util -from . import DEFAULT_NAME, DOMAIN +from .const import DEFAULT_NAME, DOMAIN @dataclass(frozen=True) diff --git a/homeassistant/components/jewish_calendar/config_flow.py b/homeassistant/components/jewish_calendar/config_flow.py index 5632b7cd584..626dc168db8 100644 --- a/homeassistant/components/jewish_calendar/config_flow.py +++ b/homeassistant/components/jewish_calendar/config_flow.py @@ -32,15 +32,17 @@ from homeassistant.helpers.selector import ( ) from homeassistant.helpers.typing import ConfigType -DOMAIN = "jewish_calendar" -CONF_DIASPORA = "diaspora" -CONF_CANDLE_LIGHT_MINUTES = "candle_lighting_minutes_before_sunset" -CONF_HAVDALAH_OFFSET_MINUTES = "havdalah_minutes_after_sunset" -DEFAULT_NAME = "Jewish Calendar" -DEFAULT_CANDLE_LIGHT = 18 -DEFAULT_DIASPORA = False -DEFAULT_HAVDALAH_OFFSET_MINUTES = 0 -DEFAULT_LANGUAGE = "english" +from .const import ( + CONF_CANDLE_LIGHT_MINUTES, + CONF_DIASPORA, + CONF_HAVDALAH_OFFSET_MINUTES, + DEFAULT_CANDLE_LIGHT, + DEFAULT_DIASPORA, + DEFAULT_HAVDALAH_OFFSET_MINUTES, + DEFAULT_LANGUAGE, + DEFAULT_NAME, + DOMAIN, +) LANGUAGE = [ SelectOptionDict(value="hebrew", label="Hebrew"), diff --git a/homeassistant/components/jewish_calendar/const.py b/homeassistant/components/jewish_calendar/const.py new file mode 100644 index 00000000000..4af76a8927b --- /dev/null +++ b/homeassistant/components/jewish_calendar/const.py @@ -0,0 +1,13 @@ +"""Jewish Calendar constants.""" + +DOMAIN = "jewish_calendar" + +CONF_DIASPORA = "diaspora" +CONF_CANDLE_LIGHT_MINUTES = "candle_lighting_minutes_before_sunset" +CONF_HAVDALAH_OFFSET_MINUTES = "havdalah_minutes_after_sunset" + +DEFAULT_NAME = "Jewish Calendar" +DEFAULT_CANDLE_LIGHT = 18 +DEFAULT_DIASPORA = False +DEFAULT_HAVDALAH_OFFSET_MINUTES = 0 +DEFAULT_LANGUAGE = "english" diff --git a/homeassistant/components/jewish_calendar/sensor.py b/homeassistant/components/jewish_calendar/sensor.py index 1616dc589d7..056fabaa805 100644 --- a/homeassistant/components/jewish_calendar/sensor.py +++ b/homeassistant/components/jewish_calendar/sensor.py @@ -22,7 +22,7 @@ from homeassistant.helpers.sun import get_astral_event_date from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType import homeassistant.util.dt as dt_util -from . import DEFAULT_NAME, DOMAIN +from .const import DEFAULT_NAME, DOMAIN _LOGGER = logging.getLogger(__name__) diff --git a/tests/components/jewish_calendar/conftest.py b/tests/components/jewish_calendar/conftest.py index 5f01ddf8f4a..f7dba01576d 100644 --- a/tests/components/jewish_calendar/conftest.py +++ b/tests/components/jewish_calendar/conftest.py @@ -5,7 +5,7 @@ from unittest.mock import AsyncMock, patch import pytest -from homeassistant.components.jewish_calendar import config_flow +from homeassistant.components.jewish_calendar.const import DEFAULT_NAME, DOMAIN from tests.common import MockConfigEntry @@ -14,8 +14,8 @@ from tests.common import MockConfigEntry def mock_config_entry() -> MockConfigEntry: """Return the default mocked config entry.""" return MockConfigEntry( - title=config_flow.DEFAULT_NAME, - domain=config_flow.DOMAIN, + title=DEFAULT_NAME, + domain=DOMAIN, ) diff --git a/tests/components/jewish_calendar/test_config_flow.py b/tests/components/jewish_calendar/test_config_flow.py index 9d0dec1b83d..ef16742d8d0 100644 --- a/tests/components/jewish_calendar/test_config_flow.py +++ b/tests/components/jewish_calendar/test_config_flow.py @@ -5,11 +5,10 @@ from unittest.mock import AsyncMock import pytest from homeassistant import config_entries, setup -from homeassistant.components.jewish_calendar import ( +from homeassistant.components.jewish_calendar.const import ( CONF_CANDLE_LIGHT_MINUTES, CONF_DIASPORA, CONF_HAVDALAH_OFFSET_MINUTES, - CONF_LANGUAGE, DEFAULT_CANDLE_LIGHT, DEFAULT_DIASPORA, DEFAULT_HAVDALAH_OFFSET_MINUTES, @@ -19,6 +18,7 @@ from homeassistant.components.jewish_calendar import ( from homeassistant.config_entries import SOURCE_USER from homeassistant.const import ( CONF_ELEVATION, + CONF_LANGUAGE, CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME, diff --git a/tests/components/jewish_calendar/test_sensor.py b/tests/components/jewish_calendar/test_sensor.py index 62d5de368d2..4ec132f5e5e 100644 --- a/tests/components/jewish_calendar/test_sensor.py +++ b/tests/components/jewish_calendar/test_sensor.py @@ -4,8 +4,8 @@ from datetime import datetime as dt, timedelta import pytest -from homeassistant.components import jewish_calendar from homeassistant.components.binary_sensor import DOMAIN as SENSOR_DOMAIN +from homeassistant.components.jewish_calendar.const import DOMAIN from homeassistant.core import HomeAssistant from homeassistant.setup import async_setup_component import homeassistant.util.dt as dt_util @@ -17,7 +17,7 @@ from tests.common import MockConfigEntry, async_fire_time_changed async def test_jewish_calendar_min_config(hass: HomeAssistant) -> None: """Test minimum jewish calendar configuration.""" - entry = MockConfigEntry(domain=jewish_calendar.DOMAIN, data={}) + entry = MockConfigEntry(domain=DOMAIN, data={}) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() @@ -26,7 +26,7 @@ async def test_jewish_calendar_min_config(hass: HomeAssistant) -> None: async def test_jewish_calendar_hebrew(hass: HomeAssistant) -> None: """Test jewish calendar sensor with language set to hebrew.""" - entry = MockConfigEntry(domain=jewish_calendar.DOMAIN, data={"language": "hebrew"}) + entry = MockConfigEntry(domain=DOMAIN, data={"language": "hebrew"}) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() @@ -167,7 +167,7 @@ async def test_jewish_calendar_sensor( with alter_time(test_time): entry = MockConfigEntry( - domain=jewish_calendar.DOMAIN, + domain=DOMAIN, data={ "language": language, "diaspora": diaspora, @@ -509,7 +509,7 @@ async def test_shabbat_times_sensor( with alter_time(test_time): entry = MockConfigEntry( - domain=jewish_calendar.DOMAIN, + domain=DOMAIN, data={ "language": language, "diaspora": diaspora, @@ -566,7 +566,7 @@ async def test_omer_sensor(hass: HomeAssistant, test_time, result) -> None: test_time = test_time.replace(tzinfo=dt_util.get_time_zone(hass.config.time_zone)) with alter_time(test_time): - entry = MockConfigEntry(domain=jewish_calendar.DOMAIN) + entry = MockConfigEntry(domain=DOMAIN) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() @@ -600,7 +600,7 @@ async def test_dafyomi_sensor(hass: HomeAssistant, test_time, result) -> None: test_time = test_time.replace(tzinfo=dt_util.get_time_zone(hass.config.time_zone)) with alter_time(test_time): - entry = MockConfigEntry(domain=jewish_calendar.DOMAIN) + entry = MockConfigEntry(domain=DOMAIN) entry.add_to_hass(hass) await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() @@ -620,7 +620,7 @@ async def test_no_discovery_info( assert await async_setup_component( hass, SENSOR_DOMAIN, - {SENSOR_DOMAIN: {"platform": jewish_calendar.DOMAIN}}, + {SENSOR_DOMAIN: {"platform": DOMAIN}}, ) await hass.async_block_till_done() assert SENSOR_DOMAIN in hass.config.components