1 """Convert the HA config to the dynalite config."""
3 from __future__
import annotations
5 from types
import MappingProxyType
8 from dynalite_devices_lib
import const
as dyn_const
46 ACTIVE_INIT: dyn_const.ACTIVE_INIT,
47 False: dyn_const.ACTIVE_OFF,
48 ACTIVE_OFF: dyn_const.ACTIVE_OFF,
49 ACTIVE_ON: dyn_const.ACTIVE_ON,
50 True: dyn_const.ACTIVE_ON,
54 CONF_ROOM: dyn_const.CONF_ROOM,
55 CONF_TIME_COVER: dyn_const.CONF_TIME_COVER,
60 """Create the initial converted map with just the basic key:value pairs updated."""
64 result[conf_map[conf]] = config[conf]
69 """Convert the config for a channel."""
71 CONF_NAME: dyn_const.CONF_NAME,
72 CONF_FADE: dyn_const.CONF_FADE,
73 CONF_TYPE: dyn_const.CONF_CHANNEL_TYPE,
79 """Convert the config for a preset."""
81 CONF_NAME: dyn_const.CONF_NAME,
82 CONF_FADE: dyn_const.CONF_FADE,
83 CONF_LEVEL: dyn_const.CONF_LEVEL,
89 """Convert the config for an area."""
91 CONF_NAME: dyn_const.CONF_NAME,
92 CONF_FADE: dyn_const.CONF_FADE,
93 CONF_NO_DEFAULT: dyn_const.CONF_NO_DEFAULT,
94 CONF_ROOM_ON: dyn_const.CONF_ROOM_ON,
95 CONF_ROOM_OFF: dyn_const.CONF_ROOM_OFF,
96 CONF_CHANNEL_COVER: dyn_const.CONF_CHANNEL_COVER,
97 CONF_DEVICE_CLASS: dyn_const.CONF_DEVICE_CLASS,
98 CONF_OPEN_PRESET: dyn_const.CONF_OPEN_PRESET,
99 CONF_CLOSE_PRESET: dyn_const.CONF_CLOSE_PRESET,
100 CONF_STOP_PRESET: dyn_const.CONF_STOP_PRESET,
101 CONF_DURATION: dyn_const.CONF_DURATION,
102 CONF_TILT_TIME: dyn_const.CONF_TILT_TIME,
105 if CONF_CHANNEL
in config:
106 result[dyn_const.CONF_CHANNEL] = {
108 for (channel, channel_conf)
in config[CONF_CHANNEL].items()
110 if CONF_PRESET
in config:
111 result[dyn_const.CONF_PRESET] = {
113 for (preset, preset_conf)
in config[CONF_PRESET].items()
115 if CONF_TEMPLATE
in config:
116 result[dyn_const.CONF_TEMPLATE] = TEMPLATE_MAP[config[CONF_TEMPLATE]]
121 """Convert the config for the platform defaults."""
126 """Convert the config for a template."""
128 CONF_ROOM_ON: dyn_const.CONF_ROOM_ON,
129 CONF_ROOM_OFF: dyn_const.CONF_ROOM_OFF,
130 CONF_CHANNEL_COVER: dyn_const.CONF_CHANNEL_COVER,
131 CONF_DEVICE_CLASS: dyn_const.CONF_DEVICE_CLASS,
132 CONF_OPEN_PRESET: dyn_const.CONF_OPEN_PRESET,
133 CONF_CLOSE_PRESET: dyn_const.CONF_CLOSE_PRESET,
134 CONF_STOP_PRESET: dyn_const.CONF_STOP_PRESET,
135 CONF_DURATION: dyn_const.CONF_DURATION,
136 CONF_TILT_TIME: dyn_const.CONF_TILT_TIME,
142 config: dict[str, Any] | MappingProxyType[str, Any],
144 """Convert a config dict by replacing component consts with library consts."""
146 CONF_NAME: dyn_const.CONF_NAME,
147 CONF_HOST: dyn_const.CONF_HOST,
148 CONF_PORT: dyn_const.CONF_PORT,
149 CONF_AUTO_DISCOVER: dyn_const.CONF_AUTO_DISCOVER,
150 CONF_POLL_TIMER: dyn_const.CONF_POLL_TIMER,
153 if CONF_AREA
in config:
154 result[dyn_const.CONF_AREA] = {
156 for (area, area_conf)
in config[CONF_AREA].items()
158 if CONF_DEFAULT
in config:
160 if CONF_ACTIVE
in config:
161 result[dyn_const.CONF_ACTIVE] = ACTIVE_MAP[config[CONF_ACTIVE]]
162 if CONF_PRESET
in config:
163 result[dyn_const.CONF_PRESET] = {
165 for (preset, preset_conf)
in config[CONF_PRESET].items()
167 if CONF_TEMPLATE
in config:
168 result[dyn_const.CONF_TEMPLATE] = {
170 for (template, template_conf)
in config[CONF_TEMPLATE].items()
def convert_with_map(config, conf_map)
dict[str, Any] convert_area(dict[str, Any] config)
dict[str, Any] convert_channel(dict[str, Any] config)
dict[str, Any] convert_default(dict[str, Any] config)
dict[str, Any] convert_preset(dict[str, Any] config)
dict[str, Any] convert_config(dict[str, Any]|MappingProxyType[str, Any] config)
dict[str, Any] convert_template(dict[str, Any] config)