hass-core/homeassistant/components/lock/isy994.py
Otto Winter 678f284015 Upgrade pylint to 1.8.2 (#12274)
* 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
2018-02-11 09:20:28 -08:00

110 lines
3.4 KiB
Python

"""
Support for ISY994 locks.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/lock.isy994/
"""
import logging
from typing import Callable # noqa
from homeassistant.components.lock import LockDevice, DOMAIN
from homeassistant.components.isy994 import (ISY994_NODES, ISY994_PROGRAMS,
ISYDevice)
from homeassistant.const import STATE_LOCKED, STATE_UNLOCKED, STATE_UNKNOWN
from homeassistant.helpers.typing import ConfigType
_LOGGER = logging.getLogger(__name__)
VALUE_TO_STATE = {
0: STATE_UNLOCKED,
100: STATE_LOCKED
}
# pylint: disable=unused-argument
def setup_platform(hass, config: ConfigType,
add_devices: Callable[[list], None], discovery_info=None):
"""Set up the ISY994 lock platform."""
devices = []
for node in hass.data[ISY994_NODES][DOMAIN]:
devices.append(ISYLockDevice(node))
for name, status, actions in hass.data[ISY994_PROGRAMS][DOMAIN]:
devices.append(ISYLockProgram(name, status, actions))
add_devices(devices)
class ISYLockDevice(ISYDevice, LockDevice):
"""Representation of an ISY994 lock device."""
def __init__(self, node) -> None:
"""Initialize the ISY994 lock device."""
super().__init__(node)
self._conn = node.parent.parent.conn
@property
def is_locked(self) -> bool:
"""Get whether the lock is in locked state."""
return self.state == STATE_LOCKED
@property
def state(self) -> str:
"""Get the state of the lock."""
if self.is_unknown():
return None
return VALUE_TO_STATE.get(self.value, STATE_UNKNOWN)
def lock(self, **kwargs) -> None:
"""Send the lock command to the ISY994 device."""
# Hack until PyISY is updated
req_url = self._conn.compileURL(['nodes', self.unique_id, 'cmd',
'SECMD', '1'])
response = self._conn.request(req_url)
if response is None:
_LOGGER.error('Unable to lock device')
self._node.update(0.5)
def unlock(self, **kwargs) -> None:
"""Send the unlock command to the ISY994 device."""
# Hack until PyISY is updated
req_url = self._conn.compileURL(['nodes', self.unique_id, 'cmd',
'SECMD', '0'])
response = self._conn.request(req_url)
if response is None:
_LOGGER.error('Unable to lock device')
self._node.update(0.5)
class ISYLockProgram(ISYLockDevice):
"""Representation of a ISY lock program."""
def __init__(self, name: str, node, actions) -> None:
"""Initialize the lock."""
super().__init__(node)
self._name = name
self._actions = actions
@property
def is_locked(self) -> bool:
"""Return true if the device is locked."""
return bool(self.value)
@property
def state(self) -> str:
"""Return the state of the lock."""
return STATE_LOCKED if self.is_locked else STATE_UNLOCKED
def lock(self, **kwargs) -> None:
"""Lock the device."""
if not self._actions.runThen():
_LOGGER.error("Unable to lock device")
def unlock(self, **kwargs) -> None:
"""Unlock the device."""
if not self._actions.runElse():
_LOGGER.error("Unable to unlock device")