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 support for Philips TVs with jointSPACE API #4157

Merged
merged 6 commits into from Nov 3, 2016
Merged

Added support for Philips TVs with jointSPACE API #4157

merged 6 commits into from Nov 3, 2016

Conversation

danielperna84
Copy link
Contributor

@danielperna84 danielperna84 commented Oct 31, 2016

Description:
This PR adds support for TVs that expose the jointSPACE API. As far as I can tell, this almost exlusively applies to TVs produced by Philips, which is why the platform is called philips_js.
A list of supported models (and how to enable the API) can be found at the jointSPACE site linked above. As a rule of thumb I would guess most TVs produced after 2010 could have the API baked into the firmware. Although I don't know if the recent models with Android TV have it too. I kind of doubt that.
To see if your TV has the API enabled, browse to it's IP at port 1925. If the API is enabled you'll see the documentation. There's even more possible with the API than I have implemented, but I'll leave that to someone else. Currently it's possible to turn off the TV, switch the input source, increase, decrease or mute the volume.
If you wonder what's the deal with the self._connfail: the webserver inside those TVs seems to be unstable at some times. If it for some reason is (too many requests?), the next few attempts to make requests are skipped to give it some time to get back on track.

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

Example entry for configuration.yaml (if applicable):

media_player:
- platform: philips_js
  name: Testname
  host: 192.168.1.33

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 files were added to .coveragerc.

@Throttle(MIN_TIME_BETWEEN_UPDATES)
def update(self):
"""Get the latest date and update device state."""
try:
Copy link
Member

Choose a reason for hiding this comment

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

Home Assistant should not contain any protocol specific code. Could you extract this into a 3rd party lib and add that as a requirement to this 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.

I'm aware of that. I did it like this for two reasons: 1. Creating an extra lib for a handful of requests seems like a little overkill. And even more important: 2. The jointSPACE API seems to be a dead project, so I won't expect any changes which would have to be taken care of in this platform. But if you insist, I'll do it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done with creating the library. Will do the implementation soon. :)

@property
def state(self):
"""Get the device state. An exception means OFF state."""
try:
Copy link
Member

Choose a reason for hiding this comment

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

We should never do any I/O inside a property. It should only return cached values.

DEFAULT_DEVICE = 'default'
DEFAULT_HOST = '127.0.0.1'
DEFAULT_NAME = 'Philips TV'
DEVICE_BASE_URL = 'http://{0}:1925/1/{1}'
Copy link
Member

Choose a reason for hiding this comment

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

This lead to the assumption that the port can not be changed by the user on the TV, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is correct. The API always runs on port 1925.

add_devices([PhilipsJS(host, name)])


# pylint: disable=too-many-instance-attributes,abstract-method
Copy link
Member

Choose a reason for hiding this comment

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

too-many-instance-attributes is now globally disabled.

@balloob
Copy link
Member

balloob commented Nov 3, 2016

Awesome, thanks ! 🐬

@balloob balloob merged commit 8e0838a into home-assistant:dev Nov 3, 2016
@home-assistant home-assistant locked and limited conversation to collaborators Mar 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants