1 """Utility functions for the ScreenLogic integration."""
5 from screenlogicpy.const.data
import SHARED_VALUES
9 from .const
import DOMAIN
as SL_DOMAIN, SL_UNIT_TO_HA_UNIT, ScreenLogicDataPath
10 from .coordinator
import ScreenlogicDataUpdateCoordinator
12 _LOGGER = logging.getLogger(__name__)
16 """Generate new unique_id for a screenlogic entity from specified parameters."""
17 _LOGGER.debug(
"gen_uid called with %s", args)
19 if args[2]
in SHARED_VALUES:
20 if args[1]
is not None and (isinstance(args[1], int)
or args[1].isdigit()):
21 return f
"{args[0]}_{args[1]}_{args[2]}"
22 return f
"{args[0]}_{args[2]}"
28 """Return equivalent Home Assistant unit of measurement if exists."""
29 if (ha_unit := SL_UNIT_TO_HA_UNIT.get(sl_unit))
is not None:
35 coordinator: ScreenlogicDataUpdateCoordinator,
37 data_path: ScreenLogicDataPath,
39 """Remove excluded entity if it exists."""
40 assert coordinator.config_entry
41 entity_registry = er.async_get(coordinator.hass)
42 unique_id = f
"{coordinator.config_entry.unique_id}_{generate_unique_id(*data_path)}"
43 if entity_id := entity_registry.async_get_entity_id(
44 platform_domain, SL_DOMAIN, unique_id
47 "Removing existing entity '%s' per data inclusion rule", entity_id
49 entity_registry.async_remove(entity_id)
str generate_unique_id(*str|int|None args)
None cleanup_excluded_entity(ScreenlogicDataUpdateCoordinator coordinator, str platform_domain, ScreenLogicDataPath data_path)