Change strings to const in Jewish Calendar (#118274)

This commit is contained in:
Tsvi Mostovicz 2024-05-28 08:49:39 +03:00 committed by GitHub
parent 4f7a91828e
commit ea91f7a5aa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 62 additions and 38 deletions

View File

@ -10,6 +10,7 @@ from homeassistant.const import (
CONF_ELEVATION,
CONF_LANGUAGE,
CONF_LATITUDE,
CONF_LOCATION,
CONF_LONGITUDE,
CONF_NAME,
CONF_TIME_ZONE,
@ -134,11 +135,11 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
location, language, candle_lighting_offset, havdalah_offset
)
hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = {
"language": language,
"diaspora": diaspora,
"location": location,
"candle_lighting_offset": candle_lighting_offset,
"havdalah_offset": havdalah_offset,
CONF_LANGUAGE: language,
CONF_DIASPORA: diaspora,
CONF_LOCATION: location,
CONF_CANDLE_LIGHT_MINUTES: candle_lighting_offset,
CONF_HAVDALAH_OFFSET_MINUTES: havdalah_offset,
"prefix": prefix,
}

View File

@ -16,12 +16,18 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_LANGUAGE, CONF_LOCATION
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
from homeassistant.helpers import event
from homeassistant.helpers.entity_platform import AddEntitiesCallback
import homeassistant.util.dt as dt_util
from .const import DEFAULT_NAME, DOMAIN
from .const import (
CONF_CANDLE_LIGHT_MINUTES,
CONF_HAVDALAH_OFFSET_MINUTES,
DEFAULT_NAME,
DOMAIN,
)
@dataclass(frozen=True)
@ -87,10 +93,10 @@ class JewishCalendarBinarySensor(BinarySensorEntity):
self.entity_description = description
self._attr_name = f"{DEFAULT_NAME} {description.name}"
self._attr_unique_id = f'{data["prefix"]}_{description.key}'
self._location = data["location"]
self._hebrew = data["language"] == "hebrew"
self._candle_lighting_offset = data["candle_lighting_offset"]
self._havdalah_offset = data["havdalah_offset"]
self._location = data[CONF_LOCATION]
self._hebrew = data[CONF_LANGUAGE] == "hebrew"
self._candle_lighting_offset = data[CONF_CANDLE_LIGHT_MINUTES]
self._havdalah_offset = data[CONF_HAVDALAH_OFFSET_MINUTES]
self._update_unsub: CALLBACK_TYPE | None = None
@property

View File

@ -15,13 +15,19 @@ from homeassistant.components.sensor import (
SensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import SUN_EVENT_SUNSET
from homeassistant.const import CONF_LANGUAGE, CONF_LOCATION, SUN_EVENT_SUNSET
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.sun import get_astral_event_date
import homeassistant.util.dt as dt_util
from .const import DEFAULT_NAME, DOMAIN
from .const import (
CONF_CANDLE_LIGHT_MINUTES,
CONF_DIASPORA,
CONF_HAVDALAH_OFFSET_MINUTES,
DEFAULT_NAME,
DOMAIN,
)
_LOGGER = logging.getLogger(__name__)
@ -169,11 +175,11 @@ class JewishCalendarSensor(SensorEntity):
self.entity_description = description
self._attr_name = f"{DEFAULT_NAME} {description.name}"
self._attr_unique_id = f'{data["prefix"]}_{description.key}'
self._location = data["location"]
self._hebrew = data["language"] == "hebrew"
self._candle_lighting_offset = data["candle_lighting_offset"]
self._havdalah_offset = data["havdalah_offset"]
self._diaspora = data["diaspora"]
self._location = data[CONF_LOCATION]
self._hebrew = data[CONF_LANGUAGE] == "hebrew"
self._candle_lighting_offset = data[CONF_CANDLE_LIGHT_MINUTES]
self._havdalah_offset = data[CONF_HAVDALAH_OFFSET_MINUTES]
self._diaspora = data[CONF_DIASPORA]
self._holiday_attrs: dict[str, str] = {}
async def async_update(self) -> None:

View File

@ -5,9 +5,14 @@ import logging
import pytest
from homeassistant.components import jewish_calendar
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
from homeassistant.const import STATE_OFF, STATE_ON
from homeassistant.components.jewish_calendar.const import (
CONF_CANDLE_LIGHT_MINUTES,
CONF_DIASPORA,
CONF_HAVDALAH_OFFSET_MINUTES,
DOMAIN,
)
from homeassistant.const import CONF_LANGUAGE, CONF_PLATFORM, STATE_OFF, STATE_ON
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
@ -187,12 +192,12 @@ async def test_issur_melacha_sensor(
with alter_time(test_time):
entry = MockConfigEntry(
domain=jewish_calendar.DOMAIN,
domain=DOMAIN,
data={
"language": "english",
"diaspora": diaspora,
"candle_lighting_minutes_before_sunset": candle_lighting,
"havdalah_minutes_after_sunset": havdalah,
CONF_LANGUAGE: "english",
CONF_DIASPORA: diaspora,
CONF_CANDLE_LIGHT_MINUTES: candle_lighting,
CONF_HAVDALAH_OFFSET_MINUTES: havdalah,
},
)
entry.add_to_hass(hass)
@ -259,12 +264,12 @@ async def test_issur_melacha_sensor_update(
with alter_time(test_time):
entry = MockConfigEntry(
domain=jewish_calendar.DOMAIN,
domain=DOMAIN,
data={
"language": "english",
"diaspora": diaspora,
"candle_lighting_minutes_before_sunset": candle_lighting,
"havdalah_minutes_after_sunset": havdalah,
CONF_LANGUAGE: "english",
CONF_DIASPORA: diaspora,
CONF_CANDLE_LIGHT_MINUTES: candle_lighting,
CONF_HAVDALAH_OFFSET_MINUTES: havdalah,
},
)
entry.add_to_hass(hass)
@ -297,7 +302,7 @@ async def test_no_discovery_info(
assert await async_setup_component(
hass,
BINARY_SENSOR_DOMAIN,
{BINARY_SENSOR_DOMAIN: {"platform": jewish_calendar.DOMAIN}},
{BINARY_SENSOR_DOMAIN: {CONF_PLATFORM: DOMAIN}},
)
await hass.async_block_till_done()
assert BINARY_SENSOR_DOMAIN in hass.config.components

View File

@ -5,7 +5,13 @@ from datetime import datetime as dt, timedelta
import pytest
from homeassistant.components.binary_sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.components.jewish_calendar.const import DOMAIN
from homeassistant.components.jewish_calendar.const import (
CONF_CANDLE_LIGHT_MINUTES,
CONF_DIASPORA,
CONF_HAVDALAH_OFFSET_MINUTES,
DOMAIN,
)
from homeassistant.const import CONF_LANGUAGE, CONF_PLATFORM
from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
import homeassistant.util.dt as dt_util
@ -169,8 +175,8 @@ async def test_jewish_calendar_sensor(
entry = MockConfigEntry(
domain=DOMAIN,
data={
"language": language,
"diaspora": diaspora,
CONF_LANGUAGE: language,
CONF_DIASPORA: diaspora,
},
)
entry.add_to_hass(hass)
@ -511,10 +517,10 @@ async def test_shabbat_times_sensor(
entry = MockConfigEntry(
domain=DOMAIN,
data={
"language": language,
"diaspora": diaspora,
"candle_lighting_minutes_before_sunset": candle_lighting,
"havdalah_minutes_after_sunset": havdalah,
CONF_LANGUAGE: language,
CONF_DIASPORA: diaspora,
CONF_CANDLE_LIGHT_MINUTES: candle_lighting,
CONF_HAVDALAH_OFFSET_MINUTES: havdalah,
},
)
entry.add_to_hass(hass)
@ -620,7 +626,7 @@ async def test_no_discovery_info(
assert await async_setup_component(
hass,
SENSOR_DOMAIN,
{SENSOR_DOMAIN: {"platform": DOMAIN}},
{SENSOR_DOMAIN: {CONF_PLATFORM: DOMAIN}},
)
await hass.async_block_till_done()
assert SENSOR_DOMAIN in hass.config.components