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 possibility of using an address list instead #202

Merged
merged 5 commits into from
Dec 7, 2021

Conversation

DurgNomis-drol
Copy link
Collaborator

This changes disable_discovery from a bool to address_list containing a dict. Example dict: ``{"Living room": "192.168.0.69"}` Not setting the address_list results in discovery been enabled. Setting it to and empty dict results in discovery being disabled.

I was not 100% sure on how to best implement this, so please provide feedback if something can be done better. 😄

Code is tested, but can someone double check to make sure that we are not breaking anything with this.

@DurgNomis-drol
Copy link
Collaborator Author

I am unsure of why the linter fails to install poetry

Copy link
Owner

@leikoilja leikoilja left a comment

Choose a reason for hiding this comment

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

That's an amazing improvements, thanks man! Have a few suggestions

glocaltokens/client.py Outdated Show resolved Hide resolved
glocaltokens/client.py Outdated Show resolved Hide resolved
glocaltokens/client.py Outdated Show resolved Hide resolved
glocaltokens/client.py Outdated Show resolved Hide resolved
glocaltokens/client.py Outdated Show resolved Hide resolved
tests/factory/providers.py Outdated Show resolved Hide resolved
tests/test_client.py Show resolved Hide resolved
@leikoilja leikoilja added the feature New feature or request label Dec 2, 2021
@DurgNomis-drol
Copy link
Collaborator Author

Please see my changes and the last comment that are open 😃

Copy link
Owner

@leikoilja leikoilja left a comment

Choose a reason for hiding this comment

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

Yay! Amazing job, man! Thanks 💯
Just a minor comment about default IPs/port, then we figure out why CI fails and it's good to go 🚀

p.s. speaking of CI and failing linters, can you please try few things:

  • rebase this branch to latest master when doing changes
  • run poetry install locally
  • run poetry run pre-commit install locally
  • run poetry run pre-commit run all-files locally
    Hopefully it should help your linters get up to date and fix the issues :)

glocaltokens/client.py Outdated Show resolved Hide resolved
glocaltokens/client.py Outdated Show resolved Hide resolved
tests/test_client.py Show resolved Hide resolved
@DurgNomis-drol
Copy link
Collaborator Author

DurgNomis-drol commented Dec 3, 2021

I have no idea of what went wrong and why it essentially deletes and the adds client.py and the new lines again, but i don't have time to fixed it today, will fixed it tomorrow

@DurgNomis-drol
Copy link
Collaborator Author

Can it be line endings?

@DurgNomis-drol
Copy link
Collaborator Author

DurgNomis-drol commented Dec 4, 2021

Got it fixed, i have no idea what went wrong but rolled back to a working commit and fixed the linter.

@leikoilja Can I get you to release a new version after this is merged? Oh and can i get you to merged it? 😄

poetry.lock Outdated Show resolved Hide resolved
@KapJI
Copy link
Collaborator

KapJI commented Dec 4, 2021

Can you give some context about what problem you're solving with this?

@DurgNomis-drol
Copy link
Collaborator Author

DurgNomis-drol commented Dec 4, 2021

Can you give some context about what problem you're solving with this?

leikoilja/ha-google-home#340 is just one of them.

As i am working on moving the ha-google-home code to the separate module, i ran into some problems with zeroconf on WSL2. Code run in WSL2 can't discover devices through zeroconf. This just makes it much easier for me to test it while i am coding 😄

@KapJI
Copy link
Collaborator

KapJI commented Dec 4, 2021

Thanks, makes sense.

I think breaking compatibility for such change is not necessary, so let's keep disable_discovery.

Instead add extra_addresses argument in the end. IP address should be the key. And append it to list of discovered devices.

@DurgNomis-drol
Copy link
Collaborator Author

DurgNomis-drol commented Dec 4, 2021

@KapJI We need to pass the name of the device as the key and the IP address as the value. If we don't, we can't match the IP address to the device and so on.

Making it a separate argument, means the user now needs to set disable_discovery to true and then set a dict with addresses. Using my way, we just disable it automatically if we have dict containing addresses.

@KapJI
Copy link
Collaborator

KapJI commented Dec 4, 2021

You don't need to disable discovery completely. If it crashes on WSL2, you can disable it automatically if running inside WSL2.

Mapping from IP to name makes more sense from UX perspective which I believe should come before implementation. You can build reverse dict here if needed.

@DurgNomis-drol
Copy link
Collaborator Author

I Think you are missing the point of what i am trying to do with this PR.

It dosen't make sense to reverse it like you are takling about. We match on device name not the IP.

@KapJI
Copy link
Collaborator

KapJI commented Dec 4, 2021

Ok, having name as a key is fine actually.

@leikoilja
Copy link
Owner

Nice!
Awesome thing we have more opinions and reviewers in here. I am not particularly worried about breaking compatibility, since we don't rely on that in ha-google-home and we can't really know if there is anyone using disable_discovery kwarg at all, so IMHO it shouldn't be a biggie. I ll leave it up to you, @DurgNomis-drol, to decide whether or not you want to refactor it into a separate kwarg keeping disable_discovery, but feel free to merge when you ready! 🚀
p.s. also given you the full repo permissions in the repo, not sure why it wasn't set in the first place 💯
Thanks man! 🔥

@DurgNomis-drol
Copy link
Collaborator Author

@leikoilja Thanks for both invites! Haven really been active here, so that is fine that i am only getting it now 😆

I will let @KapJI suggestions about disable_discovery tumble around in my head until tomorrow, just to make sure i am not missing something 😄 Right now i can't see the use for a separate argument

@KapJI
Copy link
Collaborator

KapJI commented Dec 5, 2021

Approach I proposes should be more flexible. Basically you can still use discovery and extend it with your own list. Also empty dict for disabling discovery while None enables it, is not very clear API.

@DurgNomis-drol
Copy link
Collaborator Author

@KapJI Good point about it not being clear the way i have proposed.

@DurgNomis-drol DurgNomis-drol requested a review from KapJI December 6, 2021 15:34
Copy link
Owner

@leikoilja leikoilja left a comment

Choose a reason for hiding this comment

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

Amazing stuff, thanks, @DurgNomis-drol 🚀
To me, we are ready to merge 💥
@KapJI? :)

glocaltokens/client.py Outdated Show resolved Hide resolved
glocaltokens/client.py Outdated Show resolved Hide resolved
glocaltokens/client.py Show resolved Hide resolved
glocaltokens/client.py Show resolved Hide resolved
DurgNomis-drol and others added 2 commits December 6, 2021 20:02
Good catch!

Co-authored-by: Ilja Leiko <[email protected]>
@leikoilja
Copy link
Owner

Amazing work, thank you, @DurgNomis-drol 💯 🔥

@leikoilja leikoilja merged commit 81928d1 into leikoilja:master Dec 7, 2021
@leikoilja
Copy link
Owner

ping @DurgNomis-drol for v0.6 release

@@ -405,6 +429,14 @@ def find_device(unique_id: str) -> NetworkDevice | None:
unique_id,
)
network_device = find_device(unique_id)
elif item.device_name in address_dict:
Copy link
Collaborator

Choose a reason for hiding this comment

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

This means if discovery is enabled, address_dict won't be used. That contradicts the idea to have separate disable_discovery flag.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also if there's no item with such name in address_dict, it's worth to print a warning message.

@@ -335,6 +337,7 @@ def get_google_devices(
self,
models_list: list[str] | None = None,
disable_discovery: bool = False,
addresses: dict[str, str] | None = None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's better to add new arguments in the end, to not break reverse compatibility.

@DurgNomis-drol DurgNomis-drol deleted the add-address-list branch December 7, 2021 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants