Skip to content

Commit

Permalink
[WIP] Adapted main component for ijai models basic support, fixed ini…
Browse files Browse the repository at this point in the history
…tialization of Palette

and ImageConfig objects
  • Loading branch information
Alexander "Tarh authored and Tarh-76 committed May 4, 2024
1 parent b49cf96 commit b32c343
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 951 deletions.
1 change: 0 additions & 1 deletion custom_components/xiaomi_cloud_map_extractor/__init__.py

This file was deleted.

49 changes: 28 additions & 21 deletions custom_components/xiaomi_cloud_map_extractor/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
import logging
from datetime import timedelta
from enum import StrEnum
from dataclasses import fields

from vacuum_map_parser_base.config.color import ColorsPalette
from vacuum_map_parser_base.config.drawable import Drawable
from vacuum_map_parser_base.config.image_config import ImageConfig
from vacuum_map_parser_base.config.image_config import ImageConfig, TrimConfig
from vacuum_map_parser_base.config.size import Sizes
from vacuum_map_parser_base.config.text import Text

Expand All @@ -27,6 +28,7 @@
from .vacuum_platforms.vacuum_viomi import ViomiCloudVacuum
from .vacuum_platforms.vacuum_ijai import IjaiCloudVacuum
from .vacuum_platforms.vacuum_unsupported import UnsupportedCloudVacuum
from .initializer import from_dict
from .const import *


Expand Down Expand Up @@ -122,24 +124,25 @@
})



async def async_setup_platform(hass, config, async_add_entities, discovery_info=None):
await async_setup_reload_service(hass, DOMAIN, PLATFORMS)

_LOGGER.debug(f"config={config}")
host = config[CONF_HOST]
token = config[CONF_TOKEN]
username = config[CONF_USERNAME]
password = config[CONF_PASSWORD]
country = config[CONF_COUNTRY]
name = config[CONF_NAME]
should_poll = config[CONF_AUTO_UPDATE]
image_config = config[CONF_MAP_TRANSFORM]
image_config = from_dict(ImageConfig, config[CONF_MAP_TRANSFORM])
colors = config[CONF_COLORS]
room_colors = config[CONF_ROOM_COLORS]
for room, color in room_colors.items():
colors[f"{COLOR_ROOM_PREFIX}{room}"] = color
drawables = config[CONF_DRAW]
sizes = config[CONF_SIZES]
texts = config[CONF_TEXTS]
sizes = Sizes(config[CONF_SIZES])
texts = from_dict(list, config[CONF_TEXTS])
if DRAWABLE_ALL in drawables:
drawables = CONF_AVAILABLE_DRAWABLES[1:]
attributes = config[CONF_ATTRIBUTES]
Expand All @@ -149,7 +152,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
force_api = config[CONF_FORCE_API]
entity_id = generate_entity_id(ENTITY_ID_FORMAT, name, hass=hass)
async_add_entities([VacuumCamera(entity_id, host, token, username, password, country, name, should_poll,
image_config, colors, drawables, sizes, texts, attributes, store_map_raw,
image_config, ColorsPalette(colors, room_colors), drawables, sizes, texts, attributes, store_map_raw,
store_map_image, store_map_path, force_api)])


Expand Down Expand Up @@ -230,6 +233,7 @@ def should_poll(self) -> bool:

@staticmethod
def extract_attributes(map_data: MapData, attributes_to_return: list[str], country) -> dict[str, any]:
_LOGGER.debug(f"extract_attributes{map_data}, {attributes_to_return}, country")
attributes = {}
rooms = []
if map_data.rooms is not None:
Expand Down Expand Up @@ -299,7 +303,7 @@ def _login(self):

def _initialize_device(self):
_LOGGER.debug("Retrieving device info, country: %s", self._country)
country, user_id, device_id, model, mac = self._connector.get_device_details(self._vacuum.token, self._country)
country, user_id, device_id, model, mac = self._connector.get_device_details(self._token, self._country)
if model is not None:
self._country = country
_LOGGER.debug("Retrieved device model: %s", model)
Expand Down Expand Up @@ -345,26 +349,29 @@ def _create_device(self, user_id: str, device_id: str, model: str, mac: str) ->
self._used_api = self._detect_api(model)
store_map_path = self._store_map_path if self._store_map_raw else None
vacuum_config = VacuumConfig(
self._connector,
self._country,
user_id,
device_id,
self._host,
self._token,
model,
self._colors,
self._drawables,
self._image_config,
self._sizes,
self._texts,
store_map_path
connector = self._connector,
country = self._country,
user_id = user_id,
device_id = device_id,
host = self._host,
token = self._token,
model = model,
_mac = mac,
palette = self._colors,
drawables = self._drawables,
image_config = self._image_config,
sizes = self._sizes,
texts = self._texts,
store_map_path = store_map_path
)
if self._used_api == CONF_AVAILABLE_API_XIAOMI:
return RoborockCloudVacuum(vacuum_config)
if self._used_api == CONF_AVAILABLE_API_VIOMI:
return ViomiCloudVacuum(vacuum_config)
if self._used_api == CONF_AVAILABLE_API_IJAI:
return IjaiCloudVacuum(self._connector, self._country, user_id, device_id, model, mac)
_LOGGER.debug(f"palette={vacuum_config.palette}")
_LOGGER.debug(f"image_config={vacuum_config.image_config}")
return IjaiCloudVacuum(vacuum_config)
if self._used_api == CONF_AVAILABLE_API_ROIDMI:
return RoidmiCloudVacuum(vacuum_config)
if self._used_api == CONF_AVAILABLE_API_DREAME:
Expand Down
72 changes: 0 additions & 72 deletions custom_components/xiaomi_cloud_map_extractor/common/vacuum.py

This file was deleted.

2 changes: 1 addition & 1 deletion custom_components/xiaomi_cloud_map_extractor/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
CONF_Y = "y"

CONF_AVAILABLE_APIS = [CONF_AVAILABLE_API_XIAOMI, CONF_AVAILABLE_API_VIOMI, CONF_AVAILABLE_API_ROIDMI,
CONF_AVAILABLE_API_DREAME]
CONF_AVAILABLE_API_DREAME, CONF_AVAILABLE_API_IJAI]

CONF_AVAILABLE_SIZES = [CONF_SIZE_VACUUM_RADIUS, CONF_SIZE_PATH_WIDTH, CONF_SIZE_IGNORED_OBSTACLE_RADIUS,
CONF_SIZE_IGNORED_OBSTACLE_WITH_PHOTO_RADIUS, CONF_SIZE_MOP_PATH_WIDTH,
Expand Down
Empty file.
62 changes: 0 additions & 62 deletions custom_components/xiaomi_cloud_map_extractor/ijai/aes_decryptor.py

This file was deleted.

95 changes: 0 additions & 95 deletions custom_components/xiaomi_cloud_map_extractor/ijai/image_handler.py

This file was deleted.

Loading

0 comments on commit b32c343

Please sign in to comment.