From a12d6aa6ffc7129a7be6ce2426fcbf14f84b10a2 Mon Sep 17 00:00:00 2001 From: Raman Gupta <7243222+raman325@users.noreply.github.com> Date: Tue, 22 Feb 2022 06:03:01 -0500 Subject: [PATCH] Log error when using zwave_js 'refresh_value' on ping button/node status sensor (#66847) * Raise when using 'zwave_js.refresh_value' on ping button * Revert test change * block till done * Switch from raising an exception to logging an error for both the ping button and node status sensor * missed commit --- homeassistant/components/zwave_js/button.py | 18 +++++++++++++++++- homeassistant/components/zwave_js/sensor.py | 5 ++++- tests/components/zwave_js/test_button.py | 13 +++++++++++++ tests/components/zwave_js/test_sensor.py | 13 +++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/zwave_js/button.py b/homeassistant/components/zwave_js/button.py index ef8572fedc3b..fb62bbdc3dc1 100644 --- a/homeassistant/components/zwave_js/button.py +++ b/homeassistant/components/zwave_js/button.py @@ -11,7 +11,7 @@ from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import DeviceInfo, EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback -from .const import DATA_CLIENT, DOMAIN +from .const import DATA_CLIENT, DOMAIN, LOGGER from .helpers import get_device_id, get_valueless_base_unique_id @@ -58,8 +58,24 @@ class ZWaveNodePingButton(ButtonEntity): identifiers={get_device_id(client, node)}, ) + async def async_poll_value(self, _: bool) -> None: + """Poll a value.""" + # pylint: disable=no-self-use + LOGGER.error( + "There is no value to refresh for this entity so the zwave_js.refresh_value " + "service won't work for it" + ) + async def async_added_to_hass(self) -> None: """Call when entity is added.""" + self.async_on_remove( + async_dispatcher_connect( + self.hass, + f"{DOMAIN}_{self.unique_id}_poll_value", + self.async_poll_value, + ) + ) + self.async_on_remove( async_dispatcher_connect( self.hass, diff --git a/homeassistant/components/zwave_js/sensor.py b/homeassistant/components/zwave_js/sensor.py index 840c36b7fde6..8ac909d76de9 100644 --- a/homeassistant/components/zwave_js/sensor.py +++ b/homeassistant/components/zwave_js/sensor.py @@ -488,7 +488,10 @@ class ZWaveNodeStatusSensor(SensorEntity): async def async_poll_value(self, _: bool) -> None: """Poll a value.""" # pylint: disable=no-self-use - raise ValueError("There is no value to poll for this entity") + LOGGER.error( + "There is no value to refresh for this entity so the zwave_js.refresh_value " + "service won't work for it" + ) @callback def _status_changed(self, _: dict) -> None: diff --git a/tests/components/zwave_js/test_button.py b/tests/components/zwave_js/test_button.py index deb95e5eef4d..9b5ac66b06fa 100644 --- a/tests/components/zwave_js/test_button.py +++ b/tests/components/zwave_js/test_button.py @@ -1,5 +1,6 @@ """Test the Z-Wave JS button entities.""" from homeassistant.components.button.const import DOMAIN as BUTTON_DOMAIN, SERVICE_PRESS +from homeassistant.components.zwave_js.const import DOMAIN, SERVICE_REFRESH_VALUE from homeassistant.const import ATTR_ENTITY_ID @@ -8,6 +9,7 @@ async def test_ping_entity( client, climate_radio_thermostat_ct100_plus_different_endpoints, integration, + caplog, ): """Test ping entity.""" client.async_send_command.return_value = {"responded": True} @@ -31,3 +33,14 @@ async def test_ping_entity( ) client.async_send_command.reset_mock() + + await hass.services.async_call( + DOMAIN, + SERVICE_REFRESH_VALUE, + { + ATTR_ENTITY_ID: "button.z_wave_thermostat_ping", + }, + blocking=True, + ) + + assert "There is no value to refresh for this entity" in caplog.text diff --git a/tests/components/zwave_js/test_sensor.py b/tests/components/zwave_js/test_sensor.py index c632f0fca177..891a417551ea 100644 --- a/tests/components/zwave_js/test_sensor.py +++ b/tests/components/zwave_js/test_sensor.py @@ -15,6 +15,7 @@ from homeassistant.components.zwave_js.const import ( ATTR_METER_TYPE_NAME, ATTR_VALUE, DOMAIN, + SERVICE_REFRESH_VALUE, SERVICE_RESET_METER, ) from homeassistant.const import ( @@ -207,6 +208,7 @@ async def test_node_status_sensor_not_ready( lock_id_lock_as_id150_not_ready, lock_id_lock_as_id150_state, integration, + caplog, ): """Test node status sensor is created and available if node is not ready.""" NODE_STATUS_ENTITY = "sensor.z_wave_module_for_id_lock_150_and_101_node_status" @@ -234,6 +236,17 @@ async def test_node_status_sensor_not_ready( assert hass.states.get(NODE_STATUS_ENTITY) assert hass.states.get(NODE_STATUS_ENTITY).state == "alive" + await hass.services.async_call( + DOMAIN, + SERVICE_REFRESH_VALUE, + { + ATTR_ENTITY_ID: NODE_STATUS_ENTITY, + }, + blocking=True, + ) + + assert "There is no value to refresh for this entity" in caplog.text + async def test_reset_meter( hass,