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

Changed update method to self.async_update_ha_state #18536

Closed
wants to merge 1 commit into from
Closed

Changed update method to self.async_update_ha_state #18536

wants to merge 1 commit into from

Conversation

pszafer
Copy link
Contributor

@pszafer pszafer commented Nov 17, 2018

Description:

Changed device.update to device.async_update_ha_state(force_refresh=True) and invoke state update after:

  • turn on
  • turn off
  • select cmode
  • source select.

If I don't invoke state updates than e.g. during turn_on it is switching to on in HA, than after some time it is switching to off and again after ~1 minute it is going on.

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.

@ghost ghost added the in progress label Nov 17, 2018
@fabaff fabaff changed the title Epson module - changed update method to self.async_update_ha_state Changed update method to self.async_update_ha_state Nov 18, 2018
@@ -75,7 +75,7 @@
if service.service == SERVICE_SELECT_CMODE:
cmode = service.data.get(ATTR_CMODE)
await device.select_cmode(cmode)
await device.update()
device.async_update_ha_state(force_refresh=True)
Copy link
Member

Choose a reason for hiding this comment

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

Use device.async_schedule_update_ha_state.

@@ -142,11 +142,13 @@ def supported_features(self):
"""Turn on epson."""
from epson_projector.const import TURN_ON
await self._projector.send_command(TURN_ON)
self.async_update_ha_state(force_refresh=True)
Copy link
Member

Choose a reason for hiding this comment

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

This isn't necessary since this is a polling entity. At the end of the service call a state update will be scheduled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So what could be wrong that without that it is switching on (for about 30 seconds) -> off (30 seconds) -> on?

Copy link
Member

Choose a reason for hiding this comment

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

Did you test all services?


async def async_turn_off(self):
"""Turn off epson."""
from epson_projector.const import TURN_OFF
await self._projector.send_command(TURN_OFF)
self.async_update_ha_state(force_refresh=True)
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.

@@ -167,12 +169,14 @@ def volume_level(self):
"""Set color mode in Epson."""
from epson_projector.const import (CMODE_LIST_SET)
await self._projector.send_command(CMODE_LIST_SET[cmode])
self.async_update_ha_state(force_refresh=True)
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.


async def async_select_source(self, source):
"""Select input source."""
from epson_projector.const import INV_SOURCES
selected_source = INV_SOURCES[source]
await self._projector.send_command(selected_source)
self.async_update_ha_state(force_refresh=True)
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.

@@ -102,7 +102,7 @@ def __init__(self, websession, name, host, port, encryption):
self._volume = None
self._state = None

async def update(self):
async def async_update(self):
Copy link
Member

Choose a reason for hiding this comment

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

Before this change, since this method was named update while being a coroutine, the method would never be executed. That's probably the reason for the behavior you've noticed.

@MartinHjelmare
Copy link
Member

MartinHjelmare commented Nov 18, 2018

#18357 is trying to fix the same problem.

@pszafer
Copy link
Contributor Author

pszafer commented Nov 19, 2018

Ok, let's close this as other one is already merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants