megakid / ha_octopus_intelligent

Apache License 2.0
86 stars 10 forks source link

Replace async_timeout library and simplify platform setup loop #42

Closed pdcastro closed 4 months ago

pdcastro commented 4 months ago

async_timeout is a third-party library installed through PyPI / pip install. It was written in 2016, around the time when Python 3.6 was released. At that time, Python’s asyncio built-in module had a wait_for() function but not a timeout() function. In 2022, Python 3.11 was released including a drop-in replacement for the async_timeout library through the built-in asyncio.timeout() function. Other things equal, a built-in function is preferable to a third-party PyPI library.

Meanwhile, Home Assistant dropped support for Python versions 3.10 and older in HASS version 2023.8.0 (Aug 2023). It now requires Python versions 3.11 or 3.12.

Also, the async_timeout library is not being declared as a dependency in this integration’s manifest.json file, so Home Assistant is not making sure that async_timeout is installed alongside this integration. It has been working so far because other common Home Assistant integrations still declare async_timeout as a dependency.

This PR also proposes a simplification to the platform setup loop using the async_forward_entry_setups() function added to Home Assistant 2022.8.0 (Aug 2022), and a couple of log message amendments.