Skip to content

Register 'firetv.adb_command' service#21419

Merged
MartinHjelmare merged 11 commits into
home-assistant:devfrom
JeffLIrion:dev
Feb 28, 2019
Merged

Register 'firetv.adb_command' service#21419
MartinHjelmare merged 11 commits into
home-assistant:devfrom
JeffLIrion:dev

Conversation

@JeffLIrion
Copy link
Copy Markdown
Contributor

@JeffLIrion JeffLIrion commented Feb 24, 2019

Description:

Register media_player.firetv_adb_cmd service so that users can send custom ADB commands to their device(s).

Related issue (if applicable): fixes #

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

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.

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).
  • New or updated 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:

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

Comment thread homeassistant/components/media_player/firetv.py Outdated
Comment thread homeassistant/components/media_player/firetv.py Outdated
Comment thread homeassistant/components/media_player/firetv.py Outdated
Comment thread homeassistant/components/media_player/firetv.py Outdated
@elupus
Copy link
Copy Markdown
Contributor

elupus commented Feb 25, 2019

should custom services really be in media_player?

@MartinHjelmare
Copy link
Copy Markdown
Member

Until we've moved the platform to its own component, it's ok. Moving all platforms under component packages is a work in progress. New platforms should go under their own components and register platform specific services under their component.

@andrewsayre
Copy link
Copy Markdown
Member

Until we've moved the platform to its own component, it's ok. Moving all platforms under component packages is a work in progress. New platforms should go under their own components and register platform specific services under their component.

We're enforcing this rule now. This should be moved to a new component to register the service. One less breaking change if done later.

@MartinHjelmare
Copy link
Copy Markdown
Member

MartinHjelmare commented Feb 25, 2019

It's only enforced for new platforms.

That's at least my understanding from reading the messages. I wouldn't mind enforcing it further.

@JeffLIrion JeffLIrion changed the title Register 'media_player.firetv_adb_cmd' service Register 'media_player.firetv_adb_command' service Feb 25, 2019
@JeffLIrion
Copy link
Copy Markdown
Contributor Author

Until we've moved the platform to its own component, it's ok. Moving all platforms under component packages is a work in progress. New platforms should go under their own components and register platform specific services under their component.

We're enforcing this rule now. This should be moved to a new component to register the service. One less breaking change if done later.

I'm not very familiar with the planned architectural changes. However, seeing as this migration hasn't happened yet and there are plenty of component-specific services under the media_player platform, I would prefer to get this service integrated first and move the Fire TV component (including this service) into its own platform when all the other components get moved.

@JeffLIrion JeffLIrion closed this Feb 25, 2019
@JeffLIrion JeffLIrion reopened this Feb 25, 2019
@ghost ghost added in progress and removed in progress labels Feb 25, 2019
@JeffLIrion JeffLIrion closed this Feb 26, 2019
@ghost ghost removed the in progress label Feb 26, 2019
@JeffLIrion JeffLIrion reopened this Feb 26, 2019
@ghost ghost added the in progress label Feb 26, 2019
@JeffLIrion
Copy link
Copy Markdown
Contributor Author

@MartinHjelmare, @elupus, @andrewsayre what should I do for this pull request?

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

I think it's a good point that we should avoid breaking changes if we can.

  • Make a firetv package with an init module, __init__.py, with only docstring.
  • Git move the firetv.py media_player platform to that firetv package and name it media_player.py.
  • Register the service under the new firetv domain, from the media_player platform.

@JeffLIrion
Copy link
Copy Markdown
Contributor Author

JeffLIrion commented Feb 26, 2019

I think it's a good point that we should avoid breaking changes if we can.

  • Make a firetv package with an init module, __init__.py, with only docstring.
  • Git move the firetv.py media_player platform to that firetv package and name it media_player.py.
  • Register the service under the new firetv domain, from the media_player platform.

Thanks.

Edit: I think I figured out the answers to the first two questions.

  1. Will this change the configuration for users? Or will it still be:
    media_player:
    - platform: firetv
      name: Fire TV
      ...
    • Answer: no change
  2. Will services such as media_player.media_play become firetv.media_play?
    • Answer: no
  3. Am I supposed to define a constant DOMAIN = 'firetv'? Should this be in __init__.py or media_player.py?

@JeffLIrion
Copy link
Copy Markdown
Contributor Author

Simple bash script for moving firetv to its own platform:

#!/bin/bash

# running in: home-assistant/homeassistant/components/media_player
export PLATFORM="firetv"

mkdir -p ../$PLATFORM
if [ ! -f "../$PLATFORM/__init__.py" ]; then
    # TODO: copy the docstring
    touch ../$PLATFORM/__init__.py;
fi

git add ../$PLATFORM/__init__.py
git mv $PLATFORM.py ../$PLATFORM/media_player.py

@MartinHjelmare
Copy link
Copy Markdown
Member

  1. Configuration will remain the same.
  2. No, standard services will remain registered under media_player domain. Only the new custom service should be registered under the firetv domain.
  3. It's not required to define a domain constant in the firetv media_player module. If you want to use a constant when registering the service you can eg define FIRETV_DOMAIN = 'firetv' in that module.

It's not clear to me what domain we consider the moved firetv media_player platform to belong to. If it's media_player or firetv?

@JeffLIrion
Copy link
Copy Markdown
Contributor Author

@MartinHjelmare I called it DOMAIN, but I can change it to FIRETV_DOMAIN.

Also, I don't know why the build is failing. I don't think it's due to any changes I made in this pull request.

@JeffLIrion JeffLIrion changed the title Register 'media_player.firetv_adb_command' service Register 'firetv.adb_command' service Feb 26, 2019
@JeffLIrion
Copy link
Copy Markdown
Contributor Author

Also, in the services tab, the "Entity" menu doesn't populate correctly. Any idea what I need to do to fix that?

@JeffLIrion
Copy link
Copy Markdown
Contributor Author

The build failed, but I'm pretty sure it has nothing to do with my changes.

lint runtests: commands[0] | python script/gen_requirements_all.py validate
******* ERROR
requirements_all.txt is not up to date
Please run script/gen_requirements_all.py
ERROR: InvocationError for command '/home/travis/build/home-assistant/home-assistant/.tox/lint/bin/python script/gen_requirements_all.py validate' (exited with code 1)

@MartinHjelmare
Copy link
Copy Markdown
Member

We have moved the file that contains a requirement spec. Please follow the instructions and run the script.

Also update coveragerc.

@JeffLIrion JeffLIrion closed this Feb 27, 2019
@JeffLIrion JeffLIrion reopened this Feb 27, 2019
@ghost ghost added in progress and removed in progress labels Feb 27, 2019
@JeffLIrion
Copy link
Copy Markdown
Contributor Author

I looked in the logs for both of the failed tests and it doesn't look like the failures have anything to do with the Fire TV platform.

@JeffLIrion JeffLIrion closed this Feb 27, 2019
@ghost ghost removed the in progress label Feb 27, 2019
@JeffLIrion JeffLIrion reopened this Feb 27, 2019
@ghost ghost added the in progress label Feb 27, 2019
@balloob
Copy link
Copy Markdown
Member

balloob commented Feb 27, 2019

I agree with registering services under the name of the integration . That is what we should do moving forward.

@JeffLIrion
Copy link
Copy Markdown
Contributor Author

The build passed! Any other changes needed before merging this?

Copy link
Copy Markdown
Member

@MartinHjelmare MartinHjelmare left a comment

Choose a reason for hiding this comment

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

Nice!

@MartinHjelmare MartinHjelmare merged commit 27a780d into home-assistant:dev Feb 28, 2019
@ghost ghost removed the in progress label Feb 28, 2019
@JeffLIrion
Copy link
Copy Markdown
Contributor Author

Thanks @MartinHjelmare for your help with this PR and the previous one, and thanks to @carstenschroeder for inspiring this change with #20673.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants