mirror of
https://github.com/home-assistant/core.git
synced 2025-08-04 13:15:18 +02:00
Move imports in waterfurnace component (#27449)
This commit is contained in:
committed by
Fabian Affolter
parent
cb30065a40
commit
8bd847ed39
@@ -5,6 +5,7 @@ import time
|
|||||||
import threading
|
import threading
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
from waterfurnace.waterfurnace import WaterFurnace, WFCredentialError, WFException
|
||||||
|
|
||||||
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP
|
from homeassistant.const import CONF_USERNAME, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
@@ -37,19 +38,18 @@ CONFIG_SCHEMA = vol.Schema(
|
|||||||
|
|
||||||
def setup(hass, base_config):
|
def setup(hass, base_config):
|
||||||
"""Set up waterfurnace platform."""
|
"""Set up waterfurnace platform."""
|
||||||
import waterfurnace.waterfurnace as wf
|
|
||||||
|
|
||||||
config = base_config.get(DOMAIN)
|
config = base_config.get(DOMAIN)
|
||||||
|
|
||||||
username = config.get(CONF_USERNAME)
|
username = config.get(CONF_USERNAME)
|
||||||
password = config.get(CONF_PASSWORD)
|
password = config.get(CONF_PASSWORD)
|
||||||
|
|
||||||
wfconn = wf.WaterFurnace(username, password)
|
wfconn = WaterFurnace(username, password)
|
||||||
# NOTE(sdague): login will throw an exception if this doesn't
|
# NOTE(sdague): login will throw an exception if this doesn't
|
||||||
# work, which will abort the setup.
|
# work, which will abort the setup.
|
||||||
try:
|
try:
|
||||||
wfconn.login()
|
wfconn.login()
|
||||||
except wf.WFCredentialError:
|
except WFCredentialError:
|
||||||
_LOGGER.error("Invalid credentials for waterfurnace login.")
|
_LOGGER.error("Invalid credentials for waterfurnace login.")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -83,7 +83,6 @@ class WaterFurnaceData(threading.Thread):
|
|||||||
|
|
||||||
def _reconnect(self):
|
def _reconnect(self):
|
||||||
"""Reconnect on a failure."""
|
"""Reconnect on a failure."""
|
||||||
import waterfurnace.waterfurnace as wf
|
|
||||||
|
|
||||||
self._fails += 1
|
self._fails += 1
|
||||||
if self._fails > MAX_FAILS:
|
if self._fails > MAX_FAILS:
|
||||||
@@ -105,7 +104,7 @@ class WaterFurnaceData(threading.Thread):
|
|||||||
try:
|
try:
|
||||||
self.client.login()
|
self.client.login()
|
||||||
self.data = self.client.read()
|
self.data = self.client.read()
|
||||||
except wf.WFException:
|
except WFException:
|
||||||
_LOGGER.exception("Failed to reconnect attempt %s", self._fails)
|
_LOGGER.exception("Failed to reconnect attempt %s", self._fails)
|
||||||
else:
|
else:
|
||||||
_LOGGER.debug("Reconnected to furnace")
|
_LOGGER.debug("Reconnected to furnace")
|
||||||
@@ -113,7 +112,6 @@ class WaterFurnaceData(threading.Thread):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Thread run loop."""
|
"""Thread run loop."""
|
||||||
import waterfurnace.waterfurnace as wf
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def register():
|
def register():
|
||||||
@@ -143,7 +141,7 @@ class WaterFurnaceData(threading.Thread):
|
|||||||
try:
|
try:
|
||||||
self.data = self.client.read()
|
self.data = self.client.read()
|
||||||
|
|
||||||
except wf.WFException:
|
except WFException:
|
||||||
# WFExceptions are things the WF library understands
|
# WFExceptions are things the WF library understands
|
||||||
# that pretty much can all be solved by logging in and
|
# that pretty much can all be solved by logging in and
|
||||||
# back out again.
|
# back out again.
|
||||||
|
Reference in New Issue
Block a user