Qwikswitch fix listen loop (#22600)

* Qwikswitch fix listen loop
* 0.93 fix qwikcord upstream
This commit is contained in:
Johann Kellerman 2019-04-02 05:57:25 +02:00 committed by GitHub
parent 7646dc00e0
commit 2578c8525b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 13 deletions

View file

@ -19,7 +19,7 @@ import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.discovery import load_platform from homeassistant.helpers.discovery import load_platform
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
REQUIREMENTS = ['pyqwikswitch==0.8'] REQUIREMENTS = ['pyqwikswitch==0.93']
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -119,7 +119,8 @@ class QSToggleEntity(QSEntity):
async def async_setup(hass, config): async def async_setup(hass, config):
"""Qwiskswitch component setup.""" """Qwiskswitch component setup."""
from pyqwikswitch.async_ import QSUsb from pyqwikswitch.async_ import QSUsb
from pyqwikswitch import CMD_BUTTONS, QS_CMD, QS_ID, QSType, SENSORS from pyqwikswitch.qwikswitch import (
CMD_BUTTONS, QS_CMD, QS_ID, QSType, SENSORS)
# Add cmd's to in /&listen packets will fire events # Add cmd's to in /&listen packets will fire events
# By default only buttons of type [TOGGLE,SCENE EXE,LEVEL] # By default only buttons of type [TOGGLE,SCENE EXE,LEVEL]

View file

@ -35,7 +35,7 @@ class QSBinarySensor(QSEntity, BinarySensorDevice):
def __init__(self, sensor): def __init__(self, sensor):
"""Initialize the sensor.""" """Initialize the sensor."""
from pyqwikswitch import SENSORS from pyqwikswitch.qwikswitch import SENSORS
super().__init__(sensor['id'], sensor['name']) super().__init__(sensor['id'], sensor['name'])
self.channel = sensor['channel'] self.channel = sensor['channel']

View file

@ -33,7 +33,7 @@ class QSSensor(QSEntity):
def __init__(self, sensor): def __init__(self, sensor):
"""Initialize the sensor.""" """Initialize the sensor."""
from pyqwikswitch import SENSORS from pyqwikswitch.qwikswitch import SENSORS
super().__init__(sensor['id'], sensor['name']) super().__init__(sensor['id'], sensor['name'])
self.channel = sensor['channel'] self.channel = sensor['channel']

View file

@ -1238,7 +1238,7 @@ pypollencom==2.2.3
pyps4-homeassistant==0.5.2 pyps4-homeassistant==0.5.2
# homeassistant.components.qwikswitch # homeassistant.components.qwikswitch
pyqwikswitch==0.8 pyqwikswitch==0.93
# homeassistant.components.nmbs.sensor # homeassistant.components.nmbs.sensor
pyrail==0.0.3 pyrail==0.0.3

View file

@ -234,7 +234,7 @@ pyotp==2.2.6
pyps4-homeassistant==0.5.2 pyps4-homeassistant==0.5.2
# homeassistant.components.qwikswitch # homeassistant.components.qwikswitch
pyqwikswitch==0.8 pyqwikswitch==0.93
# homeassistant.components.smartthings # homeassistant.components.smartthings
pysmartapp==0.3.2 pysmartapp==0.3.2

View file

@ -7,6 +7,7 @@ from homeassistant.const import EVENT_HOMEASSISTANT_START
from homeassistant.components.qwikswitch import DOMAIN as QWIKSWITCH from homeassistant.components.qwikswitch import DOMAIN as QWIKSWITCH
from homeassistant.bootstrap import async_setup_component from homeassistant.bootstrap import async_setup_component
from tests.test_util.aiohttp import mock_aiohttp_client from tests.test_util.aiohttp import mock_aiohttp_client
from aiohttp.client_exceptions import ClientError
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -23,6 +24,8 @@ class AiohttpClientMockResponseList(list):
try: try:
res = list.pop(self, 0) res = list.pop(self, 0)
_LOGGER.debug("MockResponseList popped %s: %s", res, self) _LOGGER.debug("MockResponseList popped %s: %s", res, self)
if isinstance(res, Exception):
raise res
return res return res
except IndexError: except IndexError:
raise AssertionError("MockResponseList empty") raise AssertionError("MockResponseList empty")
@ -54,7 +57,7 @@ def aioclient_mock():
yield mock_session yield mock_session
async def test_binary_sensor_device(hass, aioclient_mock): async def test_binary_sensor_device(hass, aioclient_mock): # noqa
"""Test a binary sensor device.""" """Test a binary sensor device."""
config = { config = {
'qwikswitch': { 'qwikswitch': {
@ -75,7 +78,8 @@ async def test_binary_sensor_device(hass, aioclient_mock):
hass.bus.async_fire(EVENT_HOMEASSISTANT_START) hass.bus.async_fire(EVENT_HOMEASSISTANT_START)
LISTEN.append('{"id":"@a00001","cmd":"","data":"4e0e1601","rssi":"61%"}') LISTEN.append('{"id":"@a00001","cmd":"","data":"4e0e1601","rssi":"61%"}')
LISTEN.append('') # Will cause a sleep LISTEN.append(ClientError()) # Will cause a sleep
await hass.async_block_till_done() await hass.async_block_till_done()
state_obj = hass.states.get('binary_sensor.s1') state_obj = hass.states.get('binary_sensor.s1')
assert state_obj.state == 'on' assert state_obj.state == 'on'
@ -87,7 +91,7 @@ async def test_binary_sensor_device(hass, aioclient_mock):
assert state_obj.state == 'off' assert state_obj.state == 'off'
async def test_sensor_device(hass, aioclient_mock): async def test_sensor_device(hass, aioclient_mock): # noqa
"""Test a sensor device.""" """Test a sensor device."""
config = { config = {
'qwikswitch': { 'qwikswitch': {
@ -100,8 +104,8 @@ async def test_sensor_device(hass, aioclient_mock):
} }
} }
await async_setup_component(hass, QWIKSWITCH, config) await async_setup_component(hass, QWIKSWITCH, config)
await hass.async_block_till_done()
await hass.async_block_till_done()
state_obj = hass.states.get('sensor.ss1') state_obj = hass.states.get('sensor.ss1')
assert state_obj.state == 'None' assert state_obj.state == 'None'
@ -110,8 +114,7 @@ async def test_sensor_device(hass, aioclient_mock):
LISTEN.append( LISTEN.append(
'{"id":"@a00001","name":"ss1","type":"rel",' '{"id":"@a00001","name":"ss1","type":"rel",'
'"val":"4733800001a00000"}') '"val":"4733800001a00000"}')
LISTEN.append('') # Will cause a sleep
await LISTEN.wait_till_empty(hass) # await hass.async_block_till_done()
await hass.async_block_till_done()
state_obj = hass.states.get('sensor.ss1') state_obj = hass.states.get('sensor.ss1')
assert state_obj.state == 'None' assert state_obj.state == '416'