mirror of
https://github.com/home-assistant/core.git
synced 2025-04-29 03:37:51 +00:00
Move holiday info into a single sensor with multiple attributess (#27654)
* Move holiday onfo into a single sensor with multiple attributess * Add tests for holiday attributes
This commit is contained in:
parent
4e25807b7d
commit
2bc6b59e79
@ -20,8 +20,7 @@ SENSOR_TYPES = {
|
|||||||
"data": {
|
"data": {
|
||||||
"date": ["Date", "mdi:judaism"],
|
"date": ["Date", "mdi:judaism"],
|
||||||
"weekly_portion": ["Parshat Hashavua", "mdi:book-open-variant"],
|
"weekly_portion": ["Parshat Hashavua", "mdi:book-open-variant"],
|
||||||
"holiday_name": ["Holiday name", "mdi:calendar-star"],
|
"holiday": ["Holiday", "mdi:calendar-star"],
|
||||||
"holiday_type": ["Holiday type", "mdi:counter"],
|
|
||||||
"omer_count": ["Day of the Omer", "mdi:counter"],
|
"omer_count": ["Day of the Omer", "mdi:counter"],
|
||||||
},
|
},
|
||||||
"time": {
|
"time": {
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "Jewish calendar",
|
"name": "Jewish calendar",
|
||||||
"documentation": "https://www.home-assistant.io/integrations/jewish_calendar",
|
"documentation": "https://www.home-assistant.io/integrations/jewish_calendar",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"hdate==0.9.0"
|
"hdate==0.9.1"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": [
|
"codeowners": [
|
||||||
|
@ -44,6 +44,7 @@ class JewishCalendarSensor(Entity):
|
|||||||
self._havdalah_offset = data["havdalah_offset"]
|
self._havdalah_offset = data["havdalah_offset"]
|
||||||
self._diaspora = data["diaspora"]
|
self._diaspora = data["diaspora"]
|
||||||
self._state = None
|
self._state = None
|
||||||
|
self._holiday_attrs = {}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
@ -103,6 +104,14 @@ class JewishCalendarSensor(Entity):
|
|||||||
hebrew=self._hebrew,
|
hebrew=self._hebrew,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_state_attributes(self):
|
||||||
|
"""Return the state attributes."""
|
||||||
|
if self._type == "holiday":
|
||||||
|
return self._holiday_attrs
|
||||||
|
|
||||||
|
return {}
|
||||||
|
|
||||||
def get_state(self, after_shkia_date, after_tzais_date):
|
def get_state(self, after_shkia_date, after_tzais_date):
|
||||||
"""For a given type of sensor, return the state."""
|
"""For a given type of sensor, return the state."""
|
||||||
# Terminology note: by convention in py-libhdate library, "upcoming"
|
# Terminology note: by convention in py-libhdate library, "upcoming"
|
||||||
@ -112,10 +121,10 @@ class JewishCalendarSensor(Entity):
|
|||||||
if self._type == "weekly_portion":
|
if self._type == "weekly_portion":
|
||||||
# Compute the weekly portion based on the upcoming shabbat.
|
# Compute the weekly portion based on the upcoming shabbat.
|
||||||
return after_tzais_date.upcoming_shabbat.parasha
|
return after_tzais_date.upcoming_shabbat.parasha
|
||||||
if self._type == "holiday_name":
|
if self._type == "holiday":
|
||||||
|
self._holiday_attrs["type"] = after_shkia_date.holiday_type.name
|
||||||
|
self._holiday_attrs["id"] = after_shkia_date.holiday_name
|
||||||
return after_shkia_date.holiday_description
|
return after_shkia_date.holiday_description
|
||||||
if self._type == "holiday_type":
|
|
||||||
return after_shkia_date.holiday_type
|
|
||||||
if self._type == "omer_count":
|
if self._type == "omer_count":
|
||||||
return after_shkia_date.omer_day
|
return after_shkia_date.omer_day
|
||||||
|
|
||||||
|
@ -619,7 +619,7 @@ hass-nabucasa==0.22
|
|||||||
hbmqtt==0.9.5
|
hbmqtt==0.9.5
|
||||||
|
|
||||||
# homeassistant.components.jewish_calendar
|
# homeassistant.components.jewish_calendar
|
||||||
hdate==0.9.0
|
hdate==0.9.1
|
||||||
|
|
||||||
# homeassistant.components.heatmiser
|
# homeassistant.components.heatmiser
|
||||||
heatmiserV3==0.9.1
|
heatmiserV3==0.9.1
|
||||||
|
@ -227,7 +227,7 @@ hass-nabucasa==0.22
|
|||||||
hbmqtt==0.9.5
|
hbmqtt==0.9.5
|
||||||
|
|
||||||
# homeassistant.components.jewish_calendar
|
# homeassistant.components.jewish_calendar
|
||||||
hdate==0.9.0
|
hdate==0.9.1
|
||||||
|
|
||||||
# homeassistant.components.here_travel_time
|
# homeassistant.components.here_travel_time
|
||||||
herepy==0.6.3.1
|
herepy==0.6.3.1
|
||||||
|
@ -42,27 +42,17 @@ TEST_PARAMS = [
|
|||||||
False,
|
False,
|
||||||
'כ"ג אלול ה\' תשע"ח',
|
'כ"ג אלול ה\' תשע"ח',
|
||||||
),
|
),
|
||||||
(
|
(dt(2018, 9, 10), "UTC", 31.778, 35.235, "hebrew", "holiday", False, "א' ראש השנה"),
|
||||||
dt(2018, 9, 10),
|
|
||||||
"UTC",
|
|
||||||
31.778,
|
|
||||||
35.235,
|
|
||||||
"hebrew",
|
|
||||||
"holiday_name",
|
|
||||||
False,
|
|
||||||
"א' ראש השנה",
|
|
||||||
),
|
|
||||||
(
|
(
|
||||||
dt(2018, 9, 10),
|
dt(2018, 9, 10),
|
||||||
"UTC",
|
"UTC",
|
||||||
31.778,
|
31.778,
|
||||||
35.235,
|
35.235,
|
||||||
"english",
|
"english",
|
||||||
"holiday_name",
|
"holiday",
|
||||||
False,
|
False,
|
||||||
"Rosh Hashana I",
|
"Rosh Hashana I",
|
||||||
),
|
),
|
||||||
(dt(2018, 9, 10), "UTC", 31.778, 35.235, "english", "holiday_type", False, 1),
|
|
||||||
(
|
(
|
||||||
dt(2018, 9, 8),
|
dt(2018, 9, 8),
|
||||||
"UTC",
|
"UTC",
|
||||||
@ -128,9 +118,8 @@ TEST_PARAMS = [
|
|||||||
TEST_IDS = [
|
TEST_IDS = [
|
||||||
"date_output",
|
"date_output",
|
||||||
"date_output_hebrew",
|
"date_output_hebrew",
|
||||||
"holiday_name",
|
"holiday",
|
||||||
"holiday_name_english",
|
"holiday_english",
|
||||||
"holiday_type",
|
|
||||||
"torah_reading",
|
"torah_reading",
|
||||||
"first_stars_ny",
|
"first_stars_ny",
|
||||||
"first_stars_jerusalem",
|
"first_stars_jerusalem",
|
||||||
@ -187,7 +176,12 @@ async def test_jewish_calendar_sensor(
|
|||||||
dt_util.as_utc(time_zone.localize(result)) if isinstance(result, dt) else result
|
dt_util.as_utc(time_zone.localize(result)) if isinstance(result, dt) else result
|
||||||
)
|
)
|
||||||
|
|
||||||
assert hass.states.get(f"sensor.test_{sensor}").state == str(result)
|
sensor_object = hass.states.get(f"sensor.test_{sensor}")
|
||||||
|
assert sensor_object.state == str(result)
|
||||||
|
|
||||||
|
if sensor == "holiday":
|
||||||
|
assert sensor_object.attributes.get("type") == "YOM_TOV"
|
||||||
|
assert sensor_object.attributes.get("id") == "rosh_hashana_i"
|
||||||
|
|
||||||
|
|
||||||
SHABBAT_PARAMS = [
|
SHABBAT_PARAMS = [
|
||||||
@ -256,8 +250,8 @@ SHABBAT_PARAMS = [
|
|||||||
"english_upcoming_shabbat_havdalah": dt(2018, 9, 15, 19, 50),
|
"english_upcoming_shabbat_havdalah": dt(2018, 9, 15, 19, 50),
|
||||||
"english_parshat_hashavua": "Vayeilech",
|
"english_parshat_hashavua": "Vayeilech",
|
||||||
"hebrew_parshat_hashavua": "וילך",
|
"hebrew_parshat_hashavua": "וילך",
|
||||||
"english_holiday_name": "Erev Rosh Hashana",
|
"english_holiday": "Erev Rosh Hashana",
|
||||||
"hebrew_holiday_name": "ערב ראש השנה",
|
"hebrew_holiday": "ערב ראש השנה",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
make_nyc_test_params(
|
make_nyc_test_params(
|
||||||
@ -269,8 +263,8 @@ SHABBAT_PARAMS = [
|
|||||||
"english_upcoming_shabbat_havdalah": dt(2018, 9, 15, 19, 50),
|
"english_upcoming_shabbat_havdalah": dt(2018, 9, 15, 19, 50),
|
||||||
"english_parshat_hashavua": "Vayeilech",
|
"english_parshat_hashavua": "Vayeilech",
|
||||||
"hebrew_parshat_hashavua": "וילך",
|
"hebrew_parshat_hashavua": "וילך",
|
||||||
"english_holiday_name": "Rosh Hashana I",
|
"english_holiday": "Rosh Hashana I",
|
||||||
"hebrew_holiday_name": "א' ראש השנה",
|
"hebrew_holiday": "א' ראש השנה",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
make_nyc_test_params(
|
make_nyc_test_params(
|
||||||
@ -282,8 +276,8 @@ SHABBAT_PARAMS = [
|
|||||||
"english_upcoming_shabbat_havdalah": dt(2018, 9, 15, 19, 50),
|
"english_upcoming_shabbat_havdalah": dt(2018, 9, 15, 19, 50),
|
||||||
"english_parshat_hashavua": "Vayeilech",
|
"english_parshat_hashavua": "Vayeilech",
|
||||||
"hebrew_parshat_hashavua": "וילך",
|
"hebrew_parshat_hashavua": "וילך",
|
||||||
"english_holiday_name": "Rosh Hashana II",
|
"english_holiday": "Rosh Hashana II",
|
||||||
"hebrew_holiday_name": "ב' ראש השנה",
|
"hebrew_holiday": "ב' ראש השנה",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
make_nyc_test_params(
|
make_nyc_test_params(
|
||||||
@ -306,8 +300,8 @@ SHABBAT_PARAMS = [
|
|||||||
"english_upcoming_shabbat_havdalah": dt(2018, 10, 6, 19, 13),
|
"english_upcoming_shabbat_havdalah": dt(2018, 10, 6, 19, 13),
|
||||||
"english_parshat_hashavua": "Bereshit",
|
"english_parshat_hashavua": "Bereshit",
|
||||||
"hebrew_parshat_hashavua": "בראשית",
|
"hebrew_parshat_hashavua": "בראשית",
|
||||||
"english_holiday_name": "Hoshana Raba",
|
"english_holiday": "Hoshana Raba",
|
||||||
"hebrew_holiday_name": "הושענא רבה",
|
"hebrew_holiday": "הושענא רבה",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
make_nyc_test_params(
|
make_nyc_test_params(
|
||||||
@ -319,8 +313,8 @@ SHABBAT_PARAMS = [
|
|||||||
"english_upcoming_shabbat_havdalah": dt(2018, 10, 6, 19, 13),
|
"english_upcoming_shabbat_havdalah": dt(2018, 10, 6, 19, 13),
|
||||||
"english_parshat_hashavua": "Bereshit",
|
"english_parshat_hashavua": "Bereshit",
|
||||||
"hebrew_parshat_hashavua": "בראשית",
|
"hebrew_parshat_hashavua": "בראשית",
|
||||||
"english_holiday_name": "Shmini Atzeret",
|
"english_holiday": "Shmini Atzeret",
|
||||||
"hebrew_holiday_name": "שמיני עצרת",
|
"hebrew_holiday": "שמיני עצרת",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
make_nyc_test_params(
|
make_nyc_test_params(
|
||||||
@ -332,8 +326,8 @@ SHABBAT_PARAMS = [
|
|||||||
"english_upcoming_shabbat_havdalah": dt(2018, 10, 6, 19, 13),
|
"english_upcoming_shabbat_havdalah": dt(2018, 10, 6, 19, 13),
|
||||||
"english_parshat_hashavua": "Bereshit",
|
"english_parshat_hashavua": "Bereshit",
|
||||||
"hebrew_parshat_hashavua": "בראשית",
|
"hebrew_parshat_hashavua": "בראשית",
|
||||||
"english_holiday_name": "Simchat Torah",
|
"english_holiday": "Simchat Torah",
|
||||||
"hebrew_holiday_name": "שמחת תורה",
|
"hebrew_holiday": "שמחת תורה",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
make_jerusalem_test_params(
|
make_jerusalem_test_params(
|
||||||
@ -345,8 +339,8 @@ SHABBAT_PARAMS = [
|
|||||||
"english_upcoming_shabbat_havdalah": dt(2018, 10, 6, 18, 56),
|
"english_upcoming_shabbat_havdalah": dt(2018, 10, 6, 18, 56),
|
||||||
"english_parshat_hashavua": "Bereshit",
|
"english_parshat_hashavua": "Bereshit",
|
||||||
"hebrew_parshat_hashavua": "בראשית",
|
"hebrew_parshat_hashavua": "בראשית",
|
||||||
"english_holiday_name": "Hoshana Raba",
|
"english_holiday": "Hoshana Raba",
|
||||||
"hebrew_holiday_name": "הושענא רבה",
|
"hebrew_holiday": "הושענא רבה",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
make_jerusalem_test_params(
|
make_jerusalem_test_params(
|
||||||
@ -358,8 +352,8 @@ SHABBAT_PARAMS = [
|
|||||||
"english_upcoming_shabbat_havdalah": dt(2018, 10, 6, 18, 56),
|
"english_upcoming_shabbat_havdalah": dt(2018, 10, 6, 18, 56),
|
||||||
"english_parshat_hashavua": "Bereshit",
|
"english_parshat_hashavua": "Bereshit",
|
||||||
"hebrew_parshat_hashavua": "בראשית",
|
"hebrew_parshat_hashavua": "בראשית",
|
||||||
"english_holiday_name": "Shmini Atzeret",
|
"english_holiday": "Shmini Atzeret",
|
||||||
"hebrew_holiday_name": "שמיני עצרת",
|
"hebrew_holiday": "שמיני עצרת",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
make_jerusalem_test_params(
|
make_jerusalem_test_params(
|
||||||
@ -382,8 +376,8 @@ SHABBAT_PARAMS = [
|
|||||||
"english_upcoming_shabbat_havdalah": "unknown",
|
"english_upcoming_shabbat_havdalah": "unknown",
|
||||||
"english_parshat_hashavua": "Bamidbar",
|
"english_parshat_hashavua": "Bamidbar",
|
||||||
"hebrew_parshat_hashavua": "במדבר",
|
"hebrew_parshat_hashavua": "במדבר",
|
||||||
"english_holiday_name": "Erev Shavuot",
|
"english_holiday": "Erev Shavuot",
|
||||||
"hebrew_holiday_name": "ערב שבועות",
|
"hebrew_holiday": "ערב שבועות",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
make_nyc_test_params(
|
make_nyc_test_params(
|
||||||
@ -395,8 +389,8 @@ SHABBAT_PARAMS = [
|
|||||||
"english_upcoming_shabbat_havdalah": dt(2016, 6, 18, 21, 19),
|
"english_upcoming_shabbat_havdalah": dt(2016, 6, 18, 21, 19),
|
||||||
"english_parshat_hashavua": "Nasso",
|
"english_parshat_hashavua": "Nasso",
|
||||||
"hebrew_parshat_hashavua": "נשא",
|
"hebrew_parshat_hashavua": "נשא",
|
||||||
"english_holiday_name": "Shavuot",
|
"english_holiday": "Shavuot",
|
||||||
"hebrew_holiday_name": "שבועות",
|
"hebrew_holiday": "שבועות",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
make_jerusalem_test_params(
|
make_jerusalem_test_params(
|
||||||
@ -408,8 +402,8 @@ SHABBAT_PARAMS = [
|
|||||||
"english_upcoming_shabbat_havdalah": dt(2017, 9, 23, 19, 13),
|
"english_upcoming_shabbat_havdalah": dt(2017, 9, 23, 19, 13),
|
||||||
"english_parshat_hashavua": "Ha'Azinu",
|
"english_parshat_hashavua": "Ha'Azinu",
|
||||||
"hebrew_parshat_hashavua": "האזינו",
|
"hebrew_parshat_hashavua": "האזינו",
|
||||||
"english_holiday_name": "Rosh Hashana I",
|
"english_holiday": "Rosh Hashana I",
|
||||||
"hebrew_holiday_name": "א' ראש השנה",
|
"hebrew_holiday": "א' ראש השנה",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
make_jerusalem_test_params(
|
make_jerusalem_test_params(
|
||||||
@ -421,8 +415,8 @@ SHABBAT_PARAMS = [
|
|||||||
"english_upcoming_shabbat_havdalah": dt(2017, 9, 23, 19, 13),
|
"english_upcoming_shabbat_havdalah": dt(2017, 9, 23, 19, 13),
|
||||||
"english_parshat_hashavua": "Ha'Azinu",
|
"english_parshat_hashavua": "Ha'Azinu",
|
||||||
"hebrew_parshat_hashavua": "האזינו",
|
"hebrew_parshat_hashavua": "האזינו",
|
||||||
"english_holiday_name": "Rosh Hashana II",
|
"english_holiday": "Rosh Hashana II",
|
||||||
"hebrew_holiday_name": "ב' ראש השנה",
|
"hebrew_holiday": "ב' ראש השנה",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
make_jerusalem_test_params(
|
make_jerusalem_test_params(
|
||||||
@ -434,8 +428,8 @@ SHABBAT_PARAMS = [
|
|||||||
"english_upcoming_shabbat_havdalah": dt(2017, 9, 23, 19, 13),
|
"english_upcoming_shabbat_havdalah": dt(2017, 9, 23, 19, 13),
|
||||||
"english_parshat_hashavua": "Ha'Azinu",
|
"english_parshat_hashavua": "Ha'Azinu",
|
||||||
"hebrew_parshat_hashavua": "האזינו",
|
"hebrew_parshat_hashavua": "האזינו",
|
||||||
"english_holiday_name": "",
|
"english_holiday": "",
|
||||||
"hebrew_holiday_name": "",
|
"hebrew_holiday": "",
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user