-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
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
Epson projector support #14841
Conversation
There was a problem hiding this 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!
Merge conflict resolved. |
class EpsonProjector(MediaPlayerDevice): | ||
"""Representation of Epson Projector Device.""" | ||
|
||
def __init__(self, hass, name, host, port, encryption): |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
All requested changes are done. |
vol.Optional(CONF_SSL, default=False): cv.boolean | ||
}) | ||
|
||
SERVICE_ATTR_CMODE = 'epson_cmode' |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
All reviewed changes done. |
vol.Optional(CONF_SSL, default=False): cv.boolean | ||
}) | ||
|
||
SERVICE_ATTR_CMODE = 'epson_select_cmode' |
There was a problem hiding this comment.
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
.
done |
Added description of cmode to services.yaml
change name of cmode service
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):Checklist:
tox
. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
REQUIREMENTS
variable (example).requirements_all.txt
by runningscript/gen_requirements_all.py
..coveragerc
.If the code does not interact with devices: