Added QwikSwitch component & platforms (#1970)
* Added QwikSwitch platform farcy - worst than my english teacher * Clean up comments * Import only inside functions * Moved imports, no global var, load_platform * add_device reworked * Only serializable content on bus * Fixed imports & removed some logging
This commit is contained in:
1 parent
f1eda430cd
commit
65ac1ae84a
5 files changed
+218
No files matched your search
@@ -0,0 +1,36 @@
|
||||
"""
|
||||
Support for Qwikswitch Relays as HA Switches.
|
||||
|
||||
See the main component for more info
|
||||
"""
|
||||
import logging
|
||||
import homeassistant.components.qwikswitch as qwikswitch
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
|
||||
DEPENDENCIES = ['qwikswitch']
|
||||
|
||||
|
||||
class QSSwitch(qwikswitch.QSToggleEntity, SwitchDevice):
|
||||
"""Switch based on a Qwikswitch relay module."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
# pylint: disable=unused-argument
|
||||
def setup_platform(hass, config, add_devices, discovery_info=None):
|
||||
"""Store add_devices for the 'switch' components."""
|
||||
if discovery_info is None or 'qsusb_id' not in discovery_info:
|
||||
logging.getLogger(__name__).error(
|
||||
'Configure main Qwikswitch component')
|
||||
return False
|
||||
|
||||
qsusb = qwikswitch.QSUSB[discovery_info['qsusb_id']]
|
||||
|
||||
for item in qsusb.ha_devices:
|
||||
if item['type'] == 'rel' and \
|
||||
item['name'].lower().endswith(' switch'):
|
||||
# Remove the ' Switch' name postfix for HA
|
||||
item['name'] = item['name'][:-7]
|
||||
dev = QSSwitch(item, qsusb)
|
||||
add_devices([dev])
|
||||
qsusb.ha_objects[item['id']] = dev
|
||||
Reference in new issue
Block a user