mirror of
https://github.com/home-assistant/core.git
synced 2025-07-12 15:57:06 +00:00
Change strings to const in Jewish Calendar (#118274)
This commit is contained in:
parent
4f7a91828e
commit
ea91f7a5aa
@ -10,6 +10,7 @@ from homeassistant.const import (
|
|||||||
CONF_ELEVATION,
|
CONF_ELEVATION,
|
||||||
CONF_LANGUAGE,
|
CONF_LANGUAGE,
|
||||||
CONF_LATITUDE,
|
CONF_LATITUDE,
|
||||||
|
CONF_LOCATION,
|
||||||
CONF_LONGITUDE,
|
CONF_LONGITUDE,
|
||||||
CONF_NAME,
|
CONF_NAME,
|
||||||
CONF_TIME_ZONE,
|
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
|
location, language, candle_lighting_offset, havdalah_offset
|
||||||
)
|
)
|
||||||
hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = {
|
hass.data.setdefault(DOMAIN, {})[config_entry.entry_id] = {
|
||||||
"language": language,
|
CONF_LANGUAGE: language,
|
||||||
"diaspora": diaspora,
|
CONF_DIASPORA: diaspora,
|
||||||
"location": location,
|
CONF_LOCATION: location,
|
||||||
"candle_lighting_offset": candle_lighting_offset,
|
CONF_CANDLE_LIGHT_MINUTES: candle_lighting_offset,
|
||||||
"havdalah_offset": havdalah_offset,
|
CONF_HAVDALAH_OFFSET_MINUTES: havdalah_offset,
|
||||||
"prefix": prefix,
|
"prefix": prefix,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,12 +16,18 @@ from homeassistant.components.binary_sensor import (
|
|||||||
BinarySensorEntityDescription,
|
BinarySensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
from homeassistant.const import CONF_LANGUAGE, CONF_LOCATION
|
||||||
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
from homeassistant.core import CALLBACK_TYPE, HomeAssistant, callback
|
||||||
from homeassistant.helpers import event
|
from homeassistant.helpers import event
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
import homeassistant.util.dt as dt_util
|
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)
|
@dataclass(frozen=True)
|
||||||
@ -87,10 +93,10 @@ class JewishCalendarBinarySensor(BinarySensorEntity):
|
|||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_name = f"{DEFAULT_NAME} {description.name}"
|
self._attr_name = f"{DEFAULT_NAME} {description.name}"
|
||||||
self._attr_unique_id = f'{data["prefix"]}_{description.key}'
|
self._attr_unique_id = f'{data["prefix"]}_{description.key}'
|
||||||
self._location = data["location"]
|
self._location = data[CONF_LOCATION]
|
||||||
self._hebrew = data["language"] == "hebrew"
|
self._hebrew = data[CONF_LANGUAGE] == "hebrew"
|
||||||
self._candle_lighting_offset = data["candle_lighting_offset"]
|
self._candle_lighting_offset = data[CONF_CANDLE_LIGHT_MINUTES]
|
||||||
self._havdalah_offset = data["havdalah_offset"]
|
self._havdalah_offset = data[CONF_HAVDALAH_OFFSET_MINUTES]
|
||||||
self._update_unsub: CALLBACK_TYPE | None = None
|
self._update_unsub: CALLBACK_TYPE | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -15,13 +15,19 @@ from homeassistant.components.sensor import (
|
|||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
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.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.sun import get_astral_event_date
|
from homeassistant.helpers.sun import get_astral_event_date
|
||||||
import homeassistant.util.dt as dt_util
|
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__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -169,11 +175,11 @@ class JewishCalendarSensor(SensorEntity):
|
|||||||
self.entity_description = description
|
self.entity_description = description
|
||||||
self._attr_name = f"{DEFAULT_NAME} {description.name}"
|
self._attr_name = f"{DEFAULT_NAME} {description.name}"
|
||||||
self._attr_unique_id = f'{data["prefix"]}_{description.key}'
|
self._attr_unique_id = f'{data["prefix"]}_{description.key}'
|
||||||
self._location = data["location"]
|
self._location = data[CONF_LOCATION]
|
||||||
self._hebrew = data["language"] == "hebrew"
|
self._hebrew = data[CONF_LANGUAGE] == "hebrew"
|
||||||
self._candle_lighting_offset = data["candle_lighting_offset"]
|
self._candle_lighting_offset = data[CONF_CANDLE_LIGHT_MINUTES]
|
||||||
self._havdalah_offset = data["havdalah_offset"]
|
self._havdalah_offset = data[CONF_HAVDALAH_OFFSET_MINUTES]
|
||||||
self._diaspora = data["diaspora"]
|
self._diaspora = data[CONF_DIASPORA]
|
||||||
self._holiday_attrs: dict[str, str] = {}
|
self._holiday_attrs: dict[str, str] = {}
|
||||||
|
|
||||||
async def async_update(self) -> None:
|
async def async_update(self) -> None:
|
||||||
|
@ -5,9 +5,14 @@ import logging
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components import jewish_calendar
|
|
||||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
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.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
@ -187,12 +192,12 @@ async def test_issur_melacha_sensor(
|
|||||||
|
|
||||||
with alter_time(test_time):
|
with alter_time(test_time):
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=jewish_calendar.DOMAIN,
|
domain=DOMAIN,
|
||||||
data={
|
data={
|
||||||
"language": "english",
|
CONF_LANGUAGE: "english",
|
||||||
"diaspora": diaspora,
|
CONF_DIASPORA: diaspora,
|
||||||
"candle_lighting_minutes_before_sunset": candle_lighting,
|
CONF_CANDLE_LIGHT_MINUTES: candle_lighting,
|
||||||
"havdalah_minutes_after_sunset": havdalah,
|
CONF_HAVDALAH_OFFSET_MINUTES: havdalah,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
@ -259,12 +264,12 @@ async def test_issur_melacha_sensor_update(
|
|||||||
|
|
||||||
with alter_time(test_time):
|
with alter_time(test_time):
|
||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=jewish_calendar.DOMAIN,
|
domain=DOMAIN,
|
||||||
data={
|
data={
|
||||||
"language": "english",
|
CONF_LANGUAGE: "english",
|
||||||
"diaspora": diaspora,
|
CONF_DIASPORA: diaspora,
|
||||||
"candle_lighting_minutes_before_sunset": candle_lighting,
|
CONF_CANDLE_LIGHT_MINUTES: candle_lighting,
|
||||||
"havdalah_minutes_after_sunset": havdalah,
|
CONF_HAVDALAH_OFFSET_MINUTES: havdalah,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
@ -297,7 +302,7 @@ async def test_no_discovery_info(
|
|||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
BINARY_SENSOR_DOMAIN,
|
BINARY_SENSOR_DOMAIN,
|
||||||
{BINARY_SENSOR_DOMAIN: {"platform": jewish_calendar.DOMAIN}},
|
{BINARY_SENSOR_DOMAIN: {CONF_PLATFORM: DOMAIN}},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert BINARY_SENSOR_DOMAIN in hass.config.components
|
assert BINARY_SENSOR_DOMAIN in hass.config.components
|
||||||
|
@ -5,7 +5,13 @@ from datetime import datetime as dt, timedelta
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import DOMAIN as SENSOR_DOMAIN
|
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.core import HomeAssistant
|
||||||
from homeassistant.setup import async_setup_component
|
from homeassistant.setup import async_setup_component
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
@ -169,8 +175,8 @@ async def test_jewish_calendar_sensor(
|
|||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
data={
|
data={
|
||||||
"language": language,
|
CONF_LANGUAGE: language,
|
||||||
"diaspora": diaspora,
|
CONF_DIASPORA: diaspora,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
@ -511,10 +517,10 @@ async def test_shabbat_times_sensor(
|
|||||||
entry = MockConfigEntry(
|
entry = MockConfigEntry(
|
||||||
domain=DOMAIN,
|
domain=DOMAIN,
|
||||||
data={
|
data={
|
||||||
"language": language,
|
CONF_LANGUAGE: language,
|
||||||
"diaspora": diaspora,
|
CONF_DIASPORA: diaspora,
|
||||||
"candle_lighting_minutes_before_sunset": candle_lighting,
|
CONF_CANDLE_LIGHT_MINUTES: candle_lighting,
|
||||||
"havdalah_minutes_after_sunset": havdalah,
|
CONF_HAVDALAH_OFFSET_MINUTES: havdalah,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
entry.add_to_hass(hass)
|
entry.add_to_hass(hass)
|
||||||
@ -620,7 +626,7 @@ async def test_no_discovery_info(
|
|||||||
assert await async_setup_component(
|
assert await async_setup_component(
|
||||||
hass,
|
hass,
|
||||||
SENSOR_DOMAIN,
|
SENSOR_DOMAIN,
|
||||||
{SENSOR_DOMAIN: {"platform": DOMAIN}},
|
{SENSOR_DOMAIN: {CONF_PLATFORM: DOMAIN}},
|
||||||
)
|
)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert SENSOR_DOMAIN in hass.config.components
|
assert SENSOR_DOMAIN in hass.config.components
|
||||||
|
Loading…
x
Reference in New Issue
Block a user