Make CoolMasterNet integration async (#38643)

* make CoolMasteNet integration async

* Apply suggestions from code review

Co-authored-by: Chris Talkington <chris@talkingtontech.com>

* Minor post-review tweaks

* Apply suggestions from code review

* Update homeassistant/components/coolmaster/__init__.py

Co-authored-by: Chris Talkington <chris@talkingtontech.com>
This commit is contained in:
On FreundandChris Talkington authored and GitHub committed 2020-08-09 13:08:07 -05:00
1 parent 597d1e2799
commit 96d48c309f
8 files changed
+144 -80

No files matched your search

@@ -1,6 +1,6 @@
"""Config flow to configure Coolmaster."""
from pycoolmasternet import CoolMasterNet
from pycoolmasternet_async import CoolMasterNet
import voluptuous as vol
from homeassistant import config_entries, core
@@ -15,9 +15,9 @@ DATA_SCHEMA = vol.Schema({vol.Required(CONF_HOST): str, **MODES_SCHEMA})
async def _validate_connection(hass: core.HomeAssistant, host):
cool = CoolMasterNet(host, port=DEFAULT_PORT)
devices = await hass.async_add_executor_job(cool.devices)
return bool(devices)
cool = CoolMasterNet(host, DEFAULT_PORT)
units = await cool.status()
return bool(units)
class CoolmasterConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
@@ -53,7 +53,7 @@ class CoolmasterConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
result = await _validate_connection(self.hass, host)
if not result:
errors["base"] = "no_units"
except (ConnectionRefusedError, TimeoutError):
except (OSError, ConnectionRefusedError, TimeoutError):
errors["base"] = "connection_error"
if errors: