diff --git a/custom_components/deebot/__init__.py b/custom_components/deebot/__init__.py index f5eb4d2..bb12946 100644 --- a/custom_components/deebot/__init__.py +++ b/custom_components/deebot/__init__.py @@ -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 @@ -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}) @@ -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 diff --git a/custom_components/deebot/config_flow.py b/custom_components/deebot/config_flow.py index 09d8e2f..385714b 100644 --- a/custom_components/deebot/config_flow.py +++ b/custom_components/deebot/config_flow.py @@ -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 ( @@ -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( @@ -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] diff --git a/custom_components/deebot/controller.py b/custom_components/deebot/controller.py index cde23d1..7330b86 100644 --- a/custom_components/deebot/controller.py +++ b/custom_components/deebot/controller.py @@ -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, @@ -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__) @@ -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( @@ -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: @@ -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, [] ): diff --git a/custom_components/deebot/image.py b/custom_components/deebot/image.py index 1236a50..5ef504b 100644 --- a/custom_components/deebot/image.py +++ b/custom_components/deebot/image.py @@ -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. diff --git a/custom_components/deebot/manifest.json b/custom_components/deebot/manifest.json index 63e9097..f0b3803 100644 --- a/custom_components/deebot/manifest.json +++ b/custom_components/deebot/manifest.json @@ -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" diff --git a/custom_components/deebot/translations/en.json b/custom_components/deebot/translations/en.json index 3ba3c6e..2616a91 100644 --- a/custom_components/deebot/translations/en.json +++ b/custom_components/deebot/translations/en.json @@ -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": { diff --git a/requirements.txt b/requirements.txt index 99acde9..7eb3e6a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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 diff --git a/translations.schema.json b/translations.schema.json index 30f0674..91c7ead 100644 --- a/translations.schema.json +++ b/translations.schema.json @@ -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": {