Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Epson projector support #14841

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

Merged
merged 7 commits into from
Jun 13, 2018
Merged

Epson projector support #14841

merged 7 commits into from
Jun 13, 2018

Conversation

pszafer
Copy link
Contributor

@pszafer pszafer commented Jun 6, 2018

Description:

I created epson projector support.
It is based on Android app (packet sniffing) from epson.
Tested with Epson EH-TW5350

Made new PR to get rid of mistakes I made trying to catch up with reality.
Old PR: #13416

Related issue (if applicable): fixes #

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

Example entry for configuration.yaml (if applicable):

- platform: epson
  host: 192.168.1.2
  name: Epson Projector

Checklist:

  • The code change is tested and works locally.
  • Local tests pass with tox. Your PR cannot be merged unless tests pass
Tests passed but needed to change test_feedreader.py date time from 5 to 6.
datetime(2018, 4, 30, 6, 10, 0)

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.

syssi
syssi previously approved these changes Jun 9, 2018
Copy link
Member

@syssi syssi left a comment

Choose a reason for hiding this comment

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

LGTM. Please resolve the merge conflict!

@ghost ghost added the in progress label Jun 9, 2018
@pszafer
Copy link
Contributor Author

pszafer commented Jun 9, 2018

Merge conflict resolved.

class EpsonProjector(MediaPlayerDevice):
"""Representation of Epson Projector Device."""

def __init__(self, hass, name, host, port, encryption):
Copy link
Member

Choose a reason for hiding this comment

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

Don't pass in hass. It will be set on the entity when it has been added to home assistant.

except (aiohttp.client_exceptions.ClientConnectorError,
asyncio.TimeoutError):
raise PlatformNotReady
if epson:
Copy link
Member

Choose a reason for hiding this comment

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

Remove this check. It doesn't add anything.

devices = hass.data[DATA_EPSON]
for device in devices:
if service.service == ATTR_CMODE:
cmode = service.data.get(ATTR_CMODE).lower()
Copy link
Member

Choose a reason for hiding this comment

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

The string cast to lowercase should be moved to the service schema.

await device.select_cmode(cmode)
await device.update()
hass.services.async_register(
DOMAIN, ATTR_CMODE, async_service_handler,
Copy link
Member

Choose a reason for hiding this comment

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

The service name should be prefixed with the platform name. The constant that holds the service name should start with SERVICE_.


def __init__(self, hass, name, host, port, encryption):
"""Initialize entity to control Epson projector."""
self._hass = hass
Copy link
Member

Choose a reason for hiding this comment

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

Remove this.

return self._source

@property
def cmode(self):
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't seem to be used and is not needed. The instance can access the attribute directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I delete methods source_list and source, then select source option is not showing up in web ui.

Copy link
Member

Choose a reason for hiding this comment

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

Don't remove those. Comments in reviews are directed at the line at the end of the code box shown. In this case that's line 181. So I was only referring to the cmode property.

"""Set color mode in Epson."""
from epson_projector.const import (CMODE_LIST_SET)
if cmode in CMODE_LIST_SET:
return await self._projector.send_command(CMODE_LIST_SET[cmode])
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. It also makes the return value inconsistent since the call is done inside a check. Just remove the return.

for device in devices:
if service.service == ATTR_CMODE:
cmode = service.data.get(ATTR_CMODE).lower()
if cmode in CMODE_LIST_SET:
Copy link
Member

@MartinHjelmare MartinHjelmare Jun 9, 2018

Choose a reason for hiding this comment

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

This should be made part of the service validation schema. Make a custom validator that checks that the passed cmode is in the cmode list set.

Caveat is that the service schema cannot be defined as a constant at the module level anymore but has to be moved inside the setup platform function to allow access to the imported CMODE_LIST_SET.

async def select_cmode(self, cmode):
"""Set color mode in Epson."""
from epson_projector.const import (CMODE_LIST_SET)
if cmode in CMODE_LIST_SET:
Copy link
Member

Choose a reason for hiding this comment

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

This can be removed after updating the service schema.

_LOGGER.debug("select source")
from epson_projector.const import INV_SOURCES
selected_source = INV_SOURCES[source]
return await self._projector.send_command(selected_source)
Copy link
Member

Choose a reason for hiding this comment

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

Remove return here and from all the following methods.

@syssi syssi dismissed their stale review June 10, 2018 06:20

Requested changes of Martin

@pszafer
Copy link
Contributor Author

pszafer commented Jun 11, 2018

All requested changes are done.

vol.Optional(CONF_SSL, default=False): cv.boolean
})

