* Upgrade pylint to 1.8.1 * Fix no-else-return * Fix bad-whitespace * Fix too-many-nested-blocks * Fix raising-format-tuple See https://github.com/PyCQA/pylint/blob/master/doc/whatsnew/1.8.rst * Fix len-as-condition * Fix logging-not-lazy Not sure about that TEMP_CELSIUS though, but internally it's probably just like if you concatenated any other (variable) string * Fix stop-iteration-return * Fix useless-super-delegation * Fix trailing-comma-tuple Both of these seem to simply be bugs: * Nest: The value of self._humidity never seems to be used anywhere * Dovado: The called API method seems to expect a "normal" number * Fix redefined-argument-from-local * Fix consider-using-enumerate * Fix wrong-import-order * Fix arguments-differ * Fix missed no-else-return * Fix no-member and related * Fix signatures-differ * Revert "Upgrade pylint to 1.8.1" This reverts commit af78aa00f125a7d34add97b9d50c14db48412211. * Fix arguments-differ * except for device_tracker * Cleanup * Fix test using positional argument * Fix line too long I forgot to run flake8 - shame on me... 🙃 * Fix bad-option-value for 1.6.5 * Fix arguments-differ for device_tracker * Upgrade pylint to 1.8.2 * 👕 Fix missed no-member
97 lines
2.7 KiB
Python
97 lines
2.7 KiB
Python
"""
|
|
Support for MyQ-Enabled Garage Doors.
|
|
|
|
For more details about this platform, please refer to the documentation
|
|
https://home-assistant.io/components/cover.myq/
|
|
"""
|
|
import logging
|
|
|
|
import voluptuous as vol
|
|
|
|
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
|
|
|
|
REQUIREMENTS = ['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
|
|
})
|
|
|
|
|
|
def setup_platform(hass, config, add_devices, discovery_info=None):
|
|
"""Set up the MyQ component."""
|
|
from pymyq import MyQAPI as pymyq
|
|
|
|
username = config.get(CONF_USERNAME)
|
|
password = config.get(CONF_PASSWORD)
|
|
brand = config.get(CONF_TYPE)
|
|
myq = pymyq(username, password, brand)
|
|
|
|
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())
|
|
return True
|
|
|
|
except (TypeError, KeyError, NameError, ValueError) as ex:
|
|
_LOGGER.error("%s", ex)
|
|
hass.components.persistent_notification.create(
|
|
'Error: {}<br />'
|
|
'You will need to restart hass after fixing.'
|
|
''.format(ex),
|
|
title=NOTIFICATION_TITLE,
|
|
notification_id=NOTIFICATION_ID)
|
|
return False
|
|
|
|
|
|
class MyQDevice(CoverDevice):
|
|
"""Representation of a MyQ cover."""
|
|
|
|
def __init__(self, myq, device):
|
|
"""Initialize with API object, device id."""
|
|
self.myq = myq
|
|
self.device_id = device['deviceid']
|
|
self._name = device['name']
|
|
self._status = STATE_CLOSED
|
|
|
|
@property
|
|
def should_poll(self):
|
|
"""Poll for state."""
|
|
return True
|
|
|
|
@property
|
|
def name(self):
|
|
"""Return the name of the garage door if any."""
|
|
return self._name if self._name else DEFAULT_NAME
|
|
|
|
@property
|
|
def is_closed(self):
|
|
"""Return true if cover is closed, else False."""
|
|
return self._status == STATE_CLOSED
|
|
|
|
def close_cover(self, **kwargs):
|
|
"""Issue close command to cover."""
|
|
self.myq.close_device(self.device_id)
|
|
|
|
def open_cover(self, **kwargs):
|
|
"""Issue open command to cover."""
|
|
self.myq.open_device(self.device_id)
|
|
|
|
def update(self):
|
|
"""Update status of cover."""
|
|
self._status = self.myq.get_status(self.device_id)
|