Skip to content

Commit

Permalink
Refactor Delonghi Primadonna component to support
Browse files Browse the repository at this point in the history
new beverage entity feature

Signed-off-by: Serge Arbuzov <info@whitediver.com>
  • Loading branch information
Arbuzov committed Nov 16, 2023
1 parent 47483a2 commit 8604e58
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 6 deletions.
7 changes: 6 additions & 1 deletion custom_components/delonghi_primadonna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from homeassistant.core import HomeAssistant, ServiceCall

from .const import BEVERAGE_SERVICE_NAME, DOMAIN
from .device import AvailableBeverage, DelongiPrimadonna
from .device import AvailableBeverage, BeverageEntityFeature, DelongiPrimadonna

PLATFORMS: list[str] = [
Platform.BUTTON,
Expand All @@ -21,6 +21,11 @@
Platform.DEVICE_TRACKER,
]

__all__ = [
'async_setup_entry',
'async_unload_entry',
'BeverageEntityFeature'
]

_LOGGER = logging.getLogger(__name__)

Expand Down
9 changes: 9 additions & 0 deletions custom_components/delonghi_primadonna/device.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Delongi primadonna device description"""
import asyncio
from enum import IntFlag
import logging
import uuid
from binascii import hexlify
Expand Down Expand Up @@ -27,6 +28,14 @@
_LOGGER = logging.getLogger(__name__)


class BeverageEntityFeature(IntFlag):
"""Supported features of the beverage entity"""

MAKE_BEVERAGE = 1
SET_TEMPERATURE = 2
SET_INTENCE = 4


class AvailableBeverage(StrEnum):
"""Coffee machine available beverages"""

Expand Down
9 changes: 7 additions & 2 deletions custom_components/delonghi_primadonna/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import AVAILABLE_PROFILES, DOMAIN, POWER_OFF_OPTIONS
from .device import AvailableBeverage, DelonghiDeviceEntity, DelongiPrimadonna
from .device import (AvailableBeverage,
BeverageEntityFeature,
DelonghiDeviceEntity,
DelongiPrimadonna)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -57,8 +60,9 @@ class BeverageSelect(DelonghiDeviceEntity, SelectEntity):

_attr_options = [*AvailableBeverage]
_attr_current_option = [*AvailableBeverage][0]
_attr_translation_key = 'beverage'
_attr_translation_key = 'make_beverage'
_attr_icon = 'mdi:coffee'
_attr_supported_features: BeverageEntityFeature = BeverageEntityFeature(0)

async def async_select_option(self, option: str) -> None:
"""Select beverage action"""
Expand Down Expand Up @@ -116,6 +120,7 @@ class WaterTemperatureSelect(DelonghiDeviceEntity, SelectEntity):
_attr_current_option = 'Low'
_attr_translation_key = 'water_temperature'
_attr_icon = 'mdi:thermometer'
_attr_supported_features: BeverageEntityFeature = BeverageEntityFeature(1)

@property
def entity_category(self, **kwargs: Any) -> None:
Expand Down
7 changes: 6 additions & 1 deletion custom_components/delonghi_primadonna/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ make_beverage:
description: Prepares beverages from the list of available beverages
target:
entity:
domain: select
domain: delonghi_primadonna
supported_features:
- delonghi_primadonna.BeverageEntityFeature. MAKE_BEVERAGE = 1


fields:
beverage:
name: Beverage
Expand All @@ -12,6 +16,7 @@ make_beverage:
default: "none"
selector:
select:
translation_key: "fan_speed"
options:
- "none"
- "steam"
Expand Down
2 changes: 1 addition & 1 deletion custom_components/delonghi_primadonna/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"profile": {
"name": "Profile"
},
"beverage": {
"make_beverage": {
"name": "Beverage"
},
"energy_save_mode": {
Expand Down
2 changes: 1 addition & 1 deletion custom_components/delonghi_primadonna/translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"profile": {
"name": "Профиль"
},
"beverage": {
"make_beverage": {
"name": "Напиток"
},
"energy_save_mode": {
Expand Down

0 comments on commit 8604e58

Please sign in to comment.