core/homeassistant/components/schluter/__init__.py

74 lines
2.1 KiB
Python
Raw Normal View History

Add integration for Schluter (#31088) * Add integration for Schluter New integration for Schluter DITRA-HEAT thermostats. Interacts with Schluter API via py-schluter to implement climate platform. * Fix for manifest issue on build Removed unnecessary configurator logic * Flake8 & ISort issues fixed * Code review modifications for Schluter integration - Removed unnecessary strings.json file - Removed unnecessary DEFAULT_SCAN_INTERVAL from __init__.py - Removed persistent notification for authentication error in __init__.py - Removed string casts from log statements in __init__.py - Removed unnecessary logging of entity creations in climate.py - Removed unnecessary lookup for hvac_mode in climate.py * Work started on Update Coordinator * Further Coordinator work * Update to DataUpdateCoordinator complete * Flake8 fix * Removal of unnecessary SchluterPlatformData Coordinator also now using SCAN_INTERVAL * Disable polling, use coordinator listeners * Isort on climate.py * Code review modifications - Hass data stored under domain - Since platform only likely to be climate, removed array, load explicitly - Remove unnecessary fan mode implementation * Switch to HVAC action for showing current heating status * Isort fix * HVAC Mode return list, set_hvac_mode function added * __init__.py modifications from code review * Climate.py code review modifications - Device info property removed - Write state function on set temp failure - Add "available" property - Delegate sync function in coordinator update to the executor * Serial number as unique identifier - Now using serial number & thermostat dictionary to protect against scenarios where a device is removed and enumerable index is no longer accurate - Removed async_write_ha_state() from set temp exception, not needed - Removed unnecessary SCAN_INTERVAL definition * Linting * Update homeassistant/components/schluter/climate.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * Update homeassistant/components/schluter/climate.py Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io> * Changed timeout from config, load platform discover to None * Proposed change for discover info issue Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-03-27 17:53:36 +00:00
"""The Schluter DITRA-HEAT integration."""
import logging
from requests import RequestException, Session
from schluter.api import Api
from schluter.authenticator import AuthenticationState, Authenticator
import voluptuous as vol
from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
from homeassistant.helpers import discovery
import homeassistant.helpers.config_validation as cv
from .const import DOMAIN
_LOGGER = logging.getLogger(__name__)
DATA_SCHLUTER_SESSION = "schluter_session"
DATA_SCHLUTER_API = "schluter_api"
SCHLUTER_CONFIG_FILE = ".schluter.conf"
API_TIMEOUT = 10
CONFIG_SCHEMA = vol.Schema(
{
vol.Required(DOMAIN): vol.Schema(
{
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
}
)
},
extra=vol.ALLOW_EXTRA,
)
def setup(hass, config):
"""Set up the Schluter component."""
_LOGGER.debug("Starting setup of schluter")
conf = config[DOMAIN]
api_http_session = Session()
api = Api(timeout=API_TIMEOUT, http_session=api_http_session)
authenticator = Authenticator(
api,
conf.get(CONF_USERNAME),
conf.get(CONF_PASSWORD),
session_id_cache_file=hass.config.path(SCHLUTER_CONFIG_FILE),
)
authentication = None
try:
authentication = authenticator.authenticate()
except RequestException as ex:
_LOGGER.error("Unable to connect to Schluter service: %s", ex)
return
state = authentication.state
if state == AuthenticationState.AUTHENTICATED:
hass.data[DOMAIN] = {
DATA_SCHLUTER_API: api,
DATA_SCHLUTER_SESSION: authentication.session_id,
}
discovery.load_platform(hass, "climate", DOMAIN, {}, config)
return True
if state == AuthenticationState.BAD_PASSWORD:
_LOGGER.error("Invalid password provided")
return False
if state == AuthenticationState.BAD_EMAIL:
_LOGGER.error("Invalid email provided")
return False
_LOGGER.error("Unknown set up error: %s", state)
return False