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

Smart watering program fix #101

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

allistermaguire
Copy link
Contributor

This PR fixes an issue with B-hyve Smart Irrigation Controllers that have multiple zones/stations. The Smart Watering program id is not constant when the program updates. This causes the following issues:

  1. 'Irrigation Smart Watering program' switches are create each time there is a change.
  2. Error when trying to turn off the above switch due to the program_id in the module and the id on the B-hyve being out of sync.

I have resolved this by creating a constant program id for programs that are Smart watering based off the device id. This shouldn't be an issue based on my assumption that you can only have one Smart watering program per device.

@sebr
Copy link
Owner

sebr commented Jan 29, 2022

@allistermaguire Thanks so much for the info and the PR.

Can you share more details about the specific discrepancies in the API which cause this to happen? Any API responses or websocket payloads that demonstrate this behaviour would be valuable to validate the logic.

This is particularly important as changing the unique_id is a breaking change (home assistant will create new entities and the user will be left with orphaned entities and need to do manual migrations)

Thank you!

@allistermaguire
Copy link
Contributor Author

Hi @sebr, that is a good point. I did not consider that as it is already broken for me, I already had multiple orphaned entities which I needed to clean up. But considering no one else has reported it is likely most people aren't using Orbit Hyve controllers with multiple zones and therefore not having this issue.

See smart_watering_program_messages_json.txt for program_changed json. I have formatted it nicely so it is easy to read include removing "watering_plan" and "long_term_program" as they are relevant and make the json really large.

@allistermaguire
Copy link
Contributor Author

I am going to have to rebase this one. I noticed that it includes my naming changes for zones and sensors.

I have submitted PR #102 which is possibly more valuable to users, then can circle back to this one later.

@allistermaguire
Copy link
Contributor Author

I have rebased and tidy up the code so it is more readable. I have also limited the change to Smart Watering programs, but it is still breaking.

The only way I could find to migrate unique_id is if the integration uses config entires.

@julian-yang
Copy link

Hi, just curious what are the next steps to get this PR merged in?

I think I am in a similar boat as allistermaguire. I'm using Smart watering on multiple zones, and the next watering time only seems to show for certain zones, and the zones that it shows for changes. Seems like it may be due to the "Smart watering program not having a constant ID" issue mentioned here.

@allistermaguire
Copy link
Contributor Author

allistermaguire commented Aug 2, 2022

I have updated this PR so that it shouldn't be a breaking change. Now that it is using config entries I can migrate the Unique ID for the Smart Watering program switch.

It uses device_id for both the unique_id and constant program_id. This works fine for my use case as I have a single device with multiple zones. I am not sure what the effect is if you have multiple devices.

@gdgeist
Copy link

gdgeist commented Jun 19, 2023

This issue still persists - whats up with this pull request?

@allistermaguire
Copy link
Contributor Author

I haven't checked the latest version/s, but I haven't seen anyone else raise this issue. Not sure if most people mainly run the smart hose timers vs the irrigation controllers as I do. I am personally running my forked version that I update, but haven't done so since Feb 23.

@motolav
Copy link

motolav commented Nov 8, 2024

I use my irrigation controller with Orbit's Smart Watering function and I see the new entities being added when I change settings in the b-hyve app, it's a little annoying having to remove the old ones

@danVnest
Copy link

I also experience this issue occasionally. This PR seems like a good idea - any reason not to merge?

@sebr
Copy link
Owner

sebr commented Nov 10, 2024

I'm happy to reopen this and have this PR merged, if I can have some beta testers?

@sebr sebr reopened this Nov 10, 2024
@motolav
Copy link

motolav commented Nov 19, 2024

I can beta test it

@danVnest
Copy link

I've done some quick tests, so far the main issue is the assumption that there is only one device.
I use 2 devices, which produces the following error when the migration tries to use the same device_id for both of my _smart_watering_program entities.

error 1 Logger: homeassistant.config_entries Source: config_entries.py:978 First occurred: 5:59:13 PM (1 occurrences) Last logged: 5:59:13 PM

Error migrating entry [email protected] for bhyve
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 978, in async_migrate
result = await component.async_migrate_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/bhyve/init.py", line 173, in async_migrate_entry
registry.async_update_entity(entity_id, new_unique_id=new_unique_id)
File "/usr/src/homeassistant/homeassistant/helpers/entity_registry.py", line 1179, in async_update_entity
return self._async_update_entity(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/helpers/entity_registry.py", line 1118, in _async_update_entity
raise ValueError(
ValueError: Unique id 'bhyve:657c1764554dee24c5f8f776:program:smart_program' is already in use by 'switch.back_tap_smart_watering_program'

I think I resolved this by using new_unique_id = f"bhyve:{e_entry.device_id}:program:smart_program", but have run into other errors.

One such error is the following, which seems to be fixed by using hass.config_entries.async_update_entry(entry, version=2) instead of entry.version = 2:

error 2 Logger: homeassistant.config_entries Source: config_entries.py:978 First occurred: 9:00:04 PM (1 occurrences) Last logged: 9:00:04 PM

Error migrating entry [email protected] for bhyve
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 978, in async_migrate
result = await component.async_migrate_entry(hass, self)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/config/custom_components/bhyve/init.py", line 181, in async_migrate_entry
entry.version = 2
^^^^^^^^^^^^^
File "/usr/src/homeassistant/homeassistant/config_entries.py", line 463, in setattr
raise AttributeError(
AttributeError: version cannot be changed directly, use async_update_entry instead

So it looks like there's a few updates required for this PR - probably primarily to function with the latest HA version?
This is not a priority for me so I'm leaving these notes here for now.

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

Successfully merging this pull request may close these issues.

6 participants