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

Prevent schedule switch from turning back in Husqvarna Automower #117692

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

Conversation

Thomas55555
Copy link
Contributor

Breaking change

Proposed change

If the mower's schedule ist turned off, while it is mowing, the mower needs some time to get to the dock. So far, the switch turned on again, because the requirements for turning off were not met. With this fix a helper is used to remember that the switch was turned off by HA. This information will not survive a restart of home assistant.

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:

@tuupos
Copy link

tuupos commented May 23, 2024

I would like to test it but I am not an programmer. I can only read code as an amateur. Is it possible to download the switch.py file add it somewhere to HA and then test it ? Or do you really need programmers to check your code?

@Thomas55555
Copy link
Contributor Author

@tuupos
Copy link

tuupos commented May 23, 2024

Thanks! I deleted that folder recently from my system since I still used the HACS component but updated to the CORE version.

I will put it back and test in and report back (415x here)

@tuupos
Copy link

tuupos commented May 23, 2024

I installed it in the custom_components folder and added a version in de manifest.json. rebooted HA and now I have 23 integrations in stead of 21. However when i switch off the schedule while docked it turns on in 2 secs.

Maybe I overlooked something? How can I show the logs?
This is what I get now:

2024-05-23 23:06:33.311 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration husqvarna_automower which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant

2024-05-23 23:11:54.503 DEBUG (MainThread) [aioautomower.auth] request[post]=https://api.amc.husqvarna.dev/v1/mowers/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/actions None
2024-05-23 23:11:54.504 DEBUG (MainThread) [aioautomower.auth] request[post json]={'data': {'type': 'ParkUntilFurtherNotice'}}
2024-05-23 23:11:56.246 DEBUG (MainThread) [aioautomower.auth] response={'data': {'type': 'control', 'id': 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'}}

@Thomas55555
Copy link
Contributor Author

What's happening next in the logs? So far it looks good.
Interesting would be the following API updates.

@tuupos
Copy link

tuupos commented May 25, 2024

What's happening next in the logs? So far it looks good. Interesting would be the following API updates.

2024-05-26 00:08:01.277 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration husqvarna_automower which has not been tested by Home Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2024-05-26 00:09:01.095 DEBUG (MainThread) [aioautomower.auth] response={'data': {'type': 'control', 'id': '47f73-fXXXXXXXX'}}
2024-05-26 00:09:19.855 DEBUG (MainThread) [aioautomower.auth] request[post]=https://api.amc.husqvarna.dev/v1/mowers/xxx-xxx-xxx-xxx/actions None
2024-05-26 00:09:19.855 DEBUG (MainThread) [aioautomower.auth] request[post json]={'data': {'type': 'ParkUntilFurtherNotice'}}
2024-05-26 00:09:21.970 DEBUG (MainThread) [aioautomower.auth] response={'data': {'type': 'control', 'id': 'c0b2c21d-XXXXXXXXXX'}}
2024-05-26 00:17:39.602 DEBUG (MainThread) [aioautomower.auth] request[post]=https://api.amc.husqvarna.dev/v1/mowers/xxx-xxx-xxx-xxx/actions None
2024-05-26 00:17:39.602 DEBUG (MainThread) [aioautomower.auth] request[post json]={'data': {'type': 'ParkUntilFurtherNotice'}}
2024-05-26 00:17:41.886 DEBUG (MainThread) [aioautomower.auth] response={'data': {'type': 'control', 'id': '0d4c30f7-XXXXXXXXXX'}}
2024-05-26 00:17:52.527 DEBUG (MainThread) [aioautomower.auth] request[post]=https://api.amc.husqvarna.dev/v1/mowers/xxx-xxx-xxx-xxx/actions None
2024-05-26 00:17:52.527 DEBUG (MainThread) [aioautomower.auth] request[post json]={'data': {'type': 'ParkUntilFurtherNotice'}}
2024-05-26 00:17:54.007 DEBUG (MainThread) [aioautomower.auth] response={'data': {'type': 'control', 'id': 'ace7789d-XXXXXXXXXX'}}
2024-05-26 00:18:14.783 DEBUG (MainThread) [aioautomower.auth] request[post]=https://api.amc.husqvarna.dev/v1/mowers/xxx-xxx-xxx-xxx/actions None
2024-05-26 00:18:14.783 DEBUG (MainThread) [aioautomower.auth] request[post json]={'data': {'type': 'ResumeSchedule'}}
2024-05-26 00:18:16.666 DEBUG (MainThread) [aioautomower.auth] response={'data': {'type': 'control', 'id': '148aebff-XXXXXXXXXX'}}
2024-05-26 00:18:16.720 DEBUG (MainThread) [aioautomower.session] Got positions-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'positions-event', 'attributes': {'positions': [{'latitude': xx.xxxxx, 'longitude': xx.xxxxx}]}}
2024-05-26 00:18:16.721 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:18:16.732 DEBUG (MainThread) [aioautomower.session] Got status-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'status-event', 'attributes': {'battery': {'batteryPercent': 95}, 'mower': {'mode': 'MAIN_AREA', 'activity': 'NOT_APPLICABLE', 'state': 'IN_OPERATION', 'inactiveReason': 'PLANNING', 'errorCode': 0, 'errorCodeTimestamp': 0}, 'planner': {'nextStartTimestamp': 0, 'override': {'action': 'NOT_ACTIVE'}, 'restrictedReason': 'NOT_APPLICABLE'}, 'metadata': {'connected': True, 'statusTimestamp': 1716675496654}}}
2024-05-26 00:18:16.733 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:18:16.921 DEBUG (MainThread) [aioautomower.session] Got status-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'status-event', 'attributes': {'battery': {'batteryPercent': 95}, 'mower': {'mode': 'MAIN_AREA', 'activity': 'CHARGING', 'state': 'IN_OPERATION', 'inactiveReason': 'NONE', 'errorCode': 0, 'errorCodeTimestamp': 0}, 'planner': {'nextStartTimestamp': 1716683152000, 'override': {'action': 'NOT_ACTIVE'}, 'restrictedReason': 'NOT_APPLICABLE'}, 'metadata': {'connected': True, 'statusTimestamp': 1716675496848}}}
2024-05-26 00:18:16.922 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:18:16.940 DEBUG (MainThread) [aioautomower.session] Got positions-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'positions-event', 'attributes': {'positions': [{'latitude': xx.xxxxx, 'longitude': xx.xxxxx}]}}
2024-05-26 00:18:16.941 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:18:17.451 DEBUG (MainThread) [aioautomower.session] Got positions-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'positions-event', 'attributes': {'positions': [{'latitude': xx.xxxxx, 'longitude': xx.xxxxx}]}}
2024-05-26 00:18:17.452 DEBUG (MainThread) [aioautomower.session] Got status-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'status-event', 'attributes': {'battery': {'batteryPercent': 95}, 'mower': {'mode': 'MAIN_AREA', 'activity': 'CHARGING', 'state': 'IN_OPERATION', 'inactiveReason': 'NONE', 'errorCode': 0, 'errorCodeTimestamp': 0}, 'planner': {'nextStartTimestamp': 1716683152000, 'override': {'action': 'NOT_ACTIVE'}, 'restrictedReason': 'NOT_APPLICABLE'}, 'metadata': {'connected': True, 'statusTimestamp': 1716675497383}}}
2024-05-26 00:18:17.452 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:18:17.454 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:18:17.832 DEBUG (MainThread) [aioautomower.session] Got status-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'status-event', 'attributes': {'battery': {'batteryPercent': 95}, 'mower': {'mode': 'MAIN_AREA', 'activity': 'CHARGING', 'state': 'IN_OPERATION', 'inactiveReason': 'NONE', 'errorCode': 0, 'errorCodeTimestamp': 0}, 'planner': {'nextStartTimestamp': 1716683152000, 'override': {'action': 'NOT_ACTIVE'}, 'restrictedReason': 'NOT_APPLICABLE'}, 'metadata': {'connected': True, 'statusTimestamp': 1716675497760}}}
2024-05-26 00:18:17.833 DEBUG (MainThread) [aioautomower.session] Got positions-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'positions-event', 'attributes': {'positions': [{'latitude': xx.xxxxx, 'longitude': xx.xxxxx}]}}
2024-05-26 00:18:17.833 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:18:17.835 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:18:38.828 DEBUG (MainThread) [aioautomower.auth] request[post]=https://api.amc.husqvarna.dev/v1/mowers/xxx-xxx-xxx-xxx/actions None
2024-05-26 00:18:38.828 DEBUG (MainThread) [aioautomower.auth] request[post json]={'data': {'type': 'ResumeSchedule'}}
2024-05-26 00:18:41.131 DEBUG (MainThread) [aioautomower.auth] response={'data': {'type': 'control', 'id': 'e7ac7b1e-xxxxxxxxx'}}
2024-05-26 00:18:41.219 DEBUG (MainThread) [aioautomower.session] Got positions-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'positions-event', 'attributes': {'positions': [{'latitude': xx.xxxxx, 'longitude': xx.xxxxx}]}}
2024-05-26 00:18:41.220 DEBUG (MainThread) [aioautomower.session] Got status-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'status-event', 'attributes': {'battery': {'batteryPercent': 95}, 'mower': {'mode': 'MAIN_AREA', 'activity': 'CHARGING', 'state': 'IN_OPERATION', 'inactiveReason': 'NONE', 'errorCode': 0, 'errorCodeTimestamp': 0}, 'planner': {'nextStartTimestamp': 1716683152000, 'override': {'action': 'NOT_ACTIVE'}, 'restrictedReason': 'NOT_APPLICABLE'}, 'metadata': {'connected': True, 'statusTimestamp': 1716675521144}}}
2024-05-26 00:18:41.220 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:18:41.222 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:19:31.420 DEBUG (MainThread) [aioautomower.auth] request[post]=https://api.amc.husqvarna.dev/v1/mowers/xxx-xxx-xxx-xxx/actions None
2024-05-26 00:19:31.420 DEBUG (MainThread) [aioautomower.auth] request[post json]={'data': {'type': 'ParkUntilFurtherNotice'}}
2024-05-26 00:19:33.912 DEBUG (MainThread) [aioautomower.auth] response={'data': {'type': 'control', 'id': '9406e314-xxxxxxxxxxxxxxxx'}}
2024-05-26 00:19:34.033 DEBUG (MainThread) [aioautomower.session] Got positions-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'positions-event', 'attributes': {'positions': [{'latitude': xx.xxxxx, 'longitude': xx.xxxxx}]}}
2024-05-26 00:19:34.035 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:19:34.042 DEBUG (MainThread) [aioautomower.session] Got status-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'status-event', 'attributes': {'battery': {'batteryPercent': 95}, 'mower': {'mode': 'HOME', 'activity': 'NOT_APPLICABLE', 'state': 'IN_OPERATION', 'inactiveReason': 'PLANNING', 'errorCode': 0, 'errorCodeTimestamp': 0}, 'planner': {'nextStartTimestamp': 0, 'override': {'action': 'NOT_ACTIVE'}, 'restrictedReason': 'NOT_APPLICABLE'}, 'metadata': {'connected': True, 'statusTimestamp': 1716675573958}}}
2024-05-26 00:19:34.043 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:19:34.934 DEBUG (MainThread) [aioautomower.session] Got positions-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'positions-event', 'attributes': {'positions': [{'latitude': xx.xxxxx, 'longitude': xx.xxxxx}]}}
2024-05-26 00:19:34.935 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:19:34.976 DEBUG (MainThread) [aioautomower.session] Got status-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'status-event', 'attributes': {'battery': {'batteryPercent': 95}, 'mower': {'mode': 'HOME', 'activity': 'NOT_APPLICABLE', 'state': 'IN_OPERATION', 'inactiveReason': 'PLANNING', 'errorCode': 0, 'errorCodeTimestamp': 0}, 'planner': {'nextStartTimestamp': 0, 'override': {'action': 'NOT_ACTIVE'}, 'restrictedReason': 'NOT_APPLICABLE'}, 'metadata': {'connected': True, 'statusTimestamp': 1716675574865}}}
2024-05-26 00:19:34.977 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:19:35.180 DEBUG (MainThread) [aioautomower.session] Got status-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'status-event', 'attributes': {'battery': {'batteryPercent': 95}, 'mower': {'mode': 'HOME', 'activity': 'CHARGING', 'state': 'IN_OPERATION', 'inactiveReason': 'NONE', 'errorCode': 0, 'errorCodeTimestamp': 0}, 'planner': {'nextStartTimestamp': 1716683152000, 'override': {'action': 'NOT_ACTIVE'}, 'restrictedReason': 'NOT_APPLICABLE'}, 'metadata': {'connected': True, 'statusTimestamp': 1716675575094}}}
2024-05-26 00:19:35.181 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:19:35.195 DEBUG (MainThread) [aioautomower.session] Got positions-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'positions-event', 'attributes': {'positions': [{'latitude': xx.xxxxx, 'longitude': xx.xxxxx}]}}
2024-05-26 00:19:35.195 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:19:35.338 DEBUG (MainThread) [aioautomower.session] Got status-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'status-event', 'attributes': {'battery': {'batteryPercent': 95}, 'mower': {'mode': 'HOME', 'activity': 'PARKED_IN_CS', 'state': 'IN_OPERATION', 'inactiveReason': 'NONE', 'errorCode': 0, 'errorCodeTimestamp': 0}, 'planner': {'nextStartTimestamp': 0, 'override': {'action': 'NOT_ACTIVE'}, 'restrictedReason': 'NOT_APPLICABLE'}, 'metadata': {'connected': True, 'statusTimestamp': 1716675575266}}}
2024-05-26 00:19:35.338 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:19:35.359 DEBUG (MainThread) [aioautomower.session] Got positions-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'positions-event', 'attributes': {'positions': [{'latitude': xx.xxxxx, 'longitude': xx.xxxxx}]}}
2024-05-26 00:19:35.360 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:19:35.860 DEBUG (MainThread) [aioautomower.session] Got status-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'status-event', 'attributes': {'battery': {'batteryPercent': 95}, 'mower': {'mode': 'HOME', 'activity': 'PARKED_IN_CS', 'state': 'IN_OPERATION', 'inactiveReason': 'NONE', 'errorCode': 0, 'errorCodeTimestamp': 0}, 'planner': {'nextStartTimestamp': 0, 'override': {'action': 'NOT_ACTIVE'}, 'restrictedReason': 'NOT_APPLICABLE'}, 'metadata': {'connected': True, 'statusTimestamp': 1716675575791}}}
2024-05-26 00:19:35.861 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:19:35.865 DEBUG (MainThread) [aioautomower.session] Got positions-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'positions-event', 'attributes': {'positions': [{'latitude': xx.xxxxx, 'longitude': xx.xxxxx}]}}
2024-05-26 00:19:35.866 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:19:36.262 DEBUG (MainThread) [aioautomower.session] Got status-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'status-event', 'attributes': {'battery': {'batteryPercent': 95}, 'mower': {'mode': 'HOME', 'activity': 'PARKED_IN_CS', 'state': 'IN_OPERATION', 'inactiveReason': 'NONE', 'errorCode': 0, 'errorCodeTimestamp': 0}, 'planner': {'nextStartTimestamp': 0, 'override': {'action': 'NOT_ACTIVE'}, 'restrictedReason': 'NOT_APPLICABLE'}, 'metadata': {'connected': True, 'statusTimestamp': 1716675576169}}}
2024-05-26 00:19:36.263 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data
2024-05-26 00:19:36.270 DEBUG (MainThread) [aioautomower.session] Got positions-event, data: {'id': 'xxx-xxx-xxx-xxx', 'type': 'positions-event', 'attributes': {'positions': [{'latitude': xx.xxxxx, 'longitude': xx.xxxxx}]}}
2024-05-26 00:19:36.271 DEBUG (MainThread) [custom_components.husqvarna_automower.coordinator] Manually updated husqvarna_automower data

Hope this helps..... I dont know where I should be looking fot in de debug code. How long do I let the debugging run ?

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.

Enable schedule cannot be turned off
3 participants