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

Added Twitch v5 support to the twitch platform #16428

Merged
merged 15 commits into from
Sep 6, 2018
Merged

Added Twitch v5 support to the twitch platform #16428

merged 15 commits into from
Sep 6, 2018

Conversation

miawgogo
Copy link
Contributor

@miawgogo miawgogo commented Sep 4, 2018

THIS IS A BREAKING CHANGE

Description:

This is an update that changes the library use for the twitch sensor, this is a breaking change due to api Changes on twitch's side where all api users require a client_id. I have also made it set the sensor icon to the channels logo when they are not live, as it looks nice.

Middle is live, the others are offline

Middle is live, the others are offline

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

Example entry for configuration.yaml (if applicable):

sensor:
  - platform: twitch
    clientid: "clientid"
    channels:
    - user1
    - user2

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass

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

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

  • New dependencies have been added to the REQUIREMENTS variable (example).
  • New dependencies are only imported inside functions that use them (example). kind of, i set up the client in the setup and pass the client through to the entities, you can ask me to change this
  • New or updated dependencies have been added to requirements_all.txt by running script/gen_requirements_all.py.

If the code does not interact with devices:

  • Tests have been added to verify that the new code works.

@ghost ghost added the in progress label Sep 4, 2018
@@ -72,15 +81,15 @@ def entity_picture(self):
# pylint: disable=no-member
def update(self):
"""Update device state."""
from twitch.api import v3 as twitch
stream = twitch.streams.by_channel(self._channel).get('stream')
id = self._client.users.translate_usernames_to_ids([self._channel])[0].id

Choose a reason for hiding this comment

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

local variable 'id' is assigned to but never used
line too long (81 > 79 characters)

@@ -34,16 +37,22 @@
def setup_platform(hass, config, add_entities, discovery_info=None):
"""Set up the Twitch platform."""
channels = config.get(CONF_CHANNELS, [])
from twitch import TwitchClient as TwitchClient
client=TwitchClient(client_id=config.get(CONF_CLIENTID))

Choose a reason for hiding this comment

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

missing whitespace around operator

channels = config.get(CONF_CHANNELS, [])
client=TwitchClient(client_id=config.get(CONF_CLIENTID))

Choose a reason for hiding this comment

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

missing whitespace around operator

channels = config.get(CONF_CHANNELS, [])

add_entities([TwitchSensor(channel) for channel in channels], True)
client=TwitchClient(client_id=config.get(CONF_CLIENTID))

Choose a reason for hiding this comment

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

missing whitespace around operator

@miawgogo miawgogo changed the title [wip]added Twitch v5 support to the twitch component, This is a breaking change added Twitch v5 support to the twitch component, This is a breaking change Sep 4, 2018
@miawgogo miawgogo changed the title added Twitch v5 support to the twitch component, This is a breaking change added Twitch v5 support to the twitch component Sep 5, 2018
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.

tests/testing_config/.storage/core.entity_registry should be part of this PR.

homeassistant/components/sensor/twitch.py Outdated Show resolved Hide resolved
homeassistant/components/sensor/twitch.py Outdated Show resolved Hide resolved
@fabaff fabaff changed the title added Twitch v5 support to the twitch component Added Twitch v5 support to the twitch platform Sep 5, 2018
@miawgogo
Copy link
Contributor Author

miawgogo commented Sep 5, 2018

tests/testing_config/.storage/core.entity_registry

i assume this shoulent be in there, I have removed it from my branch

return False
else:
_LOGGER.error("Test API call failed")
return False

Choose a reason for hiding this comment

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

indentation is not a multiple of four

_LOGGER.error("Test API call failed, Check your client_id")
return False
else:
_LOGGER.error("Test API call failed")

Choose a reason for hiding this comment

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

indentation is not a multiple of four

@ghost ghost assigned fabaff Sep 6, 2018
@fabaff fabaff merged commit ce06229 into home-assistant:dev Sep 6, 2018
@ghost ghost removed the in progress label Sep 6, 2018
@miawgogo miawgogo deleted the twitchv5 branch September 6, 2018 12:56
client.ingests.get_server_list()
except HTTPError:
_LOGGER.error("Client ID is not valid")
return False
Copy link
Member

Choose a reason for hiding this comment

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

Nothing is checking this return value.

Copy link
Contributor Author

@miawgogo miawgogo Sep 7, 2018

Choose a reason for hiding this comment

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

the orignial code did check this by checking for a 400 error, for the endpoint im using 400 error should only be caused by a missing client id

        if http_error.response.status_code == 400:
            _LOGGER.error("Test API call failed, Check your client_id")
        else:
            _LOGGER.error("Test API call failed")
        return False```

Copy link
Member

Choose a reason for hiding this comment

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

No, nothing is checking this return value. Don't return False, just return.

@miawgogo miawgogo restored the twitchv5 branch September 7, 2018 13:22
@balloob balloob mentioned this pull request Sep 17, 2018
@home-assistant home-assistant locked and limited conversation to collaborators Dec 10, 2018
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