mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Handle exception in modbus slave sensor (#67472)
This commit is contained in:
parent
dc24e6505e
commit
a4915eb704
@ -101,6 +101,9 @@ class ModbusRegisterSensor(BaseStructPlatform, RestoreEntity, SensorEntity):
|
||||
return
|
||||
self._lazy_errors = self._lazy_error_count
|
||||
self._attr_available = False
|
||||
self._attr_native_value = None
|
||||
if self._coordinator:
|
||||
self._coordinator.async_set_updated_data(None)
|
||||
self.async_write_ha_state()
|
||||
return
|
||||
|
||||
|
@ -33,6 +33,7 @@ from homeassistant.const import (
|
||||
CONF_SLAVE,
|
||||
CONF_STRUCTURE,
|
||||
STATE_UNAVAILABLE,
|
||||
STATE_UNKNOWN,
|
||||
)
|
||||
from homeassistant.core import State
|
||||
|
||||
@ -565,13 +566,14 @@ async def test_all_sensor(hass, mock_do_cycle, expected):
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"config_addon,register_words,expected",
|
||||
"config_addon,register_words,do_exception,expected",
|
||||
[
|
||||
(
|
||||
{
|
||||
CONF_SLAVE_COUNT: 0,
|
||||
},
|
||||
[0x0102, 0x0304],
|
||||
False,
|
||||
["16909060"],
|
||||
),
|
||||
(
|
||||
@ -579,6 +581,7 @@ async def test_all_sensor(hass, mock_do_cycle, expected):
|
||||
CONF_SLAVE_COUNT: 1,
|
||||
},
|
||||
[0x0102, 0x0304, 0x0403, 0x0201],
|
||||
False,
|
||||
["16909060", "67305985"],
|
||||
),
|
||||
(
|
||||
@ -595,6 +598,7 @@ async def test_all_sensor(hass, mock_do_cycle, expected):
|
||||
0x0D0E,
|
||||
0x0F00,
|
||||
],
|
||||
False,
|
||||
[
|
||||
"16909060",
|
||||
"84281096",
|
||||
@ -602,6 +606,22 @@ async def test_all_sensor(hass, mock_do_cycle, expected):
|
||||
"219025152",
|
||||
],
|
||||
),
|
||||
(
|
||||
{
|
||||
CONF_SLAVE_COUNT: 1,
|
||||
},
|
||||
[0x0102, 0x0304, 0x0403, 0x0201],
|
||||
True,
|
||||
[STATE_UNAVAILABLE, STATE_UNKNOWN],
|
||||
),
|
||||
(
|
||||
{
|
||||
CONF_SLAVE_COUNT: 1,
|
||||
},
|
||||
[],
|
||||
False,
|
||||
[STATE_UNAVAILABLE, STATE_UNKNOWN],
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_slave_sensor(hass, mock_do_cycle, expected):
|
||||
|
Loading…
x
Reference in New Issue
Block a user