Skip to content

Fix visualization by inverting open/closed state of patio awnings #128079

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2024
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
8 changes: 4 additions & 4 deletions homeassistant/components/wmspro/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Copy link
Contributor Author

@mback2k mback2k Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a middle-ground-solution, we could make this property function is_closed return the awning is closed (now meaning expanded) as soon as the current position in HA methodology is less than 100% (now meaning fully retracted) and therefore the awning being expanded even only a little bit. So, open would just mean fully retracted then to check it is really fully protected during storm/rain.

Any opinions about this?

Expand All @@ -61,12 +61,12 @@ def is_closed(self) -> bool | None:
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."""
Expand Down
4 changes: 2 additions & 2 deletions tests/components/wmspro/snapshots/test_cover.ambr
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -45,6 +45,6 @@
'last_changed': <ANY>,
'last_reported': <ANY>,
'last_updated': <ANY>,
'state': 'open',
'state': 'closed',
})
# ---
61 changes: 31 additions & 30 deletions tests/components/wmspro/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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."""
Expand All @@ -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,
Expand All @@ -87,8 +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
assert entity.state == STATE_CLOSED
assert entity.attributes["current_position"] == 0

with patch(
"wmspro.destination.Destination.refresh",
Expand All @@ -98,15 +99,15 @@ async def test_cover_close_and_open(

await hass.services.async_call(
Platform.COVER,
SERVICE_CLOSE_COVER,
SERVICE_OPEN_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 entity.state == STATE_OPEN
assert entity.attributes["current_position"] == 100
assert len(mock_hub_status_prod_awning.mock_calls) == before

with patch(
Expand All @@ -117,36 +118,36 @@ async def test_cover_close_and_open(

await hass.services.async_call(
Platform.COVER,
SERVICE_OPEN_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 == "open"
assert entity.attributes["current_position"] == 100
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_move(
async def test_cover_open_to_pos(
hass: HomeAssistant,
mock_config_entry: MockConfigEntry,
mock_hub_ping: AsyncMock,
mock_hub_configuration_prod: AsyncMock,
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
assert len(mock_hub_status_prod_awning.mock_calls) >= 1

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",
Expand All @@ -163,29 +164,29 @@ 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,
mock_hub_configuration_prod: AsyncMock,
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
assert len(mock_hub_status_prod_awning.mock_calls) >= 1

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",
Expand All @@ -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

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