Skip to content

Update pyunifi component to use APIError passed from pyunifi 2.13. Better accommodate login failures with wrapper in pyunifi 2.13.#7899

Merged
balloob merged 9 commits into
home-assistant:devfrom
finish06:unifi_login_wrapper
Jun 17, 2017
Merged

Update pyunifi component to use APIError passed from pyunifi 2.13. Better accommodate login failures with wrapper in pyunifi 2.13.#7899
balloob merged 9 commits into
home-assistant:devfrom
finish06:unifi_login_wrapper

Conversation

@finish06
Copy link
Copy Markdown
Contributor

@finish06 finish06 commented Jun 4, 2017

Description:

Added wrapper to pyunifi 2.13 '_read' function to improve handling of authentication related failures. Updated unifi component to accept 'APIError' as passed from pyunifi. Adjusted urllib3.exceptions.InsecureRequestWarning to display a single time.

Checklist:

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example).
  • New dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.
  • New files were added to .coveragerc.

If the code does not interact with devices:

  • Local tests with tox run successfully. Your PR cannot be merged unless tests pass
  • Tests have been added to verify that the new code works.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

undefined name 'APIError'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

undefined name 'APIError'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You'll need to import APIError first.

@finish06
Copy link
Copy Markdown
Contributor Author

finish06 commented Jun 4, 2017

In need of assistance regarding updating the test_unifi.py file. Thanks!

@balloob
Copy link
Copy Markdown
Member

balloob commented Jun 5, 2017

Add pyunify to https://github.com/home-assistant/home-assistant/blob/dev/script/gen_requirements_all.py#L34 and then rerun it and commit the changed files.

Comment thread tests/testing_config/automations.yaml Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please remove this file.

@finish06 finish06 mentioned this pull request Jun 7, 2017
@balloob
Copy link
Copy Markdown
Member

balloob commented Jun 9, 2017

@finish06 please make sure that APIError extends Exception:

class APIError(Exception):
    """Base class for unifi errors."""
    pass

@finish06
Copy link
Copy Markdown
Contributor Author

finish06 commented Jun 9, 2017

@balloob I definitely have it setup in the manner you recommend. The error still occurs even though 'APIError' is a child of 'Exception'.

@balloob
Copy link
Copy Markdown
Member

balloob commented Jun 12, 2017

Ooooooooooooooooooooh I get it. The old unifi tests were mocking out the unify lib: https://github.com/home-assistant/home-assistant/blob/dev/tests/components/device_tracker/test_unifi.py#L13-L20

@finish06
Copy link
Copy Markdown
Contributor Author

@balloob alright, I am glad you had a eureka, however, my naivety prevents me from understanding what the implications of the new insight... I know that adding from pyunifi import controller which I thought would being that the fixture needs that imported (or so I thought).

@balloob
Copy link
Copy Markdown
Member

balloob commented Jun 13, 2017

That fixture patches the imported modules to always load a fake one. You can remove it and instead make sure that the controller is still mocked and returned from the fixture.

@balloob
Copy link
Copy Markdown
Member

balloob commented Jun 15, 2017

I tried something, not sure if it will work.

@balloob balloob added this to the 0.47 milestone Jun 17, 2017
@balloob balloob merged commit 6a017ef into home-assistant:dev Jun 17, 2017
balloob pushed a commit that referenced this pull request Jun 17, 2017
…tter accommodate login failures with wrapper in pyunifi 2.13. (#7899)

* Pyunifi update

* Update pyunifi_test

* Import API Error

* Adjust test_unifi.py to import APIError

* Remove urllib import

* Remove urllib import from test

* Try fix mock

* Remove automations.yaml

* Lint
@balloob
Copy link
Copy Markdown
Member

balloob commented Jun 17, 2017

Cherry-picked for 0.47 👍

@balloob balloob mentioned this pull request Jun 17, 2017
@balloob balloob mentioned this pull request Jul 1, 2017
@home-assistant home-assistant locked and limited conversation to collaborators Oct 20, 2017
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.

5 participants