Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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',
})
# ---
34 changes: 17 additions & 17 deletions tests/components/wmspro/test_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ async def test_cover_update(
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 +87,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 == "closed"
assert entity.attributes["current_position"] == 0

with patch(
"wmspro.destination.Destination.refresh",
Expand All @@ -98,15 +98,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 == "open"
assert entity.attributes["current_position"] == 100
assert len(mock_hub_status_prod_awning.mock_calls) == before

with patch(
Expand All @@ -117,36 +117,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 == "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 == "closed"
assert entity.attributes["current_position"] == 0

with patch(
"wmspro.destination.Destination.refresh",
Expand All @@ -168,24 +168,24 @@ async def test_cover_move(
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 == "closed"
assert entity.attributes["current_position"] == 0

with patch(
"wmspro.destination.Destination.refresh",
Expand Down