Skip to content

Commit

Permalink
Merge pull request #51 from Arbuzov/pail23_master
Browse files Browse the repository at this point in the history
Pail23 master
  • Loading branch information
Arbuzov committed May 7, 2023
2 parents bd39775 + 4b193f9 commit 5fc8b91
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
hacs:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3.5.0"
- uses: "actions/checkout@v3.5.2"

- uses: "hacs/action@main"
name: HACS validation
Expand All @@ -21,7 +21,7 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.5.0
- uses: actions/checkout@v3.5.2

- uses: actions/setup-python@v4
with:
Expand Down
8 changes: 6 additions & 2 deletions custom_components/delonghi_primadonna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
from .const import DOMAIN
from .device import DelongiPrimadonna

PLATFORMS: list[str] = [Platform.SWITCH, Platform.BUTTON,
Platform.DEVICE_TRACKER, Platform.SENSOR]
PLATFORMS: list[str] = [Platform.BUTTON,
Platform.SENSOR,
Platform.SELECT,
Platform.SWITCH,
Platform.DEVICE_TRACKER]


_LOGGER = logging.getLogger(__name__)

Expand Down
16 changes: 14 additions & 2 deletions custom_components/delonghi_primadonna/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
NAME_CHARACTERISTIC = '00002A00-0000-1000-8000-00805F9B34FB'

DESCRIPTOR = '00002902-0000-1000-8000-00805f9b34fb'

AVAILABLE_PROFILES = {
'Profile 1': 1,
'Profile 2': 2,
'Profile 3': 3,
'Guest': 4
}

"""
Command bytes
"""
Expand Down Expand Up @@ -87,8 +95,12 @@
0x00, 0x9d, 0x61]

DEVICE_TURNOFF = [0xd0, 0x12, 0x75, 0x0f, 0x01, 0x01, 0x00, 0x00,
0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x8f, 0x2f]
0x00, 0x00, 0x03, 0x64, 0x00, 0x00, 0x00, 0x00,
0x00, 0xd6, 0x96]

START_COFFEE = [0xd0, 0x12, 0x75, 0x0f, 0x01, 0x05, 0x00, 0x00,
0x00, 0x07, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x5c, 0xa7]

"""
# noqa: E501
Expand Down
24 changes: 21 additions & 3 deletions custom_components/delonghi_primadonna/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
DEBUG, DEVICE_READY, DEVICE_TURNOFF, DOMAIN, DOPPIO_OFF,
DOPPIO_ON, ESPRESSO2_OFF, ESPRESSO2_ON, ESPRESSO_OFF,
ESPRESSO_ON, HOTWATER_OFF, HOTWATER_ON, LONG_OFF, LONG_ON,
NAME_CHARACTERISTIC, STEAM_OFF, STEAM_ON, WATER_SHORTAGE,
WATER_TANK_DETACHED)
NAME_CHARACTERISTIC, START_COFFEE, STEAM_OFF, STEAM_ON,
WATER_SHORTAGE, WATER_TANK_DETACHED)

_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -99,12 +99,15 @@ def __init__(self, kind, description):
str(bytearray(COFFEE_GROUNDS_CONTAINER_DETACHED)): BeverageNotify(
NotificationType.STATUS, 'NoGroundsContainer'),
str(bytearray(COFFEE_GROUNDS_CONTAINER_FULL)): BeverageNotify(
NotificationType.STATUS, 'GroundsContainerFull')
NotificationType.STATUS, 'GroundsContainerFull'),
str(bytearray(START_COFFEE)): BeverageNotify(
NotificationType.STATUS, 'START_COFFEE')
}


class DelonghiDeviceEntity:
"""Entity class for the Delonghi devices"""
_attr_has_entity_name = True

def __init__(self, delongh_device, hass: HomeAssistant):
"""Init entity with the device"""
Expand Down Expand Up @@ -326,3 +329,18 @@ async def get_device_name(self):
except asyncio.exceptions.CancelledError as error:
self.connected = False
_LOGGER.warning('CancelledError: %s', error)

async def select_profile(self, profile_id) -> None:
"""select a profile."""
await self._connect()
try:
message = [0x0d, 0x06, 0xa9, 0xf0, profile_id, 0xd7, 0xc0]
sign_request(message)
_LOGGER.info('Select Profile: %s',
hexlify(bytearray(message), ' '))
await self._client.write_gatt_char(
CONTROLL_CHARACTERISTIC,
bytearray(message))
except BleakError as error:
self.connected = False
_LOGGER.warning('BleakError: %s', error)
35 changes: 35 additions & 0 deletions custom_components/delonghi_primadonna/select.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import logging

from homeassistant.components.select import SelectEntity
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback

from .const import AVAILABLE_PROFILES, DOMAIN
from .device import DelonghiDeviceEntity, DelongiPrimadonna

_LOGGER = logging.getLogger(__name__)


async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry,
async_add_entities: AddEntitiesCallback):
delongh_device: DelongiPrimadonna = hass.data[DOMAIN][entry.unique_id]
async_add_entities([
ProfileSelect(delongh_device, hass)
])
return True


class ProfileSelect(DelonghiDeviceEntity, SelectEntity):
"""A select implementation for profile selection."""

_attr_name = 'Profile'
_attr_options = list(AVAILABLE_PROFILES.keys())
_attr_current_option = list(AVAILABLE_PROFILES.keys())[0]

async def async_select_option(self, option: str) -> None:
"""Change the selected option."""
profile_id = AVAILABLE_PROFILES.get(option)
self.hass.async_create_task(self.device.select_profile(profile_id))
self._attr_current_option = option

0 comments on commit 5fc8b91

Please sign in to comment.