Skip to content

Add cover entity to Fluss#169840

Closed
Marcello17 wants to merge 9 commits intohome-assistant:devfrom
fluss:fluss/cover-entity
Closed

Add cover entity to Fluss#169840
Marcello17 wants to merge 9 commits intohome-assistant:devfrom
fluss:fluss/cover-entity

Conversation

@Marcello17
Copy link
Copy Markdown
Contributor

Breaking change

Proposed change

Adds a cover platform to the Fluss+ integration so devices with a
position sensor are exposed as a garage door / gate cover instead of a
button. Builds on the per-device status fetch from #168154.

The dispatch is decided once per device at platform setup, based on
whether the API returns openCloseStatus. Devices that report it become a
CoverEntity (CoverDeviceClass.GARAGE, OPEN | CLOSE) and gain
explicit open/close commands plus open/closed state. Devices that don't
report it keep the existing button — the two are mutually exclusive per
device, so no user with an existing button setup loses anything.

Open and close go through the library's async_open_device /
async_close_device and end with coordinator.async_request_refresh(),
so state in the UI reflects the new position immediately rather than
waiting for the next 30 minute coordinator cycle. Library failures
translate to HomeAssistantError via open_failed / close_failed
translation keys.

Cover and button share the same coordinator, so we still make exactly one
status call per device per refresh — the existing
_async_get_connectivity helper is generalised to return the full
status payload, keeping connectivity behaviour and feeding openCloseStatus
to the cover from the same data.

While here, the coordinator is moved to a typed FlussDevice dataclass
(dict[str, FlussDevice]) instead of dict[str, dict[str, Any]], matching
the pattern in newer Platinum integrations like peblar, airgradient,
airos, airobot, and apcupsd. snake_case fields throughout; camelCase
conversion happens at the coordinator boundary.

openCloseStatus is parsed defensively for both the documented boolean
shape and the example-payload string shape — "Closed" / "Open"
(case-insensitive) and True / False both map correctly. Verified
locally against a real Fluss+ device.

100% test coverage on every fluss file (31 tests). ruff, hassfest,
and mypy clean.

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

@home-assistant
Copy link
Copy Markdown
Contributor

home-assistant Bot commented May 5, 2026

Hey there @fluss, mind taking a look at this pull request as it has been labeled with an integration (fluss) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of fluss can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign fluss Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

@Marcello17 Marcello17 marked this pull request as draft May 5, 2026 13:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new cover platform to the Fluss+ integration, exposing devices that report an openCloseStatus as garage-door-style covers while keeping the existing button entity for devices without a position sensor.

Changes:

  • Introduces a Fluss cover entity with open/close services and state derived from openCloseStatus.
  • Refactors coordinator data into a typed FlussDevice dataclass and expands per-device status fetching to include position status.
  • Adds snapshot + behavioral test coverage for the new cover platform, including mixed device dispatch.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
homeassistant/components/fluss/__init__.py Forwards the new cover platform alongside the existing button platform.
homeassistant/components/fluss/coordinator.py Introduces FlussDevice dataclass and fetches/merges per-device status payloads.
homeassistant/components/fluss/entity.py Updates base entity to use typed FlussDevice and adds helper for sensor capability detection.
homeassistant/components/fluss/button.py Filters out cover-capable devices and updates to use typed coordinator data.
homeassistant/components/fluss/cover.py Adds the new cover entity implementation (state parsing + open/close commands).
homeassistant/components/fluss/strings.json Adds translated exception messages for open/close failures.
tests/components/fluss/__init__.py Updates platform-forwarding expectation to include cover.
tests/components/fluss/test_cover.py Adds tests for cover registration, state parsing, services, errors, and mixed dispatch.
tests/components/fluss/snapshots/test_cover.ambr Adds entity/state snapshots for the cover platform.

Comment thread homeassistant/components/fluss/cover.py Outdated
Comment on lines +37 to +56
class FlussCover(FlussEntity, CoverEntity):
"""Representation of a Fluss+ cover (garage door / gate)."""

_attr_device_class = CoverDeviceClass.GARAGE
_attr_supported_features = CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE
_attr_name = None

@property
def is_closed(self) -> bool | None:
"""Return whether the cover is closed."""
status = self.device.open_close_status
if isinstance(status, bool):
return not status
if isinstance(status, str):
normalized = status.lower()
if normalized == "closed":
return True
if normalized == "open":
return False
return None

def has_open_close_sensor(device: FlussDevice) -> bool:
"""Return whether a device reports an open/close position sensor."""
return device.open_close_status is not None
Comment on lines +53 to +59
async def _async_get_status(self, device_id: str) -> dict[str, Any]:
"""Return per-device status; defaults to offline on API error."""
try:
status = await self.api.async_get_device_status(device_id)
response = await self.api.async_get_device_status(device_id)
except FlussApiClientError:
return False
return status["status"]["internetConnected"]
return {"internetConnected": False}
return response["status"]
Copilot AI review requested due to automatic review settings May 6, 2026 10:42
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Comment on lines +96 to +101
internet_connected = status.get("internetConnected", False)
if "openCloseStatus" in status:
self._cover_capable.add(device_id)
is_closed = status["openCloseStatus"] == "Close"
else:
is_closed = None
Comment on lines +80 to +95
@pytest.mark.parametrize(
("status_value", "expected_state"),
[("Close", STATE_CLOSED), ("Open", STATE_OPEN)],
)
async def test_cover_state(
hass: HomeAssistant,
mock_api_client: AsyncMock,
mock_config_entry: MockConfigEntry,
status_value: str,
expected_state: str,
) -> None:
"""The API contract is exactly "Open" or "Close" — verify both map correctly."""
mock_api_client.async_get_device_status.side_effect = _status_side_effect(
{DEVICE_ID_1: {"openCloseStatus": status_value}}
)
await _setup_cover_only(hass, mock_config_entry)
Comment on lines +72 to +77
except FlussApiClientError as err:
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="command_failed",
translation_placeholders={"error": str(err)},
) from err
Copilot AI review requested due to automatic review settings May 6, 2026 11:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

homeassistant/components/fluss/button.py:48

  • Use a translated HomeAssistantError (translation_domain/key) for button press failures to match the new translated cover command errors. The current plain string error message creates inconsistent UX and makes it harder to localize errors across the integration.
        try:
            await self.coordinator.api.async_trigger_device(self.device_id)
        except FlussApiClientError as err:
            raise HomeAssistantError(f"Failed to trigger device: {err}") from err

Comment on lines +96 to +100
internet_connected = status.get("internetConnected", False)
if "openCloseStatus" in status:
self._cover_capable.add(device_id)
is_closed = status["openCloseStatus"] == "Closed"
else:
internet_connected = status.get("internetConnected", False)
if "openCloseStatus" in status:
self._cover_capable.add(device_id)
is_closed = status["openCloseStatus"] == "Closed"
Comment on lines +68 to +77
async def async_open_cover(self, **kwargs: Any) -> None:
"""Open the cover."""
try:
await self.coordinator.api.async_open_device(self.device_id)
except FlussApiClientError as err:
raise HomeAssistantError(
translation_domain=DOMAIN,
translation_key="command_failed",
translation_placeholders={"error": str(err)},
) from err
Comment on lines +83 to +92
[("Closed", STATE_CLOSED), ("Open", STATE_OPEN)],
)
async def test_cover_state(
hass: HomeAssistant,
mock_api_client: AsyncMock,
mock_config_entry: MockConfigEntry,
status_value: str,
expected_state: str,
) -> None:
"""The API contract is exactly "Open" or "Closed" — verify both map correctly."""
@Marcello17 Marcello17 closed this May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants