Update modbus cover to 100% coverage (#50996)
This commit is contained in:
parent
4b0b0f5db7
commit
f55213d8b1
3 changed files with 51 additions and 3 deletions
|
@ -630,7 +630,6 @@ omit =
|
|||
homeassistant/components/mjpeg/camera.py
|
||||
homeassistant/components/mochad/*
|
||||
homeassistant/components/modbus/climate.py
|
||||
homeassistant/components/modbus/cover.py
|
||||
homeassistant/components/modem_callerid/sensor.py
|
||||
homeassistant/components/motion_blinds/__init__.py
|
||||
homeassistant/components/motion_blinds/const.py
|
||||
|
|
|
@ -147,7 +147,7 @@ class ModbusCover(BasePlatform, CoverEntity, RestoreEntity):
|
|||
self._slave, self._register, self._state_open, self._write_type
|
||||
)
|
||||
self._available = result is not None
|
||||
self.async_update()
|
||||
await self.async_update()
|
||||
|
||||
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||
"""Close cover."""
|
||||
|
@ -155,7 +155,7 @@ class ModbusCover(BasePlatform, CoverEntity, RestoreEntity):
|
|||
self._slave, self._register, self._state_closed, self._write_type
|
||||
)
|
||||
self._available = result is not None
|
||||
self.async_update()
|
||||
await self.async_update()
|
||||
|
||||
async def async_update(self, now=None):
|
||||
"""Update the state of the cover."""
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""The tests for the Modbus cover component."""
|
||||
import logging
|
||||
|
||||
from pymodbus.exceptions import ModbusException
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.cover import DOMAIN as COVER_DOMAIN
|
||||
|
@ -24,6 +25,7 @@ from homeassistant.const import (
|
|||
STATE_CLOSING,
|
||||
STATE_OPEN,
|
||||
STATE_OPENING,
|
||||
STATE_UNAVAILABLE,
|
||||
)
|
||||
from homeassistant.core import State
|
||||
|
||||
|
@ -246,3 +248,50 @@ async def test_restore_state_cover(hass, state):
|
|||
method_discovery=True,
|
||||
)
|
||||
assert hass.states.get(entity_id).state == state
|
||||
|
||||
|
||||
async def test_service_cover_move(hass, mock_pymodbus):
|
||||
"""Run test for service homeassistant.update_entity."""
|
||||
|
||||
entity_id = "cover.test"
|
||||
entity_id2 = "cover.test2"
|
||||
config = {
|
||||
CONF_COVERS: [
|
||||
{
|
||||
CONF_NAME: "test",
|
||||
CONF_REGISTER: 1234,
|
||||
CONF_STATUS_REGISTER_TYPE: CALL_TYPE_REGISTER_HOLDING,
|
||||
},
|
||||
{
|
||||
CONF_NAME: "test2",
|
||||
CALL_TYPE_COIL: 1234,
|
||||
},
|
||||
]
|
||||
}
|
||||
mock_pymodbus.read_holding_registers.return_value = ReadResult([0x01])
|
||||
await prepare_service_update(
|
||||
hass,
|
||||
config,
|
||||
)
|
||||
await hass.services.async_call(
|
||||
"cover", "open_cover", {"entity_id": entity_id}, blocking=True
|
||||
)
|
||||
assert hass.states.get(entity_id).state == STATE_OPEN
|
||||
|
||||
mock_pymodbus.read_holding_registers.return_value = ReadResult([0x00])
|
||||
await hass.services.async_call(
|
||||
"cover", "close_cover", {"entity_id": entity_id}, blocking=True
|
||||
)
|
||||
assert hass.states.get(entity_id).state == STATE_CLOSED
|
||||
|
||||
mock_pymodbus.read_holding_registers.side_effect = ModbusException("fail write_")
|
||||
await hass.services.async_call(
|
||||
"cover", "close_cover", {"entity_id": entity_id}, blocking=True
|
||||
)
|
||||
assert hass.states.get(entity_id).state == STATE_UNAVAILABLE
|
||||
|
||||
mock_pymodbus.read_coils.side_effect = ModbusException("fail write_")
|
||||
await hass.services.async_call(
|
||||
"cover", "close_cover", {"entity_id": entity_id2}, blocking=True
|
||||
)
|
||||
assert hass.states.get(entity_id2).state == STATE_UNAVAILABLE
|
Loading…
Add table
Add a link
Reference in a new issue