Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/modbus/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ async def async_open_cover(self, **kwargs: Any) -> None:
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."""
result = await self._hub.async_pymodbus_call(
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."""
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,6 +25,7 @@
STATE_CLOSING,
STATE_OPEN,
STATE_OPENING,
STATE_UNAVAILABLE,
)
from homeassistant.core import State

Expand Down Expand Up @@ -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