From f71027a9c70164a3d56134d6eaa95ebf9578d586 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Mon, 2 Jan 2017 23:19:33 -0800 Subject: [PATCH] Nx584 maint (#5149) * Update nx584 requirement to 0.4 There have been a few bug fixes to nx584 since 0.2, so this just updates our requirement to pull in the newer version. * Fix nx584 if no partitions are found If we succeed in our connection to the panel but find no configured partitions, then we will fall through to the bypass probe and fail because 'zones' is never initialized. This fixes both exception paths and adds a test that would poke it. --- homeassistant/components/alarm_control_panel/nx584.py | 4 +++- homeassistant/components/binary_sensor/nx584.py | 2 +- requirements_all.txt | 2 +- tests/components/binary_sensor/test_nx584.py | 6 ++++++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/alarm_control_panel/nx584.py b/homeassistant/components/alarm_control_panel/nx584.py index 58ec8d915ab..b7b3beec72d 100644 --- a/homeassistant/components/alarm_control_panel/nx584.py +++ b/homeassistant/components/alarm_control_panel/nx584.py @@ -16,7 +16,7 @@ from homeassistant.const import ( STATE_UNKNOWN, CONF_NAME, CONF_HOST, CONF_PORT) import homeassistant.helpers.config_validation as cv -REQUIREMENTS = ['pynx584==0.2'] +REQUIREMENTS = ['pynx584==0.4'] _LOGGER = logging.getLogger(__name__) @@ -86,9 +86,11 @@ class NX584Alarm(alarm.AlarmControlPanel): _LOGGER.error('Unable to connect to %(host)s: %(reason)s', dict(host=self._url, reason=ex)) self._state = STATE_UNKNOWN + zones = [] except IndexError: _LOGGER.error('nx584 reports no partitions') self._state = STATE_UNKNOWN + zones = [] bypassed = False for zone in zones: diff --git a/homeassistant/components/binary_sensor/nx584.py b/homeassistant/components/binary_sensor/nx584.py index b21e40dc5dd..ad7612d11a6 100644 --- a/homeassistant/components/binary_sensor/nx584.py +++ b/homeassistant/components/binary_sensor/nx584.py @@ -16,7 +16,7 @@ from homeassistant.components.binary_sensor import ( from homeassistant.const import (CONF_HOST, CONF_PORT) import homeassistant.helpers.config_validation as cv -REQUIREMENTS = ['pynx584==0.2'] +REQUIREMENTS = ['pynx584==0.4'] _LOGGER = logging.getLogger(__name__) diff --git a/requirements_all.txt b/requirements_all.txt index cb04ecbab75..79cfbb5c588 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -442,7 +442,7 @@ pynut2==2.1.2 # homeassistant.components.alarm_control_panel.nx584 # homeassistant.components.binary_sensor.nx584 -pynx584==0.2 +pynx584==0.4 # homeassistant.components.sensor.openweathermap # homeassistant.components.weather.openweathermap diff --git a/tests/components/binary_sensor/test_nx584.py b/tests/components/binary_sensor/test_nx584.py index 5481bbc9198..ef8861e12ce 100644 --- a/tests/components/binary_sensor/test_nx584.py +++ b/tests/components/binary_sensor/test_nx584.py @@ -106,6 +106,12 @@ class TestNX584SensorSetup(unittest.TestCase): requests.exceptions.ConnectionError self._test_assert_graceful_fail({}) + def test_setup_no_partitions(self): + """Test the setup with connection failure.""" + nx584_client.Client.return_value.list_zones.side_effect = \ + IndexError + self._test_assert_graceful_fail({}) + def test_setup_version_too_old(self): """"Test if version is too old.""" nx584_client.Client.return_value.get_version.return_value = '1.0'