Added persistent error message if cover.myq fails to load (#7700)
* Show persistent error if cover.myq fails * Fixed typo on getLogger() * Added ValueError on except condition * Make pylint happy * Removed DEFAULT_ENTITY_NAMESPACE since it is not being usedpull/7843/head
parent
052cd3fc53
commit
8ee32a8fbd
|
@ -12,19 +12,25 @@ from homeassistant.components.cover import CoverDevice
|
|||
from homeassistant.const import (
|
||||
CONF_USERNAME, CONF_PASSWORD, CONF_TYPE, STATE_CLOSED)
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
import homeassistant.loader as loader
|
||||
|
||||
REQUIREMENTS = [
|
||||
'https://github.com/arraylabs/pymyq/archive/v0.0.8.zip'
|
||||
'#pymyq==0.0.8']
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEFAULT_NAME = 'myq'
|
||||
|
||||
NOTIFICATION_ID = 'myq_notification'
|
||||
NOTIFICATION_TITLE = 'MyQ Cover Setup'
|
||||
|
||||
COVER_SCHEMA = vol.Schema({
|
||||
vol.Required(CONF_TYPE): cv.string,
|
||||
vol.Required(CONF_USERNAME): cv.string,
|
||||
vol.Required(CONF_PASSWORD): cv.string
|
||||
})
|
||||
|
||||
DEFAULT_NAME = 'myq'
|
||||
|
||||
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Set up the MyQ component."""
|
||||
|
@ -33,23 +39,28 @@ def setup_platform(hass, config, add_devices, discovery_info=None):
|
|||
username = config.get(CONF_USERNAME)
|
||||
password = config.get(CONF_PASSWORD)
|
||||
brand = config.get(CONF_TYPE)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
persistent_notification = loader.get_component('persistent_notification')
|
||||
myq = pymyq(username, password, brand)
|
||||
|
||||
if not myq.is_supported_brand():
|
||||
logger.error("Unsupported type. See documentation")
|
||||
return
|
||||
|
||||
if not myq.is_login_valid():
|
||||
logger.error("Username or Password is incorrect")
|
||||
return
|
||||
|
||||
try:
|
||||
if not myq.is_supported_brand():
|
||||
raise ValueError("Unsupported type. See documentation")
|
||||
|
||||
if not myq.is_login_valid():
|
||||
raise ValueError("Username or Password is incorrect")
|
||||
|
||||
add_devices(MyQDevice(myq, door) for door in myq.get_garage_doors())
|
||||
except (TypeError, KeyError, NameError) as ex:
|
||||
logger.error("%s", ex)
|
||||
return True
|
||||
|
||||
except (TypeError, KeyError, NameError, ValueError) as ex:
|
||||
_LOGGER.error("%s", ex)
|
||||
persistent_notification.create(
|
||||
hass, 'Error: {}<br />'
|
||||
'You will need to restart hass after fixing.'
|
||||
''.format(ex),
|
||||
title=NOTIFICATION_TITLE,
|
||||
notification_id=NOTIFICATION_ID)
|
||||
return False
|
||||
|
||||
|
||||
class MyQDevice(CoverDevice):
|
||||
|
|
Loading…
Reference in New Issue