Skip to content
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

Add services for jewish_calendar integration #111986

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from

Conversation

SLaks
Copy link
Contributor

@SLaks SLaks commented Mar 1, 2024

Breaking change

Proposed change

Adds services to return information about arbitrary Hebrew dates and holidays.

This makes it possible to build automations that react to future calendar events.

Also make Jewish Calendar Holiday an enum sensor, to show a dropdown list when using it in conditions.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies - a link to the changelog, or at minimum a diff between library versions is added to the PR description.
  • Untested files have been added to .coveragerc.

To help with the load of incoming pull requests:

@home-assistant
Copy link

home-assistant bot commented Mar 1, 2024

Hey there @tsvi, mind taking a look at this pull request as it has been labeled with an integration (jewish_calendar) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of jewish_calendar can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign jewish_calendar Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component) on the pull request.

@SLaks
Copy link
Contributor Author

SLaks commented Mar 1, 2024

I'm going to add parameters to specify a partial Hebrew date

@SLaks SLaks force-pushed the jc branch 4 times, most recently from 26286f4 to 514dcab Compare March 5, 2024 16:25
@SLaks SLaks marked this pull request as ready for review March 5, 2024 16:26
@SLaks
Copy link
Contributor Author

SLaks commented Mar 5, 2024

I completely rewrote this; it's now ready.

I'll write docs soon (WDYT of the exposed API?)

@SLaks
Copy link
Contributor Author

SLaks commented Mar 7, 2024

Updated docs in home-assistant/home-assistant.io#31770

Copy link
Contributor

@tsvi tsvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Please rename the services and I'll approve.
Thanks a lot

Comment on lines 3 to 6
"for_gregorian_date": "mdi:calendar",
"for_hebrew_date": "mdi:calendar",
"get_holidays": "mdi:calendar-star",
"for_next_holiday": "mdi:calendar-arrow-right"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned in the documentation, rename these to get_*

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -252,10 +253,19 @@ def get_state(
# Compute the weekly portion based on the upcoming shabbat.
return after_tzais_date.upcoming_shabbat.parasha
if self.entity_description.key == "holiday":
self._attr_device_class = SensorDeviceClass.ENUM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch 👍

@SLaks
Copy link
Contributor Author

SLaks commented Mar 7, 2024

This should also be blocked on py-libhdate/py-libhdate#117, which unbreaks get_holidays

Copy link
Contributor

@tsvi tsvi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Will try and release the fix for py-libhdate sometime next week so we don't have the double Purim bug you mentioned.

@tsvi
Copy link
Contributor

tsvi commented Mar 9, 2024

Released py-libhdate v0.10.7. Please update to this version to deal with the issue of double purim.

@SLaks
Copy link
Contributor Author

SLaks commented Mar 10, 2024

Done

@SLaks SLaks requested a review from a team as a code owner March 10, 2024 19:26
@SLaks
Copy link
Contributor Author

SLaks commented Mar 10, 2024

I can't figure out why this breaks the typing in sun/init.py.

The type of the property being set did not change.

@tsvi
Copy link
Contributor

tsvi commented Mar 11, 2024

That's my bad, I updated the astral dependency in the library in preparation for potentially adding calculations about the moon.
I'll release a newer version with astral reverted to 2.2

@tsvi
Copy link
Contributor

tsvi commented Mar 11, 2024

Please retry with version v0.10.8

@SLaks
Copy link
Contributor Author

SLaks commented Mar 11, 2024

Done

@tsvi
Copy link
Contributor

tsvi commented Mar 11, 2024

Unfortunately, you'll have to fix the tests. Although some changes were accepted into the master branch, a new version wasn't released since 2021. So, there are some minor fixes to be dealt with. Sorry.

@SLaks
Copy link
Contributor Author

SLaks commented Mar 11, 2024

Yes; will do soon

@MartinHjelmare MartinHjelmare removed the request for review from a team March 12, 2024 04:00
@SLaks
Copy link
Contributor Author

SLaks commented Mar 13, 2024

Fixed

@tsvi
Copy link
Contributor

tsvi commented Mar 13, 2024

@MartinHjelmare This is ready for review by the core team or whomever has commit rights.

@SLaks
Copy link
Contributor Author

SLaks commented Mar 22, 2024

Can someone please approve this?

@SLaks
Copy link
Contributor Author

SLaks commented Apr 14, 2024

Can someone please approve this?

Copy link
Contributor

@emontnemery emontnemery left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please split this PR in three PRs:

  1. Bump the library version
  2. Add services to return information about arbitrary Hebrew dates and holidays.
  3. Make Jewish Calendar Holiday an enum sensor, to show a dropdown list when using it in conditions.

homeassistant/components/jewish_calendar/service.py Outdated Show resolved Hide resolved
@home-assistant home-assistant bot marked this pull request as draft April 24, 2024 15:04
@home-assistant
Copy link

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@SLaks
Copy link
Contributor Author

SLaks commented Apr 26, 2024

Sent #116202 and #116252.

I'll rebase the commits out of this PR as they merge.

@tsvi tsvi mentioned this pull request Apr 29, 2024
20 tasks
@SLaks SLaks marked this pull request as ready for review May 24, 2024 16:34
@home-assistant home-assistant bot requested review from tsvi and emontnemery May 24, 2024 16:34
@SLaks
Copy link
Contributor Author

SLaks commented May 24, 2024

This is now ready

homeassistant/components/jewish_calendar/service.py Outdated Show resolved Hide resolved
selector:
select:
options:
- Tishrei
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we can provide this list from py-libhdate? What happens if we start supporting more languages? Other spellings?
The same is especially true for holidays.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is possible via async_set_service_schema(), which is meant to register dynamically-generated services.

However, looking through its implementation, it ought to work fine to replace an already-registered service too, which means I should be able to call it to either supplement or entirely replace services.yaml here.

Do you think core is likely to accept that?

@SLaks
Copy link
Contributor Author

SLaks commented May 29, 2024

@emontnemery Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants