Improve Jewish calendar entities (#120236)

* By default don't enable all sensors

* Fix tests

* Add entity category

* Set has_entity_name to true

* Revert "Set has_entity_name to true"

This reverts commit 5ebfcde78a.
This commit is contained in:
Tsvi Mostovicz 2024-06-23 18:26:45 +03:00 committed by GitHub
parent 473b3b61eb
commit 2cc34fd7e7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 2 deletions

View file

@ -16,7 +16,7 @@ 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.const import CONF_LANGUAGE, CONF_LOCATION, EntityCategory
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
@ -55,11 +55,13 @@ BINARY_SENSORS: tuple[JewishCalendarBinarySensorEntityDescription, ...] = (
key="erev_shabbat_hag", key="erev_shabbat_hag",
name="Erev Shabbat/Hag", name="Erev Shabbat/Hag",
is_on=lambda state: bool(state.erev_shabbat_chag), is_on=lambda state: bool(state.erev_shabbat_chag),
entity_registry_enabled_default=False,
), ),
JewishCalendarBinarySensorEntityDescription( JewishCalendarBinarySensorEntityDescription(
key="motzei_shabbat_hag", key="motzei_shabbat_hag",
name="Motzei Shabbat/Hag", name="Motzei Shabbat/Hag",
is_on=lambda state: bool(state.motzei_shabbat_chag), is_on=lambda state: bool(state.motzei_shabbat_chag),
entity_registry_enabled_default=False,
), ),
) )
@ -82,6 +84,7 @@ class JewishCalendarBinarySensor(BinarySensorEntity):
"""Representation of an Jewish Calendar binary sensor.""" """Representation of an Jewish Calendar binary sensor."""
_attr_should_poll = False _attr_should_poll = False
_attr_entity_category = EntityCategory.DIAGNOSTIC
entity_description: JewishCalendarBinarySensorEntityDescription entity_description: JewishCalendarBinarySensorEntityDescription
def __init__( def __init__(

View file

@ -15,7 +15,12 @@ from homeassistant.components.sensor import (
SensorEntityDescription, SensorEntityDescription,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_LANGUAGE, CONF_LOCATION, SUN_EVENT_SUNSET from homeassistant.const import (
CONF_LANGUAGE,
CONF_LOCATION,
SUN_EVENT_SUNSET,
EntityCategory,
)
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
@ -54,11 +59,13 @@ INFO_SENSORS: tuple[SensorEntityDescription, ...] = (
key="omer_count", key="omer_count",
name="Day of the Omer", name="Day of the Omer",
icon="mdi:counter", icon="mdi:counter",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="daf_yomi", key="daf_yomi",
name="Daf Yomi", name="Daf Yomi",
icon="mdi:book-open-variant", icon="mdi:book-open-variant",
entity_registry_enabled_default=False,
), ),
) )
@ -67,11 +74,13 @@ TIME_SENSORS: tuple[SensorEntityDescription, ...] = (
key="first_light", key="first_light",
name="Alot Hashachar", # codespell:ignore alot name="Alot Hashachar", # codespell:ignore alot
icon="mdi:weather-sunset-up", icon="mdi:weather-sunset-up",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="talit", key="talit",
name="Talit and Tefillin", name="Talit and Tefillin",
icon="mdi:calendar-clock", icon="mdi:calendar-clock",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="sunrise", key="sunrise",
@ -82,41 +91,49 @@ TIME_SENSORS: tuple[SensorEntityDescription, ...] = (
key="gra_end_shma", key="gra_end_shma",
name='Latest time for Shma Gr"a', name='Latest time for Shma Gr"a',
icon="mdi:calendar-clock", icon="mdi:calendar-clock",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="mga_end_shma", key="mga_end_shma",
name='Latest time for Shma MG"A', name='Latest time for Shma MG"A',
icon="mdi:calendar-clock", icon="mdi:calendar-clock",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="gra_end_tfila", key="gra_end_tfila",
name='Latest time for Tefilla Gr"a', name='Latest time for Tefilla Gr"a',
icon="mdi:calendar-clock", icon="mdi:calendar-clock",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="mga_end_tfila", key="mga_end_tfila",
name='Latest time for Tefilla MG"A', name='Latest time for Tefilla MG"A',
icon="mdi:calendar-clock", icon="mdi:calendar-clock",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="midday", key="midday",
name="Chatzot Hayom", name="Chatzot Hayom",
icon="mdi:calendar-clock", icon="mdi:calendar-clock",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="big_mincha", key="big_mincha",
name="Mincha Gedola", name="Mincha Gedola",
icon="mdi:calendar-clock", icon="mdi:calendar-clock",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="small_mincha", key="small_mincha",
name="Mincha Ketana", name="Mincha Ketana",
icon="mdi:calendar-clock", icon="mdi:calendar-clock",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="plag_mincha", key="plag_mincha",
name="Plag Hamincha", name="Plag Hamincha",
icon="mdi:weather-sunset-down", icon="mdi:weather-sunset-down",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="sunset", key="sunset",
@ -127,21 +144,25 @@ TIME_SENSORS: tuple[SensorEntityDescription, ...] = (
key="first_stars", key="first_stars",
name="T'set Hakochavim", name="T'set Hakochavim",
icon="mdi:weather-night", icon="mdi:weather-night",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="three_stars", key="three_stars",
name="T'set Hakochavim, 3 stars", name="T'set Hakochavim, 3 stars",
icon="mdi:weather-night", icon="mdi:weather-night",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="upcoming_shabbat_candle_lighting", key="upcoming_shabbat_candle_lighting",
name="Upcoming Shabbat Candle Lighting", name="Upcoming Shabbat Candle Lighting",
icon="mdi:candle", icon="mdi:candle",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="upcoming_shabbat_havdalah", key="upcoming_shabbat_havdalah",
name="Upcoming Shabbat Havdalah", name="Upcoming Shabbat Havdalah",
icon="mdi:weather-night", icon="mdi:weather-night",
entity_registry_enabled_default=False,
), ),
SensorEntityDescription( SensorEntityDescription(
key="upcoming_candle_lighting", key="upcoming_candle_lighting",
@ -178,6 +199,8 @@ async def async_setup_entry(
class JewishCalendarSensor(SensorEntity): class JewishCalendarSensor(SensorEntity):
"""Representation of an Jewish calendar sensor.""" """Representation of an Jewish calendar sensor."""
_attr_entity_category = EntityCategory.DIAGNOSTIC
def __init__( def __init__(
self, self,
entry_id: str, entry_id: str,

View file

@ -201,6 +201,7 @@ TEST_IDS = [
TEST_PARAMS, TEST_PARAMS,
ids=TEST_IDS, ids=TEST_IDS,
) )
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_jewish_calendar_sensor( async def test_jewish_calendar_sensor(
hass: HomeAssistant, hass: HomeAssistant,
now, now,
@ -541,6 +542,7 @@ SHABBAT_TEST_IDS = [
SHABBAT_PARAMS, SHABBAT_PARAMS,
ids=SHABBAT_TEST_IDS, ids=SHABBAT_TEST_IDS,
) )
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_shabbat_times_sensor( async def test_shabbat_times_sensor(
hass: HomeAssistant, hass: HomeAssistant,
language, language,
@ -617,6 +619,7 @@ OMER_TEST_IDS = [
@pytest.mark.parametrize(("test_time", "result"), OMER_PARAMS, ids=OMER_TEST_IDS) @pytest.mark.parametrize(("test_time", "result"), OMER_PARAMS, ids=OMER_TEST_IDS)
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_omer_sensor(hass: HomeAssistant, test_time, result) -> None: async def test_omer_sensor(hass: HomeAssistant, test_time, result) -> None:
"""Test Omer Count sensor output.""" """Test Omer Count sensor output."""
test_time = test_time.replace(tzinfo=dt_util.get_time_zone(hass.config.time_zone)) test_time = test_time.replace(tzinfo=dt_util.get_time_zone(hass.config.time_zone))
@ -651,6 +654,7 @@ DAFYOMI_TEST_IDS = [
@pytest.mark.parametrize(("test_time", "result"), DAFYOMI_PARAMS, ids=DAFYOMI_TEST_IDS) @pytest.mark.parametrize(("test_time", "result"), DAFYOMI_PARAMS, ids=DAFYOMI_TEST_IDS)
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
async def test_dafyomi_sensor(hass: HomeAssistant, test_time, result) -> None: async def test_dafyomi_sensor(hass: HomeAssistant, test_time, result) -> None:
"""Test Daf Yomi sensor output.""" """Test Daf Yomi sensor output."""
test_time = test_time.replace(tzinfo=dt_util.get_time_zone(hass.config.time_zone)) test_time = test_time.replace(tzinfo=dt_util.get_time_zone(hass.config.time_zone))