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 Discogs Sensor platform #10957

Merged
merged 9 commits into from Dec 18, 2017
Merged

Add Discogs Sensor platform #10957

merged 9 commits into from Dec 18, 2017

Conversation

thibmaek
Copy link
Contributor

@thibmaek thibmaek commented Dec 4, 2017

Description:

Pull request in home-assistant.github.io with documentation (if applicable): home-assistant/home-assistant.io#4138

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: discogs
    token: xxxxxxxx

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.

@thibmaek
Copy link
Contributor Author

thibmaek commented Dec 5, 2017

Not really sure how to fix linting errors from Travis:

./homeassistant/components/sensor/discogs.py:1:1: D100 Missing docstring in public module

C:  1, 0: Missing module docstring (missing-docstring)
ERROR: InvocationError: '/home/travis/build/home-assistant/home-assistant/.tox/pylint/bin/pylint homeassistant'

Other components didn't seem to do this when importing asyncio

"""Set up the discogs sensor."""
token = config.get(CONF_TOKEN)

async_add_devices([DiscogsCollection(token)], True)
Copy link
Member

@fabaff fabaff Dec 6, 2017

Choose a reason for hiding this comment

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

What happens if the token is not valid? I assume that there will be a traceback. It's preferred to check if the connection can be established, otherwise the users will end-up with a non-working 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.

Ok, I'm not at all sure how to do this, but I'll give it a try someday this week!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See DiscogsCollection#init which returns false if the user is not present

Copy link
Member

Choose a reason for hiding this comment

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

I guess that with an invalid token a discogs_client.exceptions.HTTPError will be thrown. This will happen before init return. The whole setup of the discogs client should happen in setup().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll try and check again but it probably won't be anytime soon.


REQUIREMENTS = ['discogs_client==2.2.1']

SCAN_INTERVAL = timedelta(seconds=7200)
Copy link
Member

Choose a reason for hiding this comment

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

Or hours=2.

"""Initialize the sensor."""
import discogs_client
discogs = discogs_client.Client(
'HomeAssistantDiscogs/0.1.0', user_token=token)
Copy link
Member

Choose a reason for hiding this comment

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

Can you please use SERVER_SOFTWARE (from homeassistant.helpers.aiohttp_client import SERVER_SOFTWARE)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead of the 'HomeAssistantDiscogs' string?

Copy link
Member

@fabaff fabaff left a comment

Choose a reason for hiding this comment

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

If you don't provide unit tests then you need to add your platform to .coveragerc.

@fabaff
Copy link
Member

fabaff commented Dec 6, 2017

Not really sure how to fix linting errors from Travis:

The file header is missing which is a docstring. E.g.,

"""
Support for stored record collections on Discogs.

For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/sensor.discogs/
"""


self._ds_user = discogs.identity()
self._state = None

Choose a reason for hiding this comment

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

blank line contains whitespace

Copy link
Member

@fabaff fabaff left a comment

Choose a reason for hiding this comment

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

Thanks 🐦

@fabaff fabaff merged commit 061395d into home-assistant:dev Dec 18, 2017
@balloob balloob mentioned this pull request Jan 11, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Mar 30, 2018
@ghost ghost added the integration: discogs label Mar 21, 2019
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

5 participants