Updated pyqwikswitch & QS<->HA UI behaviour (#2123)
* Updated pyqwikswitch & constants * Disable too-many-locals
This commit is contained in:
parent
dee6355cc5
commit
31c2d45a7a
2 changed files with 26 additions and 24 deletions
|
@ -9,8 +9,8 @@ from homeassistant.const import EVENT_HOMEASSISTANT_STOP
|
|||
from homeassistant.components.light import ATTR_BRIGHTNESS
|
||||
from homeassistant.components.discovery import load_platform
|
||||
|
||||
REQUIREMENTS = ['https://github.com/kellerza/pyqwikswitch/archive/v0.1.zip'
|
||||
'#pyqwikswitch==0.1']
|
||||
REQUIREMENTS = ['https://github.com/kellerza/pyqwikswitch/archive/v0.3.zip'
|
||||
'#pyqwikswitch==0.3']
|
||||
DEPENDENCIES = []
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
@ -36,11 +36,12 @@ class QSToggleEntity(object):
|
|||
|
||||
def __init__(self, qsitem, qsusb):
|
||||
"""Initialize the ToggleEntity."""
|
||||
self._id = qsitem['id']
|
||||
self._name = qsitem['name']
|
||||
from pyqwikswitch import (QS_ID, QS_NAME, QSType, PQS_VALUE, PQS_TYPE)
|
||||
self._id = qsitem[QS_ID]
|
||||
self._name = qsitem[QS_NAME]
|
||||
self._value = qsitem[PQS_VALUE]
|
||||
self._qsusb = qsusb
|
||||
self._value = qsitem.get('value', 0)
|
||||
self._dim = qsitem['type'] == 'dim'
|
||||
self._dim = qsitem[PQS_TYPE] == QSType.dimmer
|
||||
|
||||
@property
|
||||
def brightness(self):
|
||||
|
@ -73,23 +74,24 @@ class QSToggleEntity(object):
|
|||
|
||||
def turn_on(self, **kwargs):
|
||||
"""Turn the device on."""
|
||||
newvalue = 255
|
||||
if ATTR_BRIGHTNESS in kwargs:
|
||||
self.update_value(kwargs[ATTR_BRIGHTNESS])
|
||||
else:
|
||||
self.update_value(255)
|
||||
|
||||
return self._qsusb.set(self._id, round(min(self._value, 255)/2.55))
|
||||
newvalue = kwargs[ATTR_BRIGHTNESS]
|
||||
if self._qsusb.set(self._id, round(min(newvalue, 255)/2.55)) >= 0:
|
||||
self.update_value(newvalue)
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def turn_off(self, **kwargs):
|
||||
"""Turn the device off."""
|
||||
self.update_value(0)
|
||||
return self._qsusb.set(self._id, 0)
|
||||
if self._qsusb.set(self._id, 0) >= 0:
|
||||
self.update_value(0)
|
||||
|
||||
|
||||
# pylint: disable=too-many-locals
|
||||
def setup(hass, config):
|
||||
"""Setup the QSUSB component."""
|
||||
from pyqwikswitch import QSUsb, CMD_BUTTONS
|
||||
from pyqwikswitch import (QSUsb, CMD_BUTTONS, QS_NAME, QS_ID, QS_CMD,
|
||||
QS_TYPE, PQS_VALUE, PQS_TYPE, QSType)
|
||||
|
||||
# Override which cmd's in /&listen packets will fire events
|
||||
# By default only buttons of type [TOGGLE,SCENE EXE,LEVEL]
|
||||
|
@ -113,9 +115,10 @@ def setup(hass, config):
|
|||
|
||||
# Identify switches & remove ' Switch' postfix in name
|
||||
for item in qsusb.ha_devices:
|
||||
if item['type'] == 'rel' and item['name'].lower().endswith(' switch'):
|
||||
item['type'] = 'switch'
|
||||
item['name'] = item['name'][:-7]
|
||||
if item[PQS_TYPE] == QSType.relay and \
|
||||
item[QS_NAME].lower().endswith(' switch'):
|
||||
item[QS_TYPE] = 'switch'
|
||||
item[QS_NAME] = item[QS_NAME][:-7]
|
||||
|
||||
global QSUSB
|
||||
if QSUSB is None:
|
||||
|
@ -130,8 +133,8 @@ def setup(hass, config):
|
|||
def qs_callback(item):
|
||||
"""Typically a button press or update signal."""
|
||||
# If button pressed, fire a hass event
|
||||
if item.get('cmd', '') in cmd_buttons:
|
||||
hass.bus.fire('qwikswitch.button.' + item.get('id', '@no_id'))
|
||||
if item.get(QS_CMD, '') in cmd_buttons:
|
||||
hass.bus.fire('qwikswitch.button.' + item.get(QS_ID, '@no_id'))
|
||||
return
|
||||
|
||||
# Update all ha_objects
|
||||
|
@ -139,10 +142,9 @@ def setup(hass, config):
|
|||
if qsreply is False:
|
||||
return
|
||||
for item in qsreply:
|
||||
item_id = item.get('id', '')
|
||||
if item_id in qsusb.ha_objects:
|
||||
qsusb.ha_objects[item_id].update_value(
|
||||
round(min(item['value'], 100) * 2.55))
|
||||
if item[QS_ID] in qsusb.ha_objects:
|
||||
qsusb.ha_objects[item[QS_ID]].update_value(
|
||||
round(min(item[PQS_VALUE], 100) * 2.55))
|
||||
|
||||
qsusb.listen(callback=qs_callback, timeout=30)
|
||||
return True
|
||||
|
|
|
@ -119,7 +119,7 @@ https://github.com/danieljkemp/onkyo-eiscp/archive/python3.zip#onkyo-eiscp==0.9.
|
|||
https://github.com/jamespcole/home-assistant-nzb-clients/archive/616cad59154092599278661af17e2a9f2cf5e2a9.zip#python-sabnzbd==0.1
|
||||
|
||||
# homeassistant.components.qwikswitch
|
||||
https://github.com/kellerza/pyqwikswitch/archive/v0.1.zip#pyqwikswitch==0.1
|
||||
https://github.com/kellerza/pyqwikswitch/archive/v0.3.zip#pyqwikswitch==0.3
|
||||
|
||||
# homeassistant.components.ecobee
|
||||
https://github.com/nkgilley/python-ecobee-api/archive/4a884bc146a93991b4210f868f3d6aecf0a181e6.zip#python-ecobee==0.0.5
|
||||
|
|
Loading…
Add table
Reference in a new issue