22import logging
33from datetime import timedelta
44from enum import StrEnum
5+ from dataclasses import fields
56
67from vacuum_map_parser_base .config .color import ColorsPalette
78from vacuum_map_parser_base .config .drawable import Drawable
8- from vacuum_map_parser_base .config .image_config import ImageConfig
9+ from vacuum_map_parser_base .config .image_config import ImageConfig , TrimConfig
910from vacuum_map_parser_base .config .size import Sizes
1011from vacuum_map_parser_base .config .text import Text
1112
2728from .vacuum_platforms .vacuum_viomi import ViomiCloudVacuum
2829from .vacuum_platforms .vacuum_ijai import IjaiCloudVacuum
2930from .vacuum_platforms .vacuum_unsupported import UnsupportedCloudVacuum
31+ from .initializer import from_dict
3032from .const import *
3133
3234
122124 })
123125
124126
127+
125128async def async_setup_platform (hass , config , async_add_entities , discovery_info = None ):
126129 await async_setup_reload_service (hass , DOMAIN , PLATFORMS )
127-
130+ _LOGGER . debug ( f"config= { config } " )
128131 host = config [CONF_HOST ]
129132 token = config [CONF_TOKEN ]
130133 username = config [CONF_USERNAME ]
131134 password = config [CONF_PASSWORD ]
132135 country = config [CONF_COUNTRY ]
133136 name = config [CONF_NAME ]
134137 should_poll = config [CONF_AUTO_UPDATE ]
135- image_config = config [CONF_MAP_TRANSFORM ]
138+ image_config = from_dict ( ImageConfig , config [CONF_MAP_TRANSFORM ])
136139 colors = config [CONF_COLORS ]
137140 room_colors = config [CONF_ROOM_COLORS ]
138141 for room , color in room_colors .items ():
139142 colors [f"{ COLOR_ROOM_PREFIX } { room } " ] = color
140143 drawables = config [CONF_DRAW ]
141- sizes = config [CONF_SIZES ]
142- texts = config [CONF_TEXTS ]
144+ sizes = Sizes (config [CONF_SIZES ])
145+ texts = from_dict (list , config [CONF_TEXTS ])
146+
143147 if DRAWABLE_ALL in drawables :
144148 drawables = CONF_AVAILABLE_DRAWABLES [1 :]
145149 attributes = config [CONF_ATTRIBUTES ]
@@ -149,7 +153,7 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
149153 force_api = config [CONF_FORCE_API ]
150154 entity_id = generate_entity_id (ENTITY_ID_FORMAT , name , hass = hass )
151155 async_add_entities ([VacuumCamera (entity_id , host , token , username , password , country , name , should_poll ,
152- image_config , colors , drawables , sizes , texts , attributes , store_map_raw ,
156+ image_config , ColorsPalette ( colors , room_colors ) , drawables , sizes , texts , attributes , store_map_raw ,
153157 store_map_image , store_map_path , force_api )])
154158
155159
@@ -230,6 +234,7 @@ def should_poll(self) -> bool:
230234
231235 @staticmethod
232236 def extract_attributes (map_data : MapData , attributes_to_return : list [str ], country ) -> dict [str , any ]:
237+ _LOGGER .debug (f"extract_attributes{ map_data } , { attributes_to_return } , country" )
233238 attributes = {}
234239 rooms = []
235240 if map_data .rooms is not None :
@@ -299,7 +304,7 @@ def _login(self):
299304
300305 def _initialize_device (self ):
301306 _LOGGER .debug ("Retrieving device info, country: %s" , self ._country )
302- country , user_id , device_id , model , mac = self ._connector .get_device_details (self ._vacuum . token , self ._country )
307+ country , user_id , device_id , model , mac = self ._connector .get_device_details (self ._token , self ._country )
303308 if model is not None :
304309 self ._country = country
305310 _LOGGER .debug ("Retrieved device model: %s" , model )
@@ -345,26 +350,29 @@ def _create_device(self, user_id: str, device_id: str, model: str, mac: str) ->
345350 self ._used_api = self ._detect_api (model )
346351 store_map_path = self ._store_map_path if self ._store_map_raw else None
347352 vacuum_config = VacuumConfig (
348- self ._connector ,
349- self ._country ,
350- user_id ,
351- device_id ,
352- self ._host ,
353- self ._token ,
354- model ,
355- self ._colors ,
356- self ._drawables ,
357- self ._image_config ,
358- self ._sizes ,
359- self ._texts ,
360- store_map_path
353+ connector = self ._connector ,
354+ country = self ._country ,
355+ user_id = user_id ,
356+ device_id = device_id ,
357+ host = self ._host ,
358+ token = self ._token ,
359+ model = model ,
360+ _mac = mac ,
361+ palette = self ._colors ,
362+ drawables = self ._drawables ,
363+ image_config = self ._image_config ,
364+ sizes = self ._sizes ,
365+ texts = self ._texts ,
366+ store_map_path = store_map_path
361367 )
362368 if self ._used_api == CONF_AVAILABLE_API_XIAOMI :
363369 return RoborockCloudVacuum (vacuum_config )
364370 if self ._used_api == CONF_AVAILABLE_API_VIOMI :
365371 return ViomiCloudVacuum (vacuum_config )
366372 if self ._used_api == CONF_AVAILABLE_API_IJAI :
367- return IjaiCloudVacuum (self ._connector , self ._country , user_id , device_id , model , mac )
373+ _LOGGER .debug (f"palette={ vacuum_config .palette } " )
374+ _LOGGER .debug (f"image_config={ vacuum_config .image_config } " )
375+ return IjaiCloudVacuum (vacuum_config )
368376 if self ._used_api == CONF_AVAILABLE_API_ROIDMI :
369377 return RoidmiCloudVacuum (vacuum_config )
370378 if self ._used_api == CONF_AVAILABLE_API_DREAME :
0 commit comments