From 25be71e05bf5cb1d0f37d44544402d0035e0530c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henning=20Cla=C3=9Fen?= Date: Wed, 20 Mar 2024 11:42:01 +0100 Subject: [PATCH] Bump numato-gpio to v0.13.0 (#113182) --- .../components/numato/binary_sensor.py | 11 +++- homeassistant/components/numato/manifest.json | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/numato/numato_mock.py | 3 +- tests/components/numato/test_binary_sensor.py | 63 +++++++++++++++---- 6 files changed, 65 insertions(+), 18 deletions(-) diff --git a/homeassistant/components/numato/binary_sensor.py b/homeassistant/components/numato/binary_sensor.py index ad81164d4fc..1f664a372ba 100644 --- a/homeassistant/components/numato/binary_sensor.py +++ b/homeassistant/components/numato/binary_sensor.py @@ -54,7 +54,6 @@ def setup_platform( for port, port_name in ports.items(): try: api.setup_input(device_id, port) - api.edge_detect(device_id, port, partial(read_gpio, device_id)) except NumatoGpioError as err: _LOGGER.error( @@ -68,7 +67,17 @@ def setup_platform( err, ) continue + try: + api.edge_detect(device_id, port, partial(read_gpio, device_id)) + except NumatoGpioError as err: + _LOGGER.info( + "Notification setup failed on device %s, " + "updates on binary sensor %s only in polling mode: %s", + device_id, + port_name, + err, + ) binary_sensors.append( NumatoGpioBinarySensor( port_name, diff --git a/homeassistant/components/numato/manifest.json b/homeassistant/components/numato/manifest.json index e6efcea5315..f7bcf0527c2 100644 --- a/homeassistant/components/numato/manifest.json +++ b/homeassistant/components/numato/manifest.json @@ -6,5 +6,5 @@ "integration_type": "hub", "iot_class": "local_push", "loggers": ["numato_gpio"], - "requirements": ["numato-gpio==0.12.0"] + "requirements": ["numato-gpio==0.13.0"] } diff --git a/requirements_all.txt b/requirements_all.txt index a56caf9d960..8a0595fd479 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -1406,7 +1406,7 @@ nsw-fuel-api-client==1.1.0 nuheat==1.0.1 # homeassistant.components.numato -numato-gpio==0.12.0 +numato-gpio==0.13.0 # homeassistant.components.compensation # homeassistant.components.iqvia diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 738f43a1eca..32f3ea73a97 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -1124,7 +1124,7 @@ nsw-fuel-api-client==1.1.0 nuheat==1.0.1 # homeassistant.components.numato -numato-gpio==0.12.0 +numato-gpio==0.13.0 # homeassistant.components.compensation # homeassistant.components.iqvia diff --git a/tests/components/numato/numato_mock.py b/tests/components/numato/numato_mock.py index 04c10911faf..097a785beb1 100644 --- a/tests/components/numato/numato_mock.py +++ b/tests/components/numato/numato_mock.py @@ -62,7 +62,8 @@ class NumatoModuleMock: Ignore the device list argument, mock discovers /dev/ttyACM0. """ - self.devices[0] = NumatoModuleMock.NumatoDeviceMock("/dev/ttyACM0") + if not self.devices: + self.devices[0] = NumatoModuleMock.NumatoDeviceMock("/dev/ttyACM0") def cleanup(self): """Mockup for the numato device cleanup.""" diff --git a/tests/components/numato/test_binary_sensor.py b/tests/components/numato/test_binary_sensor.py index 6b45ef05a0d..e353de5e7df 100644 --- a/tests/components/numato/test_binary_sensor.py +++ b/tests/components/numato/test_binary_sensor.py @@ -1,11 +1,17 @@ """Tests for the numato binary_sensor platform.""" +import logging +from unittest.mock import patch + +import pytest + from homeassistant.const import Platform from homeassistant.core import HomeAssistant from homeassistant.helpers import discovery from homeassistant.setup import async_setup_component from .common import NUMATO_CFG, mockup_raise +from .numato_mock import NumatoGpioError, NumatoModuleMock MOCKUP_ENTITY_IDS = { "binary_sensor.numato_binary_sensor_mock_port2", @@ -25,23 +31,25 @@ async def test_failing_setups_no_entities( assert entity_id not in hass.states.async_entity_ids() -async def test_setup_callbacks( - hass: HomeAssistant, numato_fixture, monkeypatch -) -> None: +async def test_setup_callbacks(hass: HomeAssistant, numato_fixture) -> None: """During setup a callback shall be registered.""" - numato_fixture.discover() + with patch.object( + NumatoModuleMock.NumatoDeviceMock, "add_event_detect" + ) as mock_add_event_detect: + numato_fixture.discover() + assert await async_setup_component(hass, "numato", NUMATO_CFG) + await hass.async_block_till_done() # wait until services are registered - def mock_add_event_detect(self, port, callback, direction): - assert self == numato_fixture.devices[0] - assert port == 1 - assert callback is callable - assert direction == numato_fixture.BOTH - - monkeypatch.setattr( - numato_fixture.devices[0], "add_event_detect", mock_add_event_detect + mock_add_event_detect.assert_called() + assert {call.args[0] for call in mock_add_event_detect.mock_calls} == { + int(port) + for port in NUMATO_CFG["numato"]["devices"][0]["binary_sensors"]["ports"] + } + assert all(callable(call.args[1]) for call in mock_add_event_detect.mock_calls) + assert all( + call.args[2] == numato_fixture.BOTH for call in mock_add_event_detect.mock_calls ) - assert await async_setup_component(hass, "numato", NUMATO_CFG) async def test_hass_binary_sensor_notification( @@ -73,3 +81,32 @@ async def test_binary_sensor_setup_without_discovery_info( await hass.async_block_till_done() # wait for numato platform to be loaded for entity_id in MOCKUP_ENTITY_IDS: assert entity_id in hass.states.async_entity_ids() + + +async def test_binary_sensor_setup_no_notify( + hass: HomeAssistant, + numato_fixture, + caplog: pytest.LogCaptureFixture, +) -> None: + """Setup of a device without notification capability shall print an info message.""" + caplog.set_level(logging.INFO) + + def raise_notification_error(self, port, callback, direction): + raise NumatoGpioError( + f"{repr(self)} Mockup device doesn't support notifications." + ) + + with patch.object( + NumatoModuleMock.NumatoDeviceMock, + "add_event_detect", + raise_notification_error, + ): + numato_fixture.discover() + assert await async_setup_component(hass, "numato", NUMATO_CFG) + await hass.async_block_till_done() # wait until services are registered + + assert all( + f"updates on binary sensor numato_binary_sensor_mock_port{port} only in polling mode" + in caplog.text + for port in NUMATO_CFG["numato"]["devices"][0]["binary_sensors"]["ports"] + )