forked from mac-zhou/midea-ac-py
-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add self/active clean support (#180)
* Add binary sensor for self clean * Add button entity to start self clean * Add icon for self clean * Update README
- Loading branch information
Showing
6 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
"""Button platform for Midea Smart AC.""" | ||
from __future__ import annotations | ||
|
||
import logging | ||
from typing import Optional | ||
|
||
from homeassistant.components.button import ButtonEntity | ||
from homeassistant.config_entries import ConfigEntry | ||
from homeassistant.core import HomeAssistant | ||
from homeassistant.helpers.entity import EntityCategory | ||
from homeassistant.helpers.entity_platform import AddEntitiesCallback | ||
|
||
from .const import DOMAIN | ||
from .coordinator import MideaCoordinatorEntity, MideaDeviceUpdateCoordinator | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
|
||
async def async_setup_entry( | ||
hass: HomeAssistant, | ||
config_entry: ConfigEntry, | ||
add_entities: AddEntitiesCallback, | ||
) -> None: | ||
"""Setup the button platform for Midea Smart AC.""" | ||
|
||
_LOGGER.info("Setting up button platform.") | ||
|
||
# Fetch coordinator from global data | ||
coordinator = hass.data[DOMAIN][config_entry.entry_id] | ||
|
||
# Create entities for supported features | ||
entities = [] | ||
if getattr(coordinator.device, "supports_self_clean", False): | ||
entities.append(MideaButton(coordinator, | ||
"start_self_clean", | ||
"self_clean", | ||
entity_category=EntityCategory.DIAGNOSTIC, | ||
)) | ||
add_entities(entities) | ||
|
||
|
||
class MideaButton(MideaCoordinatorEntity, ButtonEntity): | ||
"""Button for Midea AC.""" | ||
|
||
def __init__(self, | ||
coordinator: MideaDeviceUpdateCoordinator, | ||
method: str, | ||
translation_key: Optional[str] = None, | ||
*, | ||
entity_category: EntityCategory = None) -> None: | ||
MideaCoordinatorEntity.__init__(self, coordinator) | ||
|
||
self._method = method | ||
self._entity_category = entity_category | ||
self._attr_translation_key = translation_key | ||
|
||
@property | ||
def device_info(self) -> dict: | ||
"""Return info for device registry.""" | ||
return { | ||
"identifiers": { | ||
(DOMAIN, self._device.id) | ||
}, | ||
} | ||
|
||
@property | ||
def has_entity_name(self) -> bool: | ||
"""Indicates if entity follows naming conventions.""" | ||
return True | ||
|
||
@property | ||
def unique_id(self) -> str: | ||
"""Return the unique ID of this entity.""" | ||
return f"{self._device.id}-{self._method}" | ||
|
||
@property | ||
def entity_category(self) -> str: | ||
"""Return the entity category of this entity.""" | ||
return self._entity_category | ||
|
||
async def async_press(self) -> None: | ||
"""Handle the button press.""" | ||
# Call the buttons method | ||
if method := getattr(self._device, self._method, None): | ||
await method() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters