-
-
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
Vesync Display Switch Feature #137493
base: dev
Are you sure you want to change the base?
Vesync Display Switch Feature #137493
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
|
Can we can use I was originally working on this (dev...iprak:core-fork:auto-stop-display-switches-for-humidifier) when I noticed it to be partially implemented. I got that fixed (webdjoe/pyvesync#293) but it hasn't been released. |
I have updated - I will put to draft until that release is done and merged. |
Looking forward to this one! I’d love to automate switching off that bright display at night. Edit: Feature request in the community forums: https://community.home-assistant.io/t/vesync-set-the-night-light-on-levoit-air-purifiers/367463 |
This is ready for review. Two notes:
I will dig into this. I personally don't think this is a deal breaker as other device models work. I have created an issue within the library and will spend some future time on that. |
Solves 131 in webdjoe/pyvesync#305. |
@pytest.mark.parametrize( | ||
("api_response", "expectation"), | ||
[(False, pytest.raises(HomeAssistantError)), (True, NoException)], | ||
) | ||
async def test_turn_on_display( | ||
hass: HomeAssistant, | ||
humidifier_config_entry: MockConfigEntry, | ||
api_response: bool, | ||
expectation, | ||
) -> None: | ||
"""Test turn_on method.""" | ||
|
||
# turn_on_display returns False indicating failure in which case switch.turn_on_display | ||
# raises HomeAssistantError. | ||
with ( | ||
expectation, | ||
patch( | ||
"pyvesync.vesyncfan.VeSyncHumid200300S.turn_on_display", | ||
return_value=api_response, | ||
) as method_mock, | ||
): | ||
with patch( | ||
"homeassistant.components.vesync.switch.VeSyncSwitchEntity.schedule_update_ha_state" | ||
) as update_mock: | ||
await hass.services.async_call( | ||
SWITCH_DOMAIN, | ||
SERVICE_TURN_ON, | ||
{ATTR_ENTITY_ID: ENTITY_SWITCH_DISPLAY}, | ||
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_display( | ||
hass: HomeAssistant, | ||
humidifier_config_entry: MockConfigEntry, | ||
api_response: bool, | ||
expectation, | ||
) -> None: | ||
"""Test turn_off method.""" | ||
|
||
# turn_off_display returns False indicating failure in which case switch.turn_off_display | ||
# raises HomeAssistantError. | ||
with ( | ||
expectation, | ||
patch( | ||
"pyvesync.vesyncfan.VeSyncHumid200300S.turn_off_display", | ||
return_value=api_response, | ||
) as method_mock, | ||
): | ||
with patch( | ||
"homeassistant.components.vesync.switch.VeSyncSwitchEntity.schedule_update_ha_state" | ||
) as update_mock: | ||
await hass.services.async_call( | ||
SWITCH_DOMAIN, | ||
SERVICE_TURN_OFF, | ||
{ATTR_ENTITY_ID: ENTITY_SWITCH_DISPLAY}, | ||
blocking=True, | ||
) | ||
|
||
await hass.async_block_till_done() | ||
method_mock.assert_called_once() | ||
update_mock.assert_called_once() |
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 it's more useful and logical to switch the way we parametrize. Have 1 test for all the failing service calls, and have 1 test for all the working service calls, since the only thing you have to change is the function called and the service name.
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.
To confirm are you thinking a consolidated test across all platforms so also parametrize a few other values or just within the platform?
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
I have updated the tests to focus on parameters. A single fixture now can setup any device. The on_off tests in turn can run on multiple platforms. This PR is required before my other ones with this issue as it holds the core test structure. Others will now just adjust the dictionary to add more tests. Let me know if off/on should be two tests or if okay within the same test like it is right now. |
Hello. Light control on CORE200S does not work. "select/select_option. 'VeSyncAirBypass' object has no attribute 'set_night_light_brightness' |
This issue is logged here - #140236 |
@joostlek tests have been updated. Please let me know if this matches the goal. If so I will update the tests on the other PRs. |
Not sure if this is the proper place for this, but with all the recent refactors, I found an issue with an older Voltson ESW01outlet, which is of device_type "wifi-switch-1.3" with firmware version 2.125. Home Assistant can no longer retrieve the power state of this plug, nor toggle it... (My identical looking plugs that are working fine report in as "ESW03-USA" (firmware 1.1.30). I'm not a python dev, so I have no idea how to provide more info or help, but I did some basic tests with the newest released pyvesync library and was able to toggle that plug state and had no issue controlling all of my plugs directly via a simplified test case. The only differences I can see are when I dumped both plug objects. For device_type: ESW03-USA, the cid is a random string. Let me know how I can provide more info or what the process is if this needs to be created as a separate issue |
@jcefoli I don't think so. See top of the issue:
In this case, I think it's just specific to humidifers and purifiers (e.g. like the Levoit 131S, see code). I think the "switch" in this case is in reference to the software switch presented by HA, not a physical wifi switch device. |
This is a new feature that hasn't been merged yet. Please open an issue under the issues tab and we can take a look. |
'last_changed': <ANY>, | ||
'last_reported': <ANY>, | ||
'last_updated': <ANY>, | ||
'state': 'unavailable', |
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.
Why is this one unavailable? It might sound like there's a bug here?
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 you are right. I adjusted this so it fails while we figure this out. I think a test has an issue as I own a 131 and it works. I updated some of the json files as they seemed incorrect without luck. @iprak thoughts?
Proposed change
Adds the screen switch for both fan and humidifier device. Tested on my physical humidifier and air purifier.
This also consolidates on/off testing so it can run parameter based tests.
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: