Skip to content

Commit

Permalink
Merge pull request #91 from Arbuzov/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
Arbuzov committed Nov 18, 2023
2 parents 9305563 + f8f0e71 commit 20254be
Show file tree
Hide file tree
Showing 13 changed files with 420 additions and 83 deletions.
10 changes: 6 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
{
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.analysis.include":[
"python.analysis.include": [
"../core/homeassistant"
],
"python.analysis.extraPaths": [
"../core/homeassistant"
]
],
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
}
}
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
[![hacs_badge](https://img.shields.io/badge/HACS-Custom-41BDF5.svg?style=for-the-badge)](https://github.com/hacs/integration)
[![License](https://img.shields.io/github/license/Arbuzov/home_assistant_delonghi_primadonna?style=for-the-badge)](https://github.com/Arbuzov/home_assistant_delonghi_primadonna/blob/master/LICENSE)
[![Latest Release](https://img.shields.io/github/v/release/Arbuzov/home_assistant_delonghi_primadonna?style=for-the-badge)](https://github.com/Arbuzov/home_assistant_delonghi_primadonna/releases)


[![Open your Home Assistant instance and open a repository inside the Home Assistant Community Store.](https://my.home-assistant.io/badges/hacs_repository.svg)](https://my.home-assistant.io/redirect/hacs_repository/?owner=Arbuzov&repository=home_assistant_delonghi_primadonna&category=integration)


[![Open your Home Assistant instance and start setting up a new integration.](https://my.home-assistant.io/badges/config_flow_start.svg)](https://my.home-assistant.io/redirect/config_flow_start/?domain=home_assistant_delonghi_primadonna)

![Company logo](https://brands.home-assistant.io/delonghi_primadonna/logo.png)
Expand Down Expand Up @@ -62,5 +66,4 @@ Copy all files from this repository in custom_components/delonghi_primadonna to
* De'Longhi ECAM 650.85.MS
* De'Longhi ECAM 550.55.W
* De'Longhi ECAM 650.55.MS EX:1
* De'Longhi Eletta Explore 450.65.G
* Please add...
* Feel free to add your model...
29 changes: 26 additions & 3 deletions custom_components/delonghi_primadonna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

import logging

import voluptuous as vol
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.core import HomeAssistant, ServiceCall

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

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

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

_LOGGER = logging.getLogger(__name__)

Expand All @@ -30,7 +36,24 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data[DOMAIN] = {}
delonghi_device = DelongiPrimadonna(entry.data, hass)
hass.data[DOMAIN][entry.unique_id] = delonghi_device
_LOGGER.warning('Device id %s', entry.unique_id)
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

async def make_beverage(call: ServiceCall) -> None:
_LOGGER.warning('Make beverage %s', call.data)
await delonghi_device.beverage_start(call.data['beverage'])

hass.services.async_register(
DOMAIN,
BEVERAGE_SERVICE_NAME,
make_beverage,
schema=vol.Schema({
vol.Required('beverage'): vol.In([*AvailableBeverage]),
vol.Optional('entity_id'): vol.Coerce(str),
vol.Optional('device_id'): vol.Coerce(str),
})
)

return True


Expand Down
2 changes: 1 addition & 1 deletion custom_components/delonghi_primadonna/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async def async_setup_entry(
class DelongiPrimadonnaPowerButton(DelonghiDeviceEntity, ButtonEntity):
"""This button turns on the device"""

_attr_name = 'Turn on ECAM'
_attr_translation_key = 'power_on'

async def async_press(self):
self.hass.async_create_task(self.device.power_on())
33 changes: 29 additions & 4 deletions custom_components/delonghi_primadonna/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@

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

BEVERAGE_SERVICE_NAME = 'make_beverage'

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

POWER_OFF_OPTIONS = {
'15min': 0,
'30min': 1,
'1h': 2,
'2h': 3,
'3h': 4
}

ENTITY_CATEGORY = {
'None': None,
'Configuration': EntityCategory.CONFIG,
Expand All @@ -29,14 +39,29 @@
"""
BYTES_POWER = [0x0d, 0x07, 0x84, 0x0f, 0x02, 0x01, 0x55, 0x12]

# This command change device state
BYTES_GENERAL_COMMAND = [
# Default bitmask for commands
BASE_COMMAND = '10000001'

# This command change device switches
BYTES_SWITCH_COMMAND = [
0x0d, 0x0b, 0x90, 0x0f, 0x00, 0x3f,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]

# Default bitmask for commands
BASE_COMMAND = '10000001'
BYTES_AUTOPOWEROFF_COMMAND = [
0x0d, 0x0b, 0x90, 0x0f, 0x00, 0x3e,
0x00, 0x00, 0x00, 0x00, 0x81, 0xe3
]

BYTES_WATER_HARDNESS_COMMAND = [
0x0d, 0x0b, 0x90, 0x0f, 0x00, 0x32,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
]

BYTES_WATER_TEMPERATURE_COMMAND = [
0x0d, 0x0b, 0x90, 0x0f, 0x00, 0x3d,
0x00, 0x00, 0x00, 0x00, 0x6f, 0x31
]

COFFE_ON = [0x0d, 0x0f, 0x83, 0xf0, 0x02, 0x01, 0x01,
0x00, 0x67, 0x02, 0x02, 0x00, 0x00, 0x06, 0x77, 0xff]
Expand Down
56 changes: 41 additions & 15 deletions custom_components/delonghi_primadonna/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import logging
import uuid
from binascii import hexlify
from enum import IntFlag

from bleak import BleakClient
from bleak.exc import BleakDBusError, BleakError
Expand All @@ -13,7 +14,9 @@
from homeassistant.helpers import device_registry as dr

from .const import (AMERICANO_OFF, AMERICANO_ON, BASE_COMMAND,
BYTES_GENERAL_COMMAND, BYTES_POWER, COFFE_OFF, COFFE_ON,
BYTES_AUTOPOWEROFF_COMMAND, BYTES_POWER,
BYTES_SWITCH_COMMAND, BYTES_WATER_HARDNESS_COMMAND,
BYTES_WATER_TEMPERATURE_COMMAND, COFFE_OFF, COFFE_ON,
COFFEE_GROUNDS_CONTAINER_DETACHED,
COFFEE_GROUNDS_CONTAINER_FULL, CONTROLL_CHARACTERISTIC,
DEBUG, DEVICE_READY, DEVICE_TURNOFF, DOMAIN, DOPPIO_OFF,
Expand All @@ -25,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 Expand Up @@ -94,6 +105,7 @@ def __init__(self):


BEVERAGE_COMMANDS = {
AvailableBeverage.NONE: BeverageCommand(DEBUG, DEBUG),
AvailableBeverage.STEAM: BeverageCommand(STEAM_ON, STEAM_OFF),
AvailableBeverage.LONG: BeverageCommand(LONG_ON, LONG_OFF),
AvailableBeverage.COFFEE: BeverageCommand(COFFE_ON, COFFE_OFF),
Expand Down Expand Up @@ -222,19 +234,15 @@ async def _connect(self):
raise error
self._connecting = False

def _make_command(self):
def _make_switch_command(self):
"""Make hex command"""
base_command = list(BASE_COMMAND)
base_command[3] = '1' if self.switches.energy_save else '0'
base_command[4] = '1' if self.switches.cup_light else '0'
base_command[5] = '1' if self.switches.sounds else '0'
if self.notify:
_LOGGER.warning('Command bin: %s', ''.join(base_command))
bytes_general_command = BYTES_GENERAL_COMMAND
bytes_general_command[9] = int(''.join(base_command), 2)
if self.notify:
_LOGGER.warning('Command bytes: %s', bytes_general_command)
return bytes_general_command
hex_command = BYTES_SWITCH_COMMAND
hex_command[9] = int(''.join(base_command), 2)
return hex_command

async def _event_trigger(self, value):
"""
Expand Down Expand Up @@ -296,32 +304,32 @@ async def power_on(self) -> None:
async def cup_light_on(self) -> None:
"""Turn the cup light on."""
self.switches.cup_light = True
await self.send_command(self._make_command())
await self.send_command(self._make_switch_command())

async def cup_light_off(self) -> None:
"""Turn the cup light off."""
self.switches.cup_light = False
await self.send_command(self._make_command())
await self.send_command(self._make_switch_command())

async def energy_save_on(self):
"""Enable energy save mode"""
self.switches.energy_save = True
await self.send_command(self._make_command())
await self.send_command(self._make_switch_command())

async def energy_save_off(self):
"""Enable energy save mode"""
self.switches.energy_save = False
await self.send_command(self._make_command())
await self.send_command(self._make_switch_command())

async def sound_alarm_on(self):
"""Enable sound alarm"""
self.switches.sounds = True
await self.send_command(self._make_command())
await self.send_command(self._make_switch_command())

async def sound_alarm_off(self):
"""Disable sound alarm"""
self.switches.sounds = False
await self.send_command(self._make_command())
await self.send_command(self._make_switch_command())

async def beverage_start(self, beverage: AvailableBeverage) -> None:
"""Start beverage"""
Expand Down Expand Up @@ -368,6 +376,24 @@ async def select_profile(self, profile_id) -> None:
message = [0x0D, 0x06, 0xA9, 0xF0, profile_id, 0xD7, 0xC0]
await self.send_command(message)

async def set_auto_power_off(self, power_off_interval) -> None:
"""Set auto power off time."""
message = BYTES_AUTOPOWEROFF_COMMAND
message[9] = power_off_interval
await self.send_command(message)

async def set_water_hardness(self, hardness_level) -> None:
"""Set water hardness"""
message = BYTES_WATER_HARDNESS_COMMAND
message[9] = hardness_level
await self.send_command(message)

async def set_water_temperature(self, temperature_level) -> None:
"""Set water temperature"""
message = BYTES_WATER_TEMPERATURE_COMMAND
message[9] = temperature_level
await self.send_command(message)

async def common_command(self, command: str) -> None:
"""Send custom BLE command"""
message = [int(x, 16) for x in command.split(' ')]
Expand Down
2 changes: 1 addition & 1 deletion custom_components/delonghi_primadonna/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
"documentation": "https://github.com/Arbuzov/home_assistant_delonghi_primadonna",
"iot_class": "local_polling",
"issue_tracker": "https://github.com/Arbuzov/home_assistant_delonghi_primadonna/issues",
"version": "1.5.2"
"version": "1.5.3"
}
Loading

0 comments on commit 20254be

Please sign in to comment.