-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
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
Update Vesync light state after on / off commands #135958
base: dev
Are you sure you want to change the base?
Conversation
Hey there @markperdue, @webdjoe, @TheGardenMonkey, @iprak, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
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.
Does the device directly show the right state?
In the native app? Yes. Without this code Home Asssitant reverts back for a bit until next scan. |
Adjusted this to just focus on light.py, added tests as well. This aligns it with humidifer.py. This same work is in my fan refactor so this reduces overlap. |
@pytest.mark.parametrize( | ||
("api_response", "expectation"), | ||
[(False, pytest.raises(HomeAssistantError)), (True, NoException)], | ||
) | ||
async def test_turn_on( | ||
hass: HomeAssistant, | ||
light_config_entry: MockConfigEntry, | ||
api_response: bool, | ||
expectation, | ||
) -> None: | ||
"""Test turn_on method.""" | ||
|
||
# turn_on returns False indicating failure in which case light.turn_on | ||
# raises HomeAssistantError. | ||
with ( | ||
expectation, | ||
patch( | ||
"pyvesync.vesyncswitch.VeSyncDimmerSwitch.turn_on", | ||
return_value=api_response, | ||
) as method_mock, | ||
): | ||
with patch( | ||
"homeassistant.components.vesync.light.VeSyncBaseLightHA.schedule_update_ha_state" | ||
) as update_mock: | ||
await hass.services.async_call( | ||
LIGHT_DOMAIN, | ||
SERVICE_TURN_ON, | ||
{ATTR_ENTITY_ID: ENTITY_LIGHT}, | ||
blocking=True, | ||
) | ||
|
||
await hass.async_block_till_done() | ||
method_mock.assert_called_once() | ||
update_mock.assert_called_once() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
("api_response", "expectation"), | ||
[(False, pytest.raises(HomeAssistantError)), (True, NoException)], | ||
) | ||
async def test_turn_off( | ||
hass: HomeAssistant, | ||
light_config_entry: MockConfigEntry, | ||
api_response: bool, | ||
expectation, | ||
) -> None: | ||
"""Test turn_off method.""" | ||
|
||
# turn_off returns False indicating failure in which case light.turn_off | ||
# raises HomeAssistantError. | ||
with ( | ||
expectation, | ||
patch( | ||
"pyvesync.vesyncswitch.VeSyncDimmerSwitch.turn_off", | ||
return_value=api_response, | ||
) as method_mock, | ||
): | ||
with patch( | ||
"homeassistant.components.vesync.light.VeSyncBaseLightHA.schedule_update_ha_state" | ||
) as update_mock: |
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 comment as with the switch entity
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.
Planning to make the change here and then update this one it is merged. #137493
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
Proposed change
Commands for on and off were slow to show in the interface. This was do to no refresh occurring after it was sent. This also throws exceptions now if it fails vs nothing.
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
.To help with the load of incoming pull requests: