Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Fix/fix fan discovery #21

Merged
merged 16 commits into from
Apr 27, 2022
Merged

Fix/fix fan discovery #21

merged 16 commits into from
Apr 27, 2022

Conversation

vlebourl
Copy link
Owner

Include missing air purifiers
Closing #19 (via #15, #16 and #18).

@github-actions github-actions bot added the bug Something isn't working label Apr 26, 2022
@vlebourl vlebourl linked an issue Apr 26, 2022 that may be closed by this pull request
3 tasks
@vlebourl vlebourl marked this pull request as draft April 26, 2022 13:07
@vlebourl vlebourl mentioned this pull request Apr 26, 2022
3 tasks
@kasper79
Copy link

Sorry, maybe it's my setup for the diagnostics downloading error? Doesn't appear to work for me, tried few diff browsers etc.

@vlebourl
Copy link
Owner Author

Sorry, maybe it's my setup for the diagnostics downloading error? Doesn't appear to work for me, tried few diff browsers etc.

No, my fix was not good. I pushed another one to try, and a fix for the PRESET.
I assumed your device has auto and sleep as preset modes, can you confirm?

@suth
Copy link

suth commented Apr 26, 2022

Core 200S (LAP-C201S-AUSR) is discovered via DHCP but no devices or entities are created. Seems like my issues are different from @kasper79

Logs:

2022-04-26 08:55:32 DEBUG (MainThread) [custom_components.vesync.config_flow] DHCP discovery detected device levoit-purifier
2022-04-26 08:56:04 DEBUG (SyncWorker_2) [custom_components.vesync.pyvesync.helpers] [post] calling '/cloud/v1/user/login' api
2022-04-26 08:56:05 DEBUG (SyncWorker_1) [custom_components.vesync.pyvesync.helpers] [post] calling '/cloud/v1/user/login' api
2022-04-26 08:56:05 DEBUG (SyncWorker_1) [custom_components.vesync.pyvesync.helpers] [post] calling '/cloud/v1/deviceManaged/devices' api
2022-04-26 08:56:05 DEBUG (SyncWorker_1) [custom_components.vesync.pyvesync.vesync] New device list initialized
2022-04-26 08:56:05 DEBUG (SyncWorker_1) [custom_components.vesync.pyvesync.helpers] [post] calling '/cloud/v2/deviceManaged/bypassV2' api
2022-04-26 08:56:05 INFO (MainThread) [custom_components.vesync.common] 1 VeSync fans found

Diagnostics:

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2022.4.7",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.9.9",
    "docker": true,
    "arch": "x86_64",
    "timezone": "America/Chicago",
    "os_name": "Linux",
    "os_version": "5.10.108",
    "supervisor": "2022.04.0",
    "host_os": "Home Assistant OS 7.6",
    "docker_version": "20.10.9",
    "chassis": "vm",
    "run_as_root": true
  },
  "custom_components": {
    "hacs": {
      "version": "1.24.5",
      "requirements": [
        "aiogithubapi>=21.11.0"
      ]
    },
    "vesync": {
      "version": "0.1.3",
      "requirements": []
    }
  },
  "integration_manifest": {
    "domain": "vesync",
    "name": "VeSync",
    "documentation": "https://www.home-assistant.io/integrations/vesync",
    "codeowners": [
      "@markperdue",
      "@webdjoe",
      "@thegardenmonkey"
    ],
    "config_flow": true,
    "iot_class": "cloud_polling",
    "version": "0.1.3",
    "issue_tracker": "https://github.com/vlebourl/vesync-bpo",
    "dhcp": [
      {
        "hostname": "levoit-*",
        "macaddress": "*"
      }
    ],
    "is_built_in": false
  },
  "data": {
    "fans": [
      {
        "device": {
          "module": "VeSyncAirBypass",
          "models": [
            "Core200S",
            "LAP-C201S-AUSR",
            "LAP-C202S-WUSR"
          ],
          "modes": [
            "sleep",
            "off"
          ],
          "features": [],
          "levels": [
            1,
            2,
            3
          ]
        },
        "config": {
          "display": false,
          "display_forever": false
        },
        "details": {
          "filter_life": 99,
          "mode": "manual",
          "level": 0,
          "display": false,
          "child_lock": false,
          "night_light": "off",
          "display_forever": false
        }
      }
    ],
    "outlets": [],
    "switches": [],
    "bulbs": []
  }
}

@kasper79
Copy link

Confirmed it does have the presets (auto, sleep)

Newest push worked for the Core 600s, it now show sup as an entity

image

@adityapavan18
Copy link

ok for Core 400S - LAP-C401S-WUSR. I added the device in const.py in my HA instance and also updated the fan.py

PRESET_MODES = {
"Core200S": [FAN_MODE_SLEEP],
"Core300S": [FAN_MODE_AUTO, FAN_MODE_SLEEP],
"Core400S": [FAN_MODE_AUTO, FAN_MODE_SLEEP],
"LV-PUR131S": [FAN_MODE_AUTO, FAN_MODE_SLEEP],
"LAP-C401S-WUSR": [FAN_MODE_AUTO, FAN_MODE_SLEEP],
}

the device now shows up in my HA - but the air quality information is wrong. Also Core 400S has a 4 levels of fan speed. But I am only able to go up till 3.

@vlebourl
Copy link
Owner Author

ok for Core 400S - LAP-C401S-WUSR. I added the device in const.py in my HA instance and also updated the fan.py

Thanks for this, could you add your diagnostics so I can see how to get the proper fan speed range from device info?
Cheers.

Repository owner deleted a comment from sourcery-ai bot Apr 27, 2022
@vlebourl
Copy link
Owner Author

I added some improvement to mode and fan speed discovery. Could you guys try it out?

@kasper79
Copy link

kasper79 commented Apr 27, 2022

Newest pull breaks all the air purifiers for me, the humidifier's still show up correctly:

Logger: homeassistant.components.fan
Source: custom_components/vesync/fan.py:70
Integration: Fan (documentation, issues)
First occurred: 7:18:49 AM (1 occurrences)
Last logged: 7:18:49 AM

Error while setting up vesync platform for fan
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 249, in _async_setup_platform
    await asyncio.shield(task)
  File "/config/custom_components/vesync/fan.py", line 41, in async_setup_entry
    _setup_entities(
  File "/config/custom_components/vesync/fan.py", line 53, in _setup_entities
    entities.append(VeSyncFanHA(dev))
  File "/config/custom_components/vesync/fan.py", line 70, in __init__
    self._speed_range = (1, max(self.device.levels))
AttributeError: 'VeSyncAirBypass' object has no attribute 'levels'

I have:
Core300s
Core400s
Core600s
LV-Pur131S

Attched diagnostics.

{
  "home_assistant": {
    "installation_type": "Home Assistant OS",
    "version": "2022.4.7",
    "dev": false,
    "hassio": true,
    "virtualenv": false,
    "python_version": "3.9.9",
    "docker": true,
    "arch": "x86_64",
    "timezone": "America/Chicago",
    "os_name": "Linux",
    "os_version": "5.10.108",
    "supervisor": "2022.04.0",
    "host_os": "Home Assistant OS 7.6",
    "docker_version": "20.10.9",
    "chassis": "embedded",
    "run_as_root": true
  },
  "custom_components": {
    "minecraft_server": {
      "version": "1.0.0",
      "requirements": [
        "aiodns==2.0.0",
        "getmac==0.8.2",
        "mcstatus==5.1.1"
      ]
    },
    "poolmath": {
      "version": "0.1.4",
      "requirements": [
        "beautifulsoup4>=4.9.0",
        "jsonpath>=0.82",
        "xmltodict>=0.12.0",
        "httpx>=0.16.1"
      ]
    },
    "apple_tv": {
      "version": "3.0.1",
      "requirements": [
        "pyatv==0.10.0"
      ]
    },
    "ha_hatch": {
      "version": "1.2.0",
      "requirements": [
        "hatch-rest-api==1.10.0"
      ]
    },
    "flair": {
      "version": "0.0.5.5",
      "requirements": [
        "hass-flair-helper==0.1.2"
      ]
    },
    "ecowitt": {
      "version": "0.1.0",
      "requirements": [
        "pyecowitt==0.12"
      ]
    },
    "midea_dehumidifier_lan": {
      "version": "0.8.1",
      "requirements": [
        "midea-beautiful-air==0.9.8"
      ]
    },
    "icloud3": {
      "version": "2.4.6",
      "requirements": []
    },
    "whistle": {
      "version": "0.0.3.4",
      "requirements": [
        "git+https://github.com/RobertD502/pywhistle@master#pywhistle==0.0.4.1"
      ]
    },
    "midea_ac": {
      "version": "0.2.3",
      "requirements": [
        "msmart==0.2.3",
        "pycryptodome",
        "pycryptodomex",
        "click"
      ]
    },
    "alexa_media": {
      "version": "3.11.2",
      "requirements": [
        "alexapy==1.25.3",
        "packaging>=20.3",
        "wrapt>=1.12.1"
      ]
    },
    "alarmo": {
      "version": "v1.8.7",
      "requirements": []
    },
    "hacs": {
      "version": "1.24.5",
      "requirements": [
        "aiogithubapi>=21.11.0"
      ]
    },
    "traeger": {
      "version": "2021.09.20",
      "requirements": []
    },
    "mail_and_packages": {
      "version": "0.3.4-b23",
      "requirements": [
        "imageio>=2.9.0",
        "python-resize-image>=1.1.19"
      ]
    },
    "vesync": {
      "version": "0.1.3",
      "requirements": []
    }
  },
  "integration_manifest": {
    "domain": "vesync",
    "name": "VeSync",
    "documentation": "https://www.home-assistant.io/integrations/vesync",
    "codeowners": [
      "@markperdue",
      "@webdjoe",
      "@thegardenmonkey",
      "@vlebourl"
    ],
    "config_flow": true,
    "iot_class": "cloud_polling",
    "version": "0.1.3",
    "issue_tracker": "https://github.com/vlebourl/custom_vesync",
    "dhcp": [
      {
        "hostname": "levoit-*",
        "macaddress": "*"
      }
    ],
    "is_built_in": false
  },
  "data": {
    "fans": [
      {
        "device": {
          "module": "VeSyncAirBypass",
          "models": [
            "Core400S",
            "LAP-C401S-WJP",
            "LAP-C401S-WUSR",
            "LAP-C401S-WAAA"
          ],
          "modes": [
            "sleep",
            "off",
            "auto"
          ],
          "features": [
            "air_quality"
          ],
          "levels": [
            1,
            2,
            3,
            4
          ]
        },
        "config": {
          "display": true,
          "display_forever": true
        },
        "details": {
          "filter_life": 99,
          "mode": "manual",
          "level": 0,
          "display": true,
          "child_lock": true,
          "night_light": "off",
          "ait_quality": 0,
          "display_forever": false,
          "air_quality": 1
        }
      },
      {
        "device": {
          "module": "VeSyncAirBypass",
          "models": [
            "Core400S",
            "LAP-C401S-WJP",
            "LAP-C401S-WUSR",
            "LAP-C401S-WAAA"
          ],
          "modes": [
            "sleep",
            "off",
            "auto"
          ],
          "features": [
            "air_quality"
          ],
          "levels": [
            1,
            2,
            3,
            4
          ]
        },
        "config": {
          "display": false,
          "display_forever": true
        },
        "details": {
          "filter_life": 83,
          "mode": "manual",
          "level": 0,
          "display": false,
          "child_lock": false,
          "night_light": "off",
          "ait_quality": 0,
          "display_forever": false,
          "air_quality": 1
        }
      },
      {
        "device": {
          "module": "VeSyncAirBypass",
          "models": [
            "Core400S",
            "LAP-C401S-WJP",
            "LAP-C401S-WUSR",
            "LAP-C401S-WAAA"
          ],
          "modes": [
            "sleep",
            "off",
            "auto"
          ],
          "features": [
            "air_quality"
          ],
          "levels": [
            1,
            2,
            3,
            4
          ]
        },
        "config": {
          "display": true,
          "display_forever": true
        },
        "details": {
          "filter_life": 83,
          "mode": "manual",
          "level": 0,
          "display": true,
          "child_lock": false,
          "night_light": "off",
          "ait_quality": 0,
          "display_forever": false,
          "air_quality": 1
        }
      },
      {
        "device": {
          "module": "VeSyncAirBypass",
          "models": [
            "Core300S",
            "LAP-C301S-WJP"
          ],
          "modes": [
            "sleep",
            "off",
            "auto"
          ],
          "features": [
            "air_quality"
          ],
          "levels": [
            1,
            2,
            3,
            4
          ]
        },
        "config": {
          "display": true,
          "display_forever": true
        },
        "details": {
          "filter_life": 100,
          "mode": "manual",
          "level": 0,
          "display": true,
          "child_lock": false,
          "night_light": "off",
          "ait_quality": 0,
          "display_forever": false,
          "air_quality": 1
        }
      },
      {
        "device": {
          "module": "VeSyncAirBypass",
          "models": [
            "Core600S",
            "LAP-C601S-WUS",
            "LAP-C601S-WUSR",
            "LAP-C601S-WEU"
          ],
          "modes": [
            "sleep",
            "off",
            "auto"
          ],
          "features": [
            "air_quality"
          ],
          "levels": [
            1,
            2,
            3,
            4
          ]
        },
        "config": {
          "display": true,
          "display_forever": true
        },
        "details": {
          "filter_life": 100,
          "mode": "manual",
          "level": 0,
          "display": true,
          "child_lock": false,
          "night_light": "off",
          "ait_quality": 0,
          "display_forever": false,
          "air_quality": 1
        }
      },
      {
        "device": {
          "module": "VeSyncHumid200300S",
          "models": [
            "Classic300S",
            "LUH-A601S-WUSB"
          ],
          "features": [
            "nightlight"
          ],
          "mist_modes": [
            "auto",
            "sleep",
            "manual"
          ],
          "mist_levels": [
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9
          ]
        },
        "config": {
          "auto_target_humidity": 45,
          "display": false,
          "automatic_stop": true
        },
        "details": {
          "humidity": 58,
          "mist_virtual_level": 1,
          "mist_level": 1,
          "mode": "auto",
          "water_lacks": false,
          "humidity_high": false,
          "water_tank_lifted": false,
          "display": false,
          "automatic_stop_reach_target": true,
          "night_light_brightness": 0
        }
      },
      {
        "device": {
          "module": "VeSyncHumid200S",
          "models": [
            "Classic200S"
          ],
          "features": [],
          "mist_modes": [
            "auto",
            "manual"
          ],
          "mist_levels": [
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            8,
            9
          ]
        },
        "config": {
          "auto_target_humidity": 45,
          "display": false,
          "automatic_stop": false
        },
        "details": {
          "humidity": 67,
          "mist_virtual_level": 9,
          "mist_level": 3,
          "mode": "manual",
          "water_lacks": false,
          "humidity_high": false,
          "water_tank_lifted": false,
          "display": false,
          "automatic_stop_reach_target": false
        }
      },
      {
        "device": {},
        "config": {},
        "details": {
          "active_time": 113047,
          "filter_life": {
            "change": false,
            "useHour": 840,
            "percent": 79
          },
          "screen_status": "on",
          "level": null,
          "air_quality": "excellent"
        }
      }
    ],
    "outlets": [],
    "switches": [],
    "bulbs": []
  }
}

@vlebourl
Copy link
Owner Author

I messed up the levels detection. It's tough to get it right without access to the device...
Would you mind joining me on discord so I can be more reactive?
https://discord.gg/xNUd82Fr

Repository owner deleted a comment from sourcery-ai bot Apr 27, 2022
Repository owner deleted a comment from sourcery-ai bot Apr 27, 2022
@vlebourl vlebourl marked this pull request as ready for review April 27, 2022 13:59
@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Apr 27, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 0.12%.

Quality metrics Before After Change
Complexity 4.94 ⭐ 5.16 ⭐ 0.22 👎
Method Length 30.52 ⭐ 29.29 ⭐ -1.23 👍
Working memory 5.63 ⭐ 5.53 ⭐ -0.10 👍
Quality 79.37% 79.49% 0.12% 👍
Other metrics Before After Change
Lines 697 750 53
Changed files Quality Before Quality After Quality Change
custom_components/vesync/init.py 55.91% 🙂 56.94% 🙂 1.03% 👍
custom_components/vesync/binary_sensor.py 93.09% ⭐ 93.47% ⭐ 0.38% 👍
custom_components/vesync/common.py 69.82% 🙂 67.17% 🙂 -2.65% 👎
custom_components/vesync/const.py 89.38% ⭐ 88.20% ⭐ -1.18% 👎
custom_components/vesync/diagnostics.py 77.27% ⭐ 79.99% ⭐ 2.72% 👍
custom_components/vesync/fan.py 85.45% ⭐ 82.98% ⭐ -2.47% 👎
custom_components/vesync/number.py 95.02% ⭐ 95.42% ⭐ 0.40% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
custom_components/vesync/common.py async_process_devices 24 😞 207 ⛔ 8 🙂 41.60% 😞 Refactor to reduce nesting. Try splitting into smaller methods
custom_components/vesync/init.py async_setup_entry 14 🙂 228 ⛔ 10 😞 43.27% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

@vlebourl vlebourl merged commit 0afbef7 into main Apr 27, 2022
@vlebourl vlebourl deleted the fix/fix-fan-discovery branch April 27, 2022 19:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support fans
4 participants