SERVICE_ATTR_CMODE = 'epson_cmode'
Copy link
Member

Choose a reason for hiding this comment

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

I think we should name this epson_set_cmode or epson_select_cmode.

SERVICE_SELECT_CMODE = 'epson_select_cmode'

for device in devices:
if service.service == SERVICE_ATTR_CMODE:
cmode = service.data.get(SERVICE_ATTR_CMODE)
if cmode in CMODE_LIST_SET:
Copy link
Member

Choose a reason for hiding this comment

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

This check can now be removed since the service validation schema is checking this.



async def async_setup_platform(
hass,
Copy link
Member

Choose a reason for hiding this comment

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

Please fill out the line as far as possible. That's more in line with home assistant style.

epson = EpsonProjector(
async_get_clientsession(hass, verify_ssl=False),
name, host,
config.get(CONF_PORT), config.get(CONF_SSL))
Copy link
Member

Choose a reason for hiding this comment

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

See above.

name, host,
config.get(CONF_PORT), config.get(CONF_SSL))
await epson.update()
if epson:
Copy link
Member

Choose a reason for hiding this comment

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

Remove this.

if cmode and cmode in CMODE_LIST:
self._cmode = CMODE_LIST.get(cmode, self._cmode)
source = await self._projector.get_property(SOURCE)
if source and source in SOURCE_LIST:
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.


async def async_select_source(self, source):
"""Select input source."""
_LOGGER.debug("select source")
Copy link
Member

Choose a reason for hiding this comment

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

Remove this. All service calls are already logged at info level by the core.


async def async_volume_up(self):
"""Increase volume."""
_LOGGER.debug("volume up")
Copy link
Member

Choose a reason for hiding this comment

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

Remove this.

"""Return device specific state attributes."""
attributes = {}
if self._cmode is not None:
attributes[SERVICE_ATTR_CMODE] = self._cmode
Copy link
Member

Choose a reason for hiding this comment

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

Use ATTR_CMODE as key.

@@ -422,3 +422,13 @@ blackbird_set_all_zones:
source:
description: Name of source to switch to.
example: 'Source 1'

epson_cmode:
Copy link
Member

Choose a reason for hiding this comment

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

Update this after updating the service name.

devices = hass.data[DATA_EPSON]
for device in devices:
if service.service == SERVICE_ATTR_CMODE:
cmode = service.data.get(SERVICE_ATTR_CMODE)
Copy link
Member

Choose a reason for hiding this comment

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

Use ATTR_CMODE for the service data key.

@pszafer
Copy link
Contributor Author

pszafer commented Jun 12, 2018

All reviewed changes done.

vol.Optional(CONF_SSL, default=False): cv.boolean
})

SERVICE_ATTR_CMODE = 'epson_select_cmode'
Copy link
Member

Choose a reason for hiding this comment

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

Please rename the constant to SERVICE_SELECT_CMODE.

@pszafer
Copy link
Contributor Author

pszafer commented Jun 12, 2018

done

@MartinHjelmare MartinHjelmare merged commit 2ac23c8 into home-assistant:dev Jun 13, 2018
@ghost ghost removed the in progress label Jun 13, 2018
awarecan pushed a commit to awarecan/home-assistant that referenced this pull request Jun 13, 2018
* Epson projector support. Version based on external library

* Epson projector support. Version based on external library

* modified epson according to MartinHjelmare review.
Added description of cmode to services.yaml

* renamed EPSON_SCHEMA to epson_schema

* removed method of getting cmode property

* removed unnecessary checks
change name of cmode service

* renamed SERVICE_ATTR_CMODE to SERVICE_SELECT_CMODE
@balloob balloob mentioned this pull request Jun 22, 2018
girlpunk pushed a commit to girlpunk/home-assistant that referenced this pull request Sep 4, 2018
* Epson projector support. Version based on external library

* Epson projector support. Version based on external library

* modified epson according to MartinHjelmare review.
Added description of cmode to services.yaml

* renamed EPSON_SCHEMA to epson_schema

* removed method of getting cmode property

* removed unnecessary checks
change name of cmode service

* renamed SERVICE_ATTR_CMODE to SERVICE_SELECT_CMODE
@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.

4 participants