home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.38k stars 30.64k forks source link

Vesync integration is not returning any devices #61417

Closed briantenazas closed 2 years ago

briantenazas commented 2 years ago

The problem

Hi!

I have a Levoit Core 200s and wanted to use the Vesync integration since I have been controlling the device via the Vesync app. When I login to the integration, nothing happens. The integration does not pull in the device.

I tried adding the raw github code from HA core as a custom component and added some additional logging. When it runs manager.update, it returns zero devices. I tried forcing it via manager.get_devices and received the error below.

I'm not sure if this is an API error, an issue with the pyVesync library or its integration with HA. I don't receive a login error and running manager.enabled returns true, so it looks like it's accepting my credentials.

What version of Home Assistant Core has the issue?

core-2021.11.5

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

vesync

Link to integration documentation on our website

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2021-12-10 00:11:15 WARNING (MainThread) [homeassistant.util.async_] Detected I/O inside the event loop. This is causing stability issues. Please report issue to the custom component author for vesync doing I/O at custom_components/vesync/common.py, line 18: _LOGGER.info(manager.get_devices())
2021-12-10 00:11:15 WARNING (MainThread) [pyvesync.helpers] I/O must be done in the executor; Use `await hass.async_add_executor_job()` at custom_components/vesync/common.py, line 18: _LOGGER.info(manager.get_devices())
2021-12-10 00:11:15 WARNING (MainThread) [pyvesync.vesync] Error retrieving device list
2021-12-10 00:11:15 INFO (MainThread) [custom_components.vesync.common] False

Additional information

Log error is a result of this:


  """Assign devices to proper component."""
    devices = {}
    devices[VS_SWITCHES] = []
    devices[VS_FANS] = []
    devices[VS_LIGHTS] = []

    _LOGGER.info(manager.get_devices())

    await hass.async_add_executor_job(manager.update)
FidgetyRat commented 2 years ago

Same issue as the OP with the same device. Works fine in vesync app.

FidgetyRat commented 2 years ago

I bought a second device recently. When removing and adding the integration, the new device is now showing up, but the older device is not, both Core 200S filters.

FidgetyRat commented 2 years ago

As an additional update, I used pyvesync directly from the command line and logged in. It's only returning one of my two devices in its manager.fans list, so looks to be something on the pyvesync or vsync side.

FidgetyRat commented 2 years ago

It turns out there is actually multiple models of the Core 200S which explains why it won't show up. The box it came in was labeled as a Core 200S but the device itself has a different model on its sticker than my other Core 200S.

Model: LAP-C201S-AUSR

Which is clearly not supported by the integration nor pyvesync.

I may fork some changes to support either model number since they are technically the same device.

briantenazas commented 2 years ago

Interesting. That's the model I have as well, which definitely explains why I can't see it.

FidgetyRat commented 2 years ago

I would normally make a custom component until fixed, but since this relies on both changes to the integration as well as the underlying pyvesync library there will need to be some coordination between the integration devs and the pyvesync library itself.

In the mean time, if you want to manually make the change yourself to support the device, it's a very minor change to two files. These will get overwritten each time you update homeassistant, so if you do make the change keep a record so you can update the files next update as well..

Note: My directory paths reflect the homeassistant core installation in a python virtual environment, your paths to the core files may vary.

You can see by the code snippets that I simply duplicated the few references describing the Core200S to support both models.

The HA Integration /srv/homeassistant/lib/python3.9/site-packages/homeassistant/components/vesync/fan.py

DEV_TYPE_TO_HA = {
    "LV-PUR131S": "fan",
    "LAP-C201S-AUSR": "fan",
    "Core200S": "fan",
    "Core400S": "fan",
}

FAN_MODE_AUTO = "auto"
FAN_MODE_SLEEP = "sleep"

PRESET_MODES = {
    "LV-PUR131S": [FAN_MODE_AUTO, FAN_MODE_SLEEP],
    "Core200S": [FAN_MODE_SLEEP],
    "LAP-C201S-AUSR": [FAN_MODE_SLEEP],
    "Core400S": [FAN_MODE_AUTO, FAN_MODE_SLEEP],
}
SPEED_RANGE = (1, 3)  # off is not included

The PyVesync Library /srv/homeassistant/lib/python3.9/site-packages/pyvesync/vesync.py

_DEVICE_CLASS: Dict[str, Any] = {
    'wifi-switch-1.3': VeSyncOutlet7A,
    'ESW03-USA': VeSyncOutlet10A,
    'ESW01-EU': VeSyncOutlet10A,
    'ESW15-USA': VeSyncOutlet15A,
    'ESWL01': VeSyncWallSwitch,
    'ESWL03': VeSyncWallSwitch,
    'LV-PUR131S': VeSyncAir131,
    'ESO15-TB': VeSyncOutdoorPlug,
    'ESL100': VeSyncBulbESL100,
    'ESL100CW': VeSyncBulbESL100CW,
    'ESWD16': VeSyncDimmerSwitch,
    'Classic300S': VeSyncHumid300S,
    'Core200S': VeSyncAir200S300S,
    'LAP-C201S-AUSR': VeSyncAir200S300S,
    'Core300S': VeSyncAir200S300S,
    'Core400S': VeSyncAir400S,
}

_DEVICE_TYPES_DICT: Dict[str, List[str]] = dict(
    outlets=['wifi-switch-1.3', 'ESW03-USA',
             'ESW01-EU', 'ESW15-USA', 'ESO15-TB'],
    switches=['ESWL01', 'ESWL03', 'ESWD16'],
    fans=['LV-PUR131S', 'Classic300S', 'Core200S', 'LAP-C201S-AUSR', 'Core300S', 'Core400S'],
    bulbs=['ESL100', 'ESL100CW'],
)

The model needs to be added in two places in both files. Fortunately they are right next to each other in the code, so just make sure you get each spot.

Make sure you delete the pycache directory in both these locations so that the cached python scripts get re-generated the next time you start homeassistant.

After these changes, HA should be able to handle both models of the Core200S. (At least it did for me)

I suppose in the end, a simpler change may be to have the pyvesync code translate the alternate model to Core200S when it is first detected, that way the remainder of the code as well as the HomeAssistant integration can go unchanged as the vesync library will just treat both as the same device at the time of detection.

probot-home-assistant[bot] commented 2 years ago

Hey there @markperdue, @webdjoe, @thegardenmonkey, mind taking a look at this issue as it has been labeled with an integration (vesync) you are listed as a code owner for? Thanks! (message by CodeOwnersMention)


vesync documentation vesync source (message by IssueLinks)

kevchu3 commented 2 years ago

Like @briantenazas, I have a Levoit Core 200s and have Vesync integration with my Home Assistant for the past year or so, but it's never shown my device. I strongly suspect that I'm running into the same issue as what's reported here.

In HA, how can I pull the latest pyvesync code to help test this integration? Do we expect this to be merged into HA core's code rather quickly, or should we just work off of upstream pyvesync code for now?

MarkRMonaco commented 2 years ago

I have this issue as well and cannot get my Core 200s to be detected. I just purchased it so I am assuming it's the newer revision that others have mentioned.

polonel commented 2 years ago

My Core 200s were showing up fine until the last 2 days. Now they show as unavailable in HA but work fine in the vesync app. Seems like they did an update.

MarkRMonaco commented 2 years ago

I cannot comment on the past few days since I only had my purifier since yesterday. However, I wound up adding the additional code that @FidgetyRat provided. Once I restarted HA, my 200s was immediately detected.

kevchu3 commented 2 years ago

Hey folks, since pyvesync v1.4.3 has now been released, I've implemented @FidgetyRat's workaround in a formal PR against core. There are a number of differences between functions and variables exposed by fans and humidifiers, and thus this wasn't as easy as the code snippet above. Take a look at the following PR and if you can test against it, that would be great:

As an aside, I have a Classic 200S and Dual 200S at home and was thus able to test against these two models. I hesitate to add support for any other models that I can't formally run tests against.

wesgeorge commented 2 years ago

I'm having the same problem, but I suspect this is because my only VeSync device is a Levoit Core 600S, which is fairly new and doesn't appear to have made it into the supported list yet. I'll be happy to open a separate issue for that, but not completely sure if that's considered a bug or a new feature request.

borpin commented 2 years ago

Just to note pyvesync has moved to V2.0.0 so there may be more devices available to integrate.

adityapavan18 commented 2 years ago

Yes, pyvesync 2.0.0 has been released recently and supports multiple new leviot Devices work in that. Do we know when these new devices will be added to home assistant code ? I have a humidifier 600s and air purifier 400s working great in pyvesync 2.0.0. Would be great if relates changes are made in ha core to include this new version library and devices

borpin commented 2 years ago

There is a PR #62907 open to do just that (the pyvesync version has just been bumped I believe). For now there is a custom component available here. https://github.com/vlebourl/custom_vesync

github-actions[bot] commented 2 years ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.