1 """Support for NuHeat thermostats."""
3 from datetime
import timedelta
4 from http
import HTTPStatus
16 from .const
import CONF_SERIAL_NUMBER, DOMAIN, PLATFORMS
18 _LOGGER = logging.getLogger(__name__)
22 """Authenticate and create the thermostat object."""
24 return api.get_thermostat(serial_number)
28 """Set up NuHeat from a config entry."""
32 username = conf[CONF_USERNAME]
33 password = conf[CONF_PASSWORD]
34 serial_number = conf[CONF_SERIAL_NUMBER]
36 api = nuheat.NuHeat(username, password)
39 thermostat = await hass.async_add_executor_job(
40 _get_thermostat, api, serial_number
42 except requests.exceptions.Timeout
as ex:
43 raise ConfigEntryNotReady
from ex
44 except requests.exceptions.HTTPError
as ex:
46 ex.response.status_code > HTTPStatus.BAD_REQUEST
47 and ex.response.status_code < HTTPStatus.INTERNAL_SERVER_ERROR
49 _LOGGER.error(
"Failed to login to nuheat: %s", ex)
51 raise ConfigEntryNotReady
from ex
52 except Exception
as ex:
53 _LOGGER.error(
"Failed to login to nuheat: %s", ex)
56 async
def _async_update_data():
57 """Fetch data from API endpoint."""
58 await hass.async_add_executor_job(thermostat.get_data)
64 name=f
"nuheat {serial_number}",
65 update_method=_async_update_data,
69 hass.data.setdefault(DOMAIN, {})
70 hass.data[DOMAIN][entry.entry_id] = (thermostat, coordinator)
72 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
78 """Unload a config entry."""
79 unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
81 hass.data[DOMAIN].pop(entry.entry_id)
def _get_thermostat(api, serial_number)
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)