8000 Add cover platform to Qbus integration by thomasddn · Pull Request #145771 · home-assistant/core · GitHub
[go: up one dir, main page]

Skip to content

Add cover platform to Qbus integration #145771

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

Closed
wants to merge 5 commits into from
Closed
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
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'upstream/dev' into platform-cover
  • Loading branch information
thomasddn committed May 27, 2025
commit 6e585b3d7726c2512139952cba3fb18b86a5dab9
9 changes: 4 additions & 5 deletions homeassistant/components/qbus/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

from .const import DOMAIN
from .coordinator import QbusConfigEntry, QbusControllerCoordinator
from .coordinator import QbusConfigEntry
from .entity import QbusEntity, add_new_outputs

PARALLEL_UPDATES = 0
Expand Down Expand Up @@ -59,18 +59,17 @@ class QbusClimate(QbusEntity, ClimateEntity):

_state_cls = QbusMqttThermoState

_attr_name = None
_attr_hvac_modes = [HVACMode.HEAT]
_attr_supported_features = (
ClimateEntityFeature.PRESET_MODE | ClimateEntityFeature.TARGET_TEMPERATURE
)
_attr_temperature_unit = UnitOfTemperature.CELSIUS

def __init__(
self, coordinator: QbusControllerCoordinator, mqtt_output: QbusMqttOutput
) -> None:
def __init__(self, mqtt_output: QbusMqttOutput) -> None:
"""Initialize climate entity."""

super().__init__(coordinator, mqtt_output)
super().__init__(mqtt_output)

self._attr_hvac_action = HVACAction.IDLE
self._attr_hvac_mode = HVACMode.HEAT
Expand Down
9 changes: 4 additions & 5 deletions homeassistant/components/qbus/cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

from .coordinator import QbusConfigEntry, QbusControllerCoordinator
from .coordinator import QbusConfigEntry
from .entity import QbusEntity, add_new_outputs

PARALLEL_UPDATES = 0
Expand Down Expand Up @@ -53,15 +53,14 @@ class QbusCover(QbusEntity, CoverEntity):

_state_cls = QbusMqttShutterState

_attr_name = None
_attr_supported_features: CoverEntityFeature
_attr_device_class = CoverDeviceClass.BLIND

def __init__(
self, coordinator: QbusControllerCoordinator, mqtt_output: QbusMqttOutput
) -> None:
def __init__(self, mqtt_output: QbusMqttOutput) -> None:
"""Initialize cover entity."""

super().__init__(coordinator, mqtt_output)
super().__init__(mqtt_output)

self._attr_assumed_state = False
self._attr_current_cover_position = 0
Expand Down
15 changes: 8 additions & 7 deletions homeassistant/components/qbus/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def add_new_outputs(

if new_outputs:
added_outputs.extend(new_outputs)
async_add_entities([entity_type(coordinator, output) for output in new_outputs])
async_add_entities([entity_type(output) for output in new_outputs])


def format_ref_id(ref_id: str) -> str | None:
Expand All @@ -57,21 +57,22 @@ def format_ref_id(ref_id: str) -> str | None:
return None


def create_main_device_identifier(mqtt_output: QbusMqttOutput) -> tuple[str, str]:
"""Create the identifier referring to the main device this output belongs to."""
return (DOMAIN, format_mac(mqtt_output.device.mac))


class QbusEntity(Entity, Generic[StateT], ABC):
"""Representation of a Qbus entity."""

_state_cls: type[StateT] = cast(type[StateT], QbusMqttState)

_attr_has_entity_name = True
_attr_name: str | None = None
_attr_should_poll = False

def __init__(
self, coordinator: QbusControllerCoordinator, mqtt_output: QbusMqttOutput
) -> None:
def __init__(self, mqtt_output: QbusMqttOutput) -> None:
"""Initialize the Qbus entity."""

self._coordinator = coordinator
self._mqtt_output = mqtt_output

self._topic_factory = QbusMqttTopicFactory()
Expand All @@ -90,7 +91,7 @@ def __init__(
manufacturer=MANUFACTURER,
identifiers={(DOMAIN, f"{mqtt_output.device.serial_number}_{ref_id}")},
suggested_area=mqtt_output.location.title(),
via_device=(DOMAIN, format_mac(mqtt_output.device.mac)),
via_device=create_main_device_identifier(mqtt_output),
)

async def async_added_to_hass(self) -> None:
Expand Down
9 changes: 4 additions & 5 deletions homeassistant/components/qbus/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.util.color import brightness_to_value, value_to_brightness

from .coordinator import QbusConfigEntry, QbusControllerCoordinator
from .coordinator import QbusConfigEntry
from .entity import QbusEntity, add_new_outputs

PARALLEL_UPDATES = 0
Expand Down Expand Up @@ -44,15 +44,14 @@ class QbusLight(QbusEntity, LightEntity):

_state_cls = QbusMqttAnalogState

_attr_name = None
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
_attr_color_mode = ColorMode.BRIGHTNESS

def __init__(
self, coordinator: QbusControllerCoordinator, mqtt_output: QbusMqttOutput
) -> None:
def __init__(self, mqtt_output: QbusMqttOutput) -> None:
"""Initialize light entity."""

super().__init__(coordinator, mqtt_output)
super().__init__(mqtt_output)

self._set_state(0)

Expand Down
30 changes: 10 additions & 20 deletions homeassistant/components/qbus/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

from homeassistant.components.scene import Scene< 67E6 /td>
from homeassistant.core import HomeAssistant
from homeassistant.helpers.device_registry import DeviceInfo
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback
from homeassistant.util import dt as dt_util

from .coordinator import QbusConfigEntry, QbusControllerCoordinator
from .entity import QbusEntity, add_new_outputs
from .coordinator import QbusConfigEntry
from .entity import QbusEntity, add_new_outputs, create_main_device_identifier

PARALLEL_UPDATES = 0

Expand Down Expand Up @@ -42,15 +42,15 @@ def _check_outputs() -> None:
class QbusScene(QbusEntity, Scene):
"""Representation of a Qbus scene entity."""

def __init__(
self, coordinator: QbusControllerCoordinator, mqtt_output: QbusMqttOutput
) -> None:
def __init__(self, mqtt_output: QbusMqttOutput) -> None:
"""Initialize scene entity."""

super().__init__(coordinator, mqtt_output)
super().__init__(mqtt_output)

# Add to main controller device
self._attr_device_info = coordinator.device_info
self._attr_device_info = DeviceInfo(
identifiers={create_main_device_identifier(mqtt_output)}
)
self._attr_name = mqtt_output.name.title()

async def async_activate(self, **kwargs: Any) -> None:
Expand All @@ -61,15 +61,5 @@ async def async_activate(self, **kwargs: Any) -> None:
await self._async_publish_output_state(state)

async def _handle_state_received(self, state: QbusMqttState) -> None:
# We want users to be able to act on a scene activated with physical buttons
# of Qbus. This lets users add entities from other integrations to a Qbus
# scene (e.g. Hue, Sonos, etc).
#
# To accomplish this, users can use the state of a scene as a trigger in
# their automations.
#
# The only way to update the state of a scene entity, is by setting the
# private `__last_activated` variable of the parent `Scene` class.
#
# pylint: disable-next=attribute-defined-outside-init
self._Scene__last_activated = dt_util.utcnow().isoformat()
# Nothing to do
pass
9 changes: 4 additions & 5 deletions homeassistant/components/qbus/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddConfigEntryEntitiesCallback

from .coordinator import QbusConfigEntry, QbusControllerCoordinator
from .coordinator import QbusConfigEntry
from .entity import QbusEntity, add_new_outputs

PARALLEL_UPDATES = 0
Expand Down Expand Up @@ -43,14 +43,13 @@ class QbusSwitch(QbusEntity, SwitchEntity):

_state_cls = QbusMqttOnOffState

_attr_name = None
_attr_device_class = SwitchDeviceClass.SWITCH

def __init__(
self, coordinator: QbusControllerCoordinator, mqtt_output: QbusMqttOutput
) -> None:
def __init__(self, mqtt_output: QbusMqttOutput) -> None:
"""Initialize switch entity."""

super().__init__(coordinator, mqtt_output)
super().__init__(mqtt_output)

self._attr_is_on = False

Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0