mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 17:27:10 +00:00
Fix visualization by inverting open/closed state of patio awnings (#128079)
This commit is contained in:
parent
c264ee22e7
commit
2c9ad9562e
@ -46,12 +46,12 @@ class WebControlProAwning(WebControlProGenericEntity, CoverEntity):
|
||||
def current_cover_position(self) -> int | None:
|
||||
"""Return current position of cover."""
|
||||
action = self._dest.action(WMS_WebControl_pro_API_actionDescription.AwningDrive)
|
||||
return action["percentage"]
|
||||
return 100 - action["percentage"]
|
||||
|
||||
async def async_set_cover_position(self, **kwargs: Any) -> None:
|
||||
"""Move the cover to a specific position."""
|
||||
action = self._dest.action(WMS_WebControl_pro_API_actionDescription.AwningDrive)
|
||||
await action(percentage=kwargs[ATTR_POSITION])
|
||||
await action(percentage=100 - kwargs[ATTR_POSITION])
|
||||
|
||||
@property
|
||||
def is_closed(self) -> bool | None:
|
||||
@ -61,12 +61,12 @@ class WebControlProAwning(WebControlProGenericEntity, CoverEntity):
|
||||
async def async_open_cover(self, **kwargs: Any) -> None:
|
||||
"""Open the cover."""
|
||||
action = self._dest.action(WMS_WebControl_pro_API_actionDescription.AwningDrive)
|
||||
await action(percentage=100)
|
||||
await action(percentage=0)
|
||||
|
||||
async def async_close_cover(self, **kwargs: Any) -> None:
|
||||
"""Close the cover."""
|
||||
action = self._dest.action(WMS_WebControl_pro_API_actionDescription.AwningDrive)
|
||||
await action(percentage=0)
|
||||
await action(percentage=100)
|
||||
|
||||
async def async_stop_cover(self, **kwargs: Any) -> None:
|
||||
"""Stop the device if in motion."""
|
||||
|
@ -35,7 +35,7 @@
|
||||
StateSnapshot({
|
||||
'attributes': ReadOnlyDict({
|
||||
'attribution': 'Data provided by WMS WebControl pro API',
|
||||
'current_position': 100,
|
||||
'current_position': 0,
|
||||
'device_class': 'awning',
|
||||
'friendly_name': 'Markise',
|
||||
'supported_features': <CoverEntityFeature: 15>,
|
||||
@ -45,6 +45,6 @@
|
||||
'last_changed': <ANY>,
|
||||
'last_reported': <ANY>,
|
||||
'last_updated': <ANY>,
|
||||
'state': 'open',
|
||||
'state': 'closed',
|
||||
})
|
||||
# ---
|
||||
|
@ -2,24 +2,27 @@
|
||||
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
from freezegun.api import FrozenDateTimeFactory
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.wmspro.const import DOMAIN
|
||||
from homeassistant.components.wmspro.cover import SCAN_INTERVAL
|
||||
from homeassistant.const import (
|
||||
ATTR_ENTITY_ID,
|
||||
SERVICE_CLOSE_COVER,
|
||||
SERVICE_OPEN_COVER,
|
||||
SERVICE_SET_COVER_POSITION,
|
||||
SERVICE_STOP_COVER,
|
||||
STATE_CLOSED,
|
||||
STATE_OPEN,
|
||||
Platform,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import device_registry as dr
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
||||
from . import setup_config_entry
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
||||
|
||||
async def test_cover_device(
|
||||
@ -48,6 +51,7 @@ async def test_cover_update(
|
||||
mock_hub_ping: AsyncMock,
|
||||
mock_hub_configuration_prod: AsyncMock,
|
||||
mock_hub_status_prod_awning: AsyncMock,
|
||||
freezer: FrozenDateTimeFactory,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test that a cover entity is created and updated correctly."""
|
||||
@ -60,18 +64,15 @@ async def test_cover_update(
|
||||
assert entity is not None
|
||||
assert entity == snapshot
|
||||
|
||||
await async_setup_component(hass, "homeassistant", {})
|
||||
await hass.services.async_call(
|
||||
"homeassistant",
|
||||
"update_entity",
|
||||
{ATTR_ENTITY_ID: entity.entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
# Move time to next update
|
||||
freezer.tick(SCAN_INTERVAL)
|
||||
async_fire_time_changed(hass)
|
||||
await hass.async_block_till_done(wait_background_tasks=True)
|
||||
|
||||
assert len(mock_hub_status_prod_awning.mock_calls) == 3
|
||||
assert len(mock_hub_status_prod_awning.mock_calls) >= 3
|
||||
|
||||
|
||||
async def test_cover_close_and_open(
|
||||
async def test_cover_open_and_close(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_hub_ping: AsyncMock,
|
||||
@ -87,27 +88,8 @@ async def test_cover_close_and_open(
|
||||
|
||||
entity = hass.states.get("cover.markise")
|
||||
assert entity is not None
|
||||
assert entity.state == "open"
|
||||
assert entity.attributes["current_position"] == 100
|
||||
|
||||
with patch(
|
||||
"wmspro.destination.Destination.refresh",
|
||||
return_value=True,
|
||||
):
|
||||
before = len(mock_hub_status_prod_awning.mock_calls)
|
||||
|
||||
await hass.services.async_call(
|
||||
Platform.COVER,
|
||||
SERVICE_CLOSE_COVER,
|
||||
{ATTR_ENTITY_ID: entity.entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
entity = hass.states.get("cover.markise")
|
||||
assert entity is not None
|
||||
assert entity.state == "closed"
|
||||
assert entity.attributes["current_position"] == 0
|
||||
assert len(mock_hub_status_prod_awning.mock_calls) == before
|
||||
assert entity.state == STATE_CLOSED
|
||||
assert entity.attributes["current_position"] == 0
|
||||
|
||||
with patch(
|
||||
"wmspro.destination.Destination.refresh",
|
||||
@ -124,12 +106,31 @@ async def test_cover_close_and_open(
|
||||
|
||||
entity = hass.states.get("cover.markise")
|
||||
assert entity is not None
|
||||
assert entity.state == "open"
|
||||
assert entity.state == STATE_OPEN
|
||||
assert entity.attributes["current_position"] == 100
|
||||
assert len(mock_hub_status_prod_awning.mock_calls) == before
|
||||
|
||||
with patch(
|
||||
"wmspro.destination.Destination.refresh",
|
||||
return_value=True,
|
||||
):
|
||||
before = len(mock_hub_status_prod_awning.mock_calls)
|
||||
|
||||
async def test_cover_move(
|
||||
await hass.services.async_call(
|
||||
Platform.COVER,
|
||||
SERVICE_CLOSE_COVER,
|
||||
{ATTR_ENTITY_ID: entity.entity_id},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
entity = hass.states.get("cover.markise")
|
||||
assert entity is not None
|
||||
assert entity.state == STATE_CLOSED
|
||||
assert entity.attributes["current_position"] == 0
|
||||
assert len(mock_hub_status_prod_awning.mock_calls) == before
|
||||
|
||||
|
||||
async def test_cover_open_to_pos(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_hub_ping: AsyncMock,
|
||||
@ -137,7 +138,7 @@ async def test_cover_move(
|
||||
mock_hub_status_prod_awning: AsyncMock,
|
||||
mock_action_call: AsyncMock,
|
||||
) -> None:
|
||||
"""Test that a cover entity is moved and closed correctly."""
|
||||
"""Test that a cover entity is opened to correct position."""
|
||||
assert await setup_config_entry(hass, mock_config_entry)
|
||||
assert len(mock_hub_ping.mock_calls) == 1
|
||||
assert len(mock_hub_configuration_prod.mock_calls) == 1
|
||||
@ -145,8 +146,8 @@ async def test_cover_move(
|
||||
|
||||
entity = hass.states.get("cover.markise")
|
||||
assert entity is not None
|
||||
assert entity.state == "open"
|
||||
assert entity.attributes["current_position"] == 100
|
||||
assert entity.state == STATE_CLOSED
|
||||
assert entity.attributes["current_position"] == 0
|
||||
|
||||
with patch(
|
||||
"wmspro.destination.Destination.refresh",
|
||||
@ -163,12 +164,12 @@ async def test_cover_move(
|
||||
|
||||
entity = hass.states.get("cover.markise")
|
||||
assert entity is not None
|
||||
assert entity.state == "open"
|
||||
assert entity.state == STATE_OPEN
|
||||
assert entity.attributes["current_position"] == 50
|
||||
assert len(mock_hub_status_prod_awning.mock_calls) == before
|
||||
|
||||
|
||||
async def test_cover_move_and_stop(
|
||||
async def test_cover_open_and_stop(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_hub_ping: AsyncMock,
|
||||
@ -176,7 +177,7 @@ async def test_cover_move_and_stop(
|
||||
mock_hub_status_prod_awning: AsyncMock,
|
||||
mock_action_call: AsyncMock,
|
||||
) -> None:
|
||||
"""Test that a cover entity is moved and closed correctly."""
|
||||
"""Test that a cover entity is opened and stopped correctly."""
|
||||
assert await setup_config_entry(hass, mock_config_entry)
|
||||
assert len(mock_hub_ping.mock_calls) == 1
|
||||
assert len(mock_hub_configuration_prod.mock_calls) == 1
|
||||
@ -184,8 +185,8 @@ async def test_cover_move_and_stop(
|
||||
|
||||
entity = hass.states.get("cover.markise")
|
||||
assert entity is not None
|
||||
assert entity.state == "open"
|
||||
assert entity.attributes["current_position"] == 100
|
||||
assert entity.state == STATE_CLOSED
|
||||
assert entity.attributes["current_position"] == 0
|
||||
|
||||
with patch(
|
||||
"wmspro.destination.Destination.refresh",
|
||||
@ -202,7 +203,7 @@ async def test_cover_move_and_stop(
|
||||
|
||||
entity = hass.states.get("cover.markise")
|
||||
assert entity is not None
|
||||
assert entity.state == "open"
|
||||
assert entity.state == STATE_OPEN
|
||||
assert entity.attributes["current_position"] == 80
|
||||
assert len(mock_hub_status_prod_awning.mock_calls) == before
|
||||
|
||||
@ -221,6 +222,6 @@ async def test_cover_move_and_stop(
|
||||
|
||||
entity = hass.states.get("cover.markise")
|
||||
assert entity is not None
|
||||
assert entity.state == "open"
|
||||
assert entity.state == STATE_OPEN
|
||||
assert entity.attributes["current_position"] == 80
|
||||
assert len(mock_hub_status_prod_awning.mock_calls) == before
|
||||
|
Loading…
x
Reference in New Issue
Block a user