-
-
Notifications
You must be signed in to change notification settings - Fork 38.2k
Jewish calendar binary sensor #26200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
a4433fd
Move jewish calendar to its own platform
tsvi ee155a5
Fix tests for Jewish Calendar platform
tsvi 5e1c8dc
Get sensors to update during test
tsvi 6b9c0af
Use hass.config.set_time_zone instead of directly calling set_default…
tsvi 3bbf625
Cleanup log messages
tsvi 65d29c4
Rename result from weekly_portion to parshat_hashavua
tsvi a467dbd
Fix english/hebrew tests
tsvi a766b72
Fix updating of issue melacha binary sensor
tsvi d97a599
Fix docstrings of binary sensor
tsvi f2d3bc5
Reset timezones before and after each test
tsvi 9a66823
Use correct entity_id for day of the omer tests
tsvi 156daab
Fix omer tests
tsvi 42ede7a
Cleanup and rearrange tests
tsvi ff4cc58
Remove the old issur_melacha_in_effect sensor
tsvi 4d65727
Rename variables to make the code clearer
tsvi 096199c
Use dt_util.set_default_time_zone instead of hass.config.set_time_zon…
tsvi 27b1aac
Remove should_poll set to false (accidental copy/paste)
tsvi ca03279
Remove _LOGGER messaging during init and impossible cases
tsvi 73ddbba
Move binary tests to standalone test functions
tsvi acd6ddb
Collect entities before calling add_entities
tsvi 6b72775
Fix pylint errors
tsvi 9677156
Simplify logic in binary sensor until a future a PR adds more sensors
tsvi 779065c
Rename test_id holyness to holiday_type
tsvi be0ec18
Fix time zone for binary sensor tests
tsvi 1ccca66
Don't use unnecessary alter_time in sensors
tsvi 3960547
Simply set hass.config.time_zone instead of murking around with globa…
tsvi 77508c6
Use async_fire_time_changed instead of directly calling async_update_…
tsvi 7c92dd6
Removing debug messaging during init of integration
tsvi a71ed76
Capitalize constants
tsvi 7329208
Collect all Entities before calling async_add_entities
tsvi 26fb77f
Revert "Don't use unnecessary alter_time in sensors"
tsvi 05797b9
Use test time instead of utc_now
tsvi 781adb8
Remove superfluous testing
tsvi b0a12a6
Fix triggering of time changed
tsvi e39e624
Fix failing tests due to side-effects
tsvi 879e2f6
Use dt_util.as_utc instead of reimplementing it's functionality
tsvi 611b668
Use dict[key] for default values
tsvi 726914c
Move 3rd party imports to the top of the module
tsvi d0ad1c8
Fix imports
tsvi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,110 @@ | ||
| """The jewish_calendar component.""" | ||
| import logging | ||
|
|
||
| import voluptuous as vol | ||
|
|
||
| import hdate | ||
|
|
||
| from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME | ||
| from homeassistant.helpers.discovery import async_load_platform | ||
| import homeassistant.helpers.config_validation as cv | ||
|
|
||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
| DOMAIN = "jewish_calendar" | ||
|
|
||
| SENSOR_TYPES = { | ||
| "binary": { | ||
| "issur_melacha_in_effect": ["Issur Melacha in Effect", "mdi:power-plug-off"] | ||
| }, | ||
| "data": { | ||
| "date": ["Date", "mdi:judaism"], | ||
| "weekly_portion": ["Parshat Hashavua", "mdi:book-open-variant"], | ||
| "holiday_name": ["Holiday name", "mdi:calendar-star"], | ||
| "holiday_type": ["Holiday type", "mdi:counter"], | ||
| "omer_count": ["Day of the Omer", "mdi:counter"], | ||
| }, | ||
| "time": { | ||
| "first_light": ["Alot Hashachar", "mdi:weather-sunset-up"], | ||
| "gra_end_shma": ['Latest time for Shm"a GR"A', "mdi:calendar-clock"], | ||
| "mga_end_shma": ['Latest time for Shm"a MG"A', "mdi:calendar-clock"], | ||
| "plag_mincha": ["Plag Hamincha", "mdi:weather-sunset-down"], | ||
| "first_stars": ["T'set Hakochavim", "mdi:weather-night"], | ||
| "upcoming_shabbat_candle_lighting": [ | ||
| "Upcoming Shabbat Candle Lighting", | ||
| "mdi:candle", | ||
| ], | ||
| "upcoming_shabbat_havdalah": ["Upcoming Shabbat Havdalah", "mdi:weather-night"], | ||
| "upcoming_candle_lighting": ["Upcoming Candle Lighting", "mdi:candle"], | ||
| "upcoming_havdalah": ["Upcoming Havdalah", "mdi:weather-night"], | ||
| }, | ||
| } | ||
|
|
||
| CONF_DIASPORA = "diaspora" | ||
| CONF_LANGUAGE = "language" | ||
| CONF_CANDLE_LIGHT_MINUTES = "candle_lighting_minutes_before_sunset" | ||
| CONF_HAVDALAH_OFFSET_MINUTES = "havdalah_minutes_after_sunset" | ||
|
|
||
| CANDLE_LIGHT_DEFAULT = 18 | ||
|
|
||
| DEFAULT_NAME = "Jewish Calendar" | ||
|
|
||
| CONFIG_SCHEMA = vol.Schema( | ||
| { | ||
| DOMAIN: vol.Schema( | ||
| { | ||
| vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string, | ||
| vol.Optional(CONF_DIASPORA, default=False): cv.boolean, | ||
| vol.Inclusive(CONF_LATITUDE, "coordinates"): cv.latitude, | ||
| vol.Inclusive(CONF_LONGITUDE, "coordinates"): cv.longitude, | ||
| vol.Optional(CONF_LANGUAGE, default="english"): vol.In( | ||
| ["hebrew", "english"] | ||
| ), | ||
| vol.Optional( | ||
| CONF_CANDLE_LIGHT_MINUTES, default=CANDLE_LIGHT_DEFAULT | ||
| ): int, | ||
| # Default of 0 means use 8.5 degrees / 'three_stars' time. | ||
| vol.Optional(CONF_HAVDALAH_OFFSET_MINUTES, default=0): int, | ||
| } | ||
| ) | ||
| }, | ||
| extra=vol.ALLOW_EXTRA, | ||
| ) | ||
|
|
||
|
|
||
| async def async_setup(hass, config): | ||
| """Set up the Jewish Calendar component.""" | ||
| name = config[DOMAIN][CONF_NAME] | ||
| language = config[DOMAIN][CONF_LANGUAGE] | ||
|
|
||
| latitude = config[DOMAIN].get(CONF_LATITUDE, hass.config.latitude) | ||
| longitude = config[DOMAIN].get(CONF_LONGITUDE, hass.config.longitude) | ||
| diaspora = config[DOMAIN][CONF_DIASPORA] | ||
|
|
||
| candle_lighting_offset = config[DOMAIN][CONF_CANDLE_LIGHT_MINUTES] | ||
| havdalah_offset = config[DOMAIN][CONF_HAVDALAH_OFFSET_MINUTES] | ||
|
|
||
| location = hdate.Location( | ||
| latitude=latitude, | ||
| longitude=longitude, | ||
| timezone=hass.config.time_zone, | ||
| diaspora=diaspora, | ||
| ) | ||
|
|
||
| hass.data[DOMAIN] = { | ||
| "location": location, | ||
| "name": name, | ||
| "language": language, | ||
| "candle_lighting_offset": candle_lighting_offset, | ||
| "havdalah_offset": havdalah_offset, | ||
| "diaspora": diaspora, | ||
| } | ||
|
|
||
| hass.async_create_task(async_load_platform(hass, "sensor", DOMAIN, {}, config)) | ||
|
|
||
| hass.async_create_task( | ||
| async_load_platform(hass, "binary_sensor", DOMAIN, {}, config) | ||
| ) | ||
|
|
||
| return True | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| """Support for Jewish Calendar binary sensors.""" | ||
| import logging | ||
|
|
||
| from homeassistant.components.binary_sensor import BinarySensorDevice | ||
| import homeassistant.util.dt as dt_util | ||
|
|
||
| from . import DOMAIN, SENSOR_TYPES | ||
|
|
||
| import hdate | ||
|
tsvi marked this conversation as resolved.
Outdated
|
||
|
|
||
| _LOGGER = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| async def async_setup_platform(hass, config, async_add_entities, discovery_info=None): | ||
| """Set up the Jewish Calendar binary sensor devices.""" | ||
| if discovery_info is None: | ||
| return | ||
|
|
||
| async_add_entities( | ||
| [ | ||
| JewishCalendarBinarySensor(hass.data[DOMAIN], sensor, sensor_info) | ||
| for sensor, sensor_info in SENSOR_TYPES["binary"].items() | ||
| ] | ||
| ) | ||
|
|
||
|
|
||
| class JewishCalendarBinarySensor(BinarySensorDevice): | ||
| """Representation of an Jewish Calendar binary sensor.""" | ||
|
|
||
| def __init__(self, data, sensor, sensor_info): | ||
| """Initialize the binary sensor.""" | ||
| self._location = data["location"] | ||
| self._type = sensor | ||
| self._name = f"{data['name']} {sensor_info[0]}" | ||
| self._icon = sensor_info[1] | ||
| self._hebrew = data["language"] == "hebrew" | ||
| self._candle_lighting_offset = data["candle_lighting_offset"] | ||
| self._havdalah_offset = data["havdalah_offset"] | ||
| self._state = False | ||
|
|
||
| @property | ||
| def icon(self): | ||
| """Return the icon of the entity.""" | ||
| return self._icon | ||
|
|
||
| @property | ||
| def name(self): | ||
| """Return the name of the entity.""" | ||
| return self._name | ||
|
|
||
| @property | ||
| def is_on(self): | ||
| """Return true if sensor is on.""" | ||
| return self._state | ||
|
|
||
| async def async_update(self): | ||
| """Update the state of the sensor.""" | ||
| zmanim = hdate.Zmanim( | ||
| date=dt_util.now(), | ||
| location=self._location, | ||
| candle_lighting_offset=self._candle_lighting_offset, | ||
| havdalah_offset=self._havdalah_offset, | ||
| hebrew=self._hebrew, | ||
| ) | ||
|
|
||
| self._state = zmanim.issur_melacha_in_effect | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.