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

Set min, max, and step for ViCare number entities #104593

Merged
merged 9 commits into from Nov 28, 2023

Conversation

CFenner
Copy link
Contributor

@CFenner CFenner commented Nov 27, 2023

Breaking change

Proposed change

With this the number entities get it's min, max and stepping values from the function definition of the api.

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 Black (black --fast 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:

@CFenner CFenner marked this pull request as ready for review November 27, 2023 14:35
homeassistant/components/vicare/number.py Outdated Show resolved Hide resolved
homeassistant/components/vicare/number.py Outdated Show resolved Hide resolved
@@ -10,7 +10,7 @@
from PyViCare.PyViCareDevice import Device as PyViCareDevice
from PyViCare.PyViCareDeviceConfig import PyViCareDeviceConfig
from PyViCare.PyViCareHeatingDevice import (
HeatingDeviceWithComponent as PyViCareHeatingDeviceWithComponent,
HeatingDeviceWithComponent as PyViCareHeatingDeviceComponent,
Copy link
Contributor

Choose a reason for hiding this comment

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

Whats the reason to rename the import? Why aren't we using the original name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To me this naming makes more sense. We deal here with burners, compressors or heating circuits which are components of a heating device and not heating devices as the name heating device with components suggest.

@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.

@home-assistant home-assistant bot marked this pull request as draft November 27, 2023 18:09
@edenhaus edenhaus self-assigned this Nov 27, 2023
CFenner and others added 3 commits November 27, 2023 21:06
@CFenner CFenner marked this pull request as ready for review November 27, 2023 20:24
@home-assistant home-assistant bot marked this pull request as draft November 28, 2023 07:16
CFenner and others added 3 commits November 28, 2023 08:28
Co-authored-by: Robert Resch <robert@resch.dev>
@CFenner CFenner marked this pull request as ready for review November 28, 2023 08:05
Copy link
Contributor

@edenhaus edenhaus left a comment

Choose a reason for hiding this comment

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

Thanks @CFenner 👍

@edenhaus edenhaus changed the title Use stepping, min, max from API in number entities in ViCare integration Set min, max, and step for ViCare number entities Nov 28, 2023
@edenhaus edenhaus merged commit 1ef97ab into home-assistant:dev Nov 28, 2023
23 checks passed
circuits = await hass.async_add_executor_job(get_circuits, api)
for circuit in circuits:
for description in CIRCUIT_ENTITY_DESCRIPTIONS:
entity = await hass.async_add_executor_job(
Copy link
Member

Choose a reason for hiding this comment

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

We should collect all the sync work in a function and schedule that work once on the executor. The context switch from event loop to the executor is expensive.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would it make sense to do that once in __init__ and store on hass.data[DOMAIN]?

Copy link
Member

Choose a reason for hiding this comment

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

Entities are a platform concern. It would be ok to collect device information in a central place if it's relevant for more than one entity. But the entities themselves should not be stored anywhere outside their platform.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I misunderstood, I thought this is about circuits = await hass.async_add_executor_job(get_circuits, api) which is done for all platforms.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The issue is that the library caches the API data for 60 seconds and each access one of its objects can result in an update of that cache.
Probably an UpdateCoordinator would be better to have, but my knowledge neither in python nor in home assistant is deep enough to do that.

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand what the cache has to do with if we make one or multiple sequential executor jobs? It doesn't change how we access the library objects. It only changes how that work is scheduled from the event loop on the executor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you think about something like this where the async executor is moved outside the loops?
https://github.com/home-assistant/core/compare/dev...CFenner:sync-4?expand=1

Copy link
Member

Choose a reason for hiding this comment

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

Yes, but use a list comprehension. We don't need any local variable for entity then.

@CFenner CFenner deleted the constraints branch November 28, 2023 14:29
@github-actions github-actions bot locked and limited conversation to collaborators Nov 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants