Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
Time to migrate (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
edenhaus authored Feb 1, 2024
1 parent c14dd50 commit 66bbf75
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 24 deletions.
25 changes: 25 additions & 0 deletions custom_components/deebot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
from homeassistant.const import CONF_DEVICES, CONF_USERNAME, CONF_VERIFY_SSL, Platform
from homeassistant.const import __version__ as HA_VERSION
from homeassistant.core import HomeAssistant
from homeassistant.helpers.issue_registry import (
IssueSeverity,
async_create_issue,
async_delete_issue,
)

from custom_components.deebot.controller import DeebotController

Expand Down Expand Up @@ -60,6 +65,21 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
if INTEGRATION_VERSION == "main":
_LOGGER.warning("Beta-Version! Use this version only for testing.")

if AwesomeVersion(HA_VERSION) >= "2024.2.0b0":
async_create_issue(
hass,
DOMAIN,
"deprecated_integration_issue",
is_fixable=False,
issue_domain=DOMAIN,
severity=IssueSeverity.WARNING,
translation_key="deprecated_integration_issue",
translation_placeholders={
"config_url": "/config/integrations/dashboard/add?domain=ecovacs",
"docs_url": "https://www.home-assistant.io/integrations/ecovacs/",
},
)

# Store an instance of the "connecting" class that does the work of speaking
# with your actual devices.
controller = DeebotController(hass, {**entry.data, **entry.options})
Expand Down Expand Up @@ -91,6 +111,11 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
hass.data[DOMAIN].pop(entry.entry_id)
if len(hass.data[DOMAIN]) == 0:
hass.data.pop(DOMAIN)
async_delete_issue(
hass,
DOMAIN,
"deprecated_integration_issue",
)

return unload_ok

Expand Down
13 changes: 6 additions & 7 deletions custom_components/deebot/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import voluptuous as vol
from aiohttp import ClientError
from deebot_client.api_client import ApiClient
from deebot_client.authentication import Authenticator
from deebot_client.authentication import Authenticator, create_rest_config
from deebot_client.exceptions import InvalidAuthenticationError
from deebot_client.models import Configuration, DeviceInfo
from deebot_client.models import DeviceInfo
from deebot_client.util import md5
from homeassistant.config_entries import ConfigEntry, ConfigFlow, OptionsFlow
from homeassistant.const import (
Expand Down Expand Up @@ -244,12 +244,10 @@ async def _retrieve_devices(
hass: HomeAssistant, domain_config: dict[str, Any]
) -> list[DeviceInfo]:
verify_ssl = domain_config.get(CONF_VERIFY_SSL, True)
deebot_config = Configuration(
deebot_config = create_rest_config(
aiohttp_client.async_get_clientsession(hass, verify_ssl=verify_ssl),
device_id=DEEBOT_API_DEVICEID,
continent=domain_config[CONF_CONTINENT],
country=domain_config[CONF_COUNTRY],
verify_ssl=verify_ssl,
country=domain_config[CONF_COUNTRY].upper(),
)

authenticator = Authenticator(
Expand All @@ -259,7 +257,8 @@ async def _retrieve_devices(
)
api_client = ApiClient(authenticator)

return await api_client.get_devices()
devices = await api_client.get_devices()
return [device for device in devices if isinstance(device, DeviceInfo)]


class DeebotOptionsFlowHandler(OptionsFlow): # type: ignore[misc]
Expand Down
27 changes: 18 additions & 9 deletions custom_components/deebot/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
from typing import Any

from deebot_client.api_client import ApiClient
from deebot_client.authentication import Authenticator
from deebot_client.authentication import Authenticator, create_rest_config
from deebot_client.const import UNDEFINED
from deebot_client.device import Device
from deebot_client.exceptions import InvalidAuthenticationError
from deebot_client.models import ApiDeviceInfo, Configuration
from deebot_client.mqtt_client import MqttClient, MqttConfiguration
from deebot_client.models import ApiDeviceInfo, DeviceInfo
from deebot_client.mqtt_client import MqttClient, create_mqtt_config
from deebot_client.util import md5
from homeassistant.const import (
CONF_DEVICES,
Expand All @@ -24,10 +25,11 @@
from homeassistant.helpers.device_registry import DeviceEntry
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.util.ssl import get_default_no_verify_context

from custom_components.deebot.entity import DeebotEntity, DeebotEntityDescription

from .const import CONF_CLIENT_DEVICE_ID, CONF_CONTINENT, CONF_COUNTRY
from .const import CONF_CLIENT_DEVICE_ID, CONF_COUNTRY

_LOGGER = logging.getLogger(__name__)

Expand All @@ -52,12 +54,11 @@ def __init__(self, hass: HomeAssistant, config: Mapping[str, Any]):
random.choice(string.ascii_uppercase + string.digits) for _ in range(12)
)

deebot_config = Configuration(
country = config.get(CONF_COUNTRY, "it").upper()
deebot_config = create_rest_config(
aiohttp_client.async_get_clientsession(self._hass, verify_ssl=verify_ssl),
device_id=device_id,
country=config.get(CONF_COUNTRY, "it").lower(),
continent=config.get(CONF_CONTINENT, "eu").lower(),
verify_ssl=config.get(CONF_VERIFY_SSL, True),
country=country,
)

self._authenticator = Authenticator(
Expand All @@ -67,7 +68,11 @@ def __init__(self, hass: HomeAssistant, config: Mapping[str, Any]):
)
self._api_client = ApiClient(self._authenticator)

mqtt_config = MqttConfiguration(config=deebot_config)
mqtt_config = create_mqtt_config(
device_id=device_id,
country=country,
ssl_context=UNDEFINED if verify_ssl else get_default_no_verify_context(),
)
self._mqtt: MqttClient = MqttClient(mqtt_config, self._authenticator)

async def initialize(self) -> None:
Expand All @@ -80,6 +85,10 @@ async def initialize(self) -> None:
await self._mqtt.connect()

for device in devices:
if not isinstance(device, DeviceInfo):
# Legacy devices are not supported
continue

if device.api_device_info["name"] in self._hass_config.get(
CONF_DEVICES, []
):
Expand Down
6 changes: 0 additions & 6 deletions custom_components/deebot/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ async def on_changed(event: MapChangedEvent) -> None:
self._subscribe(self._capability.chached_info.event, on_info)
self._subscribe(self._capability.changed.event, on_changed)

def on_remove() -> None:
self._device.map.disable()

self.async_on_remove(on_remove)
self._device.map.enable()

async def async_update(self) -> None:
"""Update the entity.
Expand Down
2 changes: 1 addition & 1 deletion custom_components/deebot/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"deebot_client"
],
"requirements": [
"deebot-client==4.1.0",
"deebot-client==5.0.0",
"numpy>=1.23.2"
],
"version": "v0.0.0"
Expand Down
4 changes: 4 additions & 0 deletions custom_components/deebot/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@
}
},
"issues": {
"deprecated_integration_issue": {
"description": "I migrated the custom component `Deebot 4 Home Assistant` to the core and merged it with the existing `Ecovacs` integration.\n\nThe custom component is no longer needed and will be archived in the future.\n\nEverything was migrated except:\n- The events `cleaning_job` and `custom_command`.\n- The last cleaning and stats type sensors\n- Deprecated services\n\nMigration steps:\n1: Remove all `Deebot 4 Home Assistant` config entries\n2: Uninstall `Deebot 4 Home Assistant` via HACS\n3: Setup the [Ecovacs integration]({docs_url}) by clicking [here]({config_url})",
"title": "Time to migrate!"
},
"deprecated_service_refresh": {
"fix_flow": {
"step": {
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# if code from specific branch is needed
#git+https://github.com/DeebotUniverse/client.py@dev#deebot-client==4.2.0dev0
deebot-client==4.1.0
deebot-client==5.0.0

homeassistant>=2024.1.0b0
mypy==1.8.0
Expand Down
12 changes: 12 additions & 0 deletions translations.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,18 @@
"issues": {
"additionalProperties": false,
"properties": {
"deprecated_integration_issue": {
"additionalProperties": false,
"properties": {
"description": {
"type": "string"
},
"title": {
"type": "string"
}
},
"type": "object"
},
"deprecated_service_refresh": {
"additionalProperties": false,
"properties": {
Expand Down

0 comments on commit 66bbf75

Please sign in to comment.