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
This commit is contained in:
Raman Gupta 2022-02-22 06:03:01 -05:00 committed by GitHub
parent 909de62bd4
commit a12d6aa6ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 2 deletions

View File

@ -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,

View File

@ -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:

View File

@ -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

View File

@ -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,