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

Feat: Remove use of frontend automations #173

Merged
merged 32 commits into from
Sep 29, 2023
Merged

Conversation

tykeal
Copy link
Owner

@tykeal tykeal commented Sep 29, 2023

Move from using frontend automations to populate data into the backend to
talking to the Home Assistant state machine and firing modification events
directly at entities.

  • Chore: Bump icalendar version requirement
  • Feat: Get Keymaster overrides on startup
  • Chore: Cleanup startup automation
  • Refactor: Standardize on using config_entry
  • Refactor: Simplify RentalControl init and annotate
  • Refactor: Annotate RentalControl class more
  • Refactor: Finish RentalControl annotation cleanup
  • Chore: Set integration_type in manifest
  • Chore: Bump HACS install reqs
  • Refactor: Prep for adding sub/unsub of events
  • Feat: Move mapping update to event listener
  • Refactor: Rename rental_control to coordinator
  • Feat: Mapping is now more responsive to overrides
  • Refactor: Move clear code from automation
  • Feat: New overrides handling
  • Refactor: Start migration of event overrides
  • Feat: Calendar updates refresh event sensors
  • Chore: Remove mapping sensor creation
  • Refactor: Stop using automation for setting slots
  • Refactor: Move add_call to separate function
  • Feat: Teach slots how to follow date changes
  • Refactor: Move info logs to debug
  • Chore: Finalize removal of old mapping sensor
  • Refactor: Add type hinting to calendar sensor
  • Chore: Remove old fire_set_code
  • Fix: Add prefix back to slot names if defined
  • Chore: Cleanup package generation
  • Chore: Remove final RentalControl services
  • Chore: Cleanup unused functions
  • Refactor: Get rid of old overrides system
  • Feat: Finalize upgrade to schema v6
  • Docs: Update the documentation

icalendar 4.x is effectively deprecated, bump to 5.x

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Inspect the HA state machine directly to get the current defined
Keymaster slot definitions to build up the the overrides table.

This makes the startup / rental_control_refresh automation redundant

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
* Sets config version to 5
* Causes the automations to be rebuilt and the startup automation to be
  removed as the logic has moved inside of the integration startup

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Instead of having some functions have entry and others use the more
community commont config_entry, just standardize on using config_entry

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Simplify the call to the init routine and also make sure that it is
properly annotated.

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
* More annotation of the RentalControl class
* Minor cleanup of property loading as there are no (reported) versions
  that are so old that the guards are needed any more

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Finish cleaning up the RentalControl class annotations

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
https://developers.home-assistant.io/docs/creating_integration_manifest
specifies that integration_type needs to be set in the manifest. The
current default is 'hub' but RentalControl falls more into either the
'service' (which we're choosing) or possibly 'device' categories.

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Latest changes are only being tested on HA 2023.9.x with HACS >=1.32.1
so set the minimum install requirements to these values

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
* Migrates the RentalControl object to a "coordinator" object that is
  stored in hass.data as part of a dictionary
* Properly updates all sensors for the new location of the coordinator
  object (and renames it to be consistent)

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
* Moves the slot mapping to an event listener
* Removes the update automation as we now listen on the controller side

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
The term coordinator really makes more sense and is more in line with
the shift that happened in the main RentalControl class while moving
awawy from front end automations.

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
The mapping update is now called during override updates. This allows it
to be very responsive to making sure a code is still defined

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
* Move the clear code operation from an automation listenting for a
  rental_control event to a listener.
* Remove the clear_code automation definition

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Build up new overrides handling system and hook it in next to the
current one.

* Handles overrides in a more correct manner
* Has a get_next_available_slot routine to more easily acquire where the
  next code should be sent.

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Move the event overrides logic to it's own object.

This makes the code in RentalControl itself easier to read and also
centralizes most of the logic.

The majority of the logic is all sync instead of async code to help make
sure we're only operating on a given state at a time

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Event sensors no longer call a refresh of the event calendar, instead,
the event calendar will trigger a refresh of event sensors making them
more responsive to updates in the calendar.

Issue: Fixes #163
Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
The MappingSensor has never really worked particularly well. As it never
properly worked, all the automations that were expected to start using
it never did.

Additionally, since the shipped automations are going away, the need for
the sensor is even less relevant.

Remove the loading of it.

Also, fix issues with reload of the integration

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
* Removes the installation of the set_code automation
* Triggers slot setting as needed
* Is unfortunately much slower to load in all codes when a calendar is
  first instantiated into empty slots

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Move it out of async_fire_set_code so that it can be used by other
functions

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Updates to start/end dates now properly cause updates to slot
definitions. Start / stop _times_ still fully override even over date
changes.

Issue: Fixes #105
Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
* Add type hinting to calendar sensor
* Add an available flag that follows the coordinator availability

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
The old event firing is no longer needed as it has been subsumed by more
direct methods of setting the slots

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Rental Control no longer uses automations coming from the front end to
inform features. As the services that were defined were all related to
passing data from the frontend to the backend they are no longer useful.

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
* async_check_overrides - this has moved into the event_overrides module
* fire_clear_code - this has been redesigned as async_fire_clear_code to
  interact directly with HA instead of firing an event to be picked up
  by an automation

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Remove the last vestiges of the old overrides system and move the new
one into the coordinator.event_overrides location

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
Make sure all migrations are happening instead of only one per restart
(not certain how I missed this for so long!)

Final state has the packages/rental_control directory structure completely
removed. Users will have do one more restart of HA before they can
completely remove all orphaned entities which will have to be a manual
process :(

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
* Detail how custom calendar events should be constructed
* Remove information about the removed mapping sensor

Signed-off-by: Andrew Grimberg <tykeal@bardicgrove.org>
@tykeal tykeal added the enhancement New feature or request label Sep 29, 2023
@tykeal tykeal enabled auto-merge September 29, 2023 17:43
@tykeal tykeal merged commit a434f14 into main Sep 29, 2023
7 checks passed
@tykeal tykeal deleted the get_rid_of_automations branch September 29, 2023 17:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant