From ff2321ece9790abff7256cb0a26528f42c763575 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sat, 19 Dec 2020 14:06:48 +0100 Subject: [PATCH] simplify _split_service_data --- custom_components/adaptive_lighting/switch.py | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 3c373782..921a228a 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -184,25 +184,19 @@ def is_our_context(context: Optional[Context]) -> bool: return context.id.startswith(_DOMAIN_SHORT) -def _copy_and_pop(dct, keys): - """Copy a dictionary and remove 'keys' if they exist.""" - copy = dct.copy() - for key in keys: - copy.pop(key, None) - return copy - - def _split_service_data(service_data, adapt_brightness, adapt_color): """Split service_data into two dictionaries (for color and brightness).""" service_datas = [] if adapt_color: - service_datas.append( - _copy_and_pop(service_data, (ATTR_WHITE_VALUE, ATTR_BRIGHTNESS)) - ) + service_data_color = service_data.copy() + service_data_color.pop(ATTR_WHITE_VALUE, None) + service_data_color.pop(ATTR_BRIGHTNESS, None) + service_datas.append(service_data_color) if adapt_brightness: - service_datas.append( - _copy_and_pop(service_data, (ATTR_RGB_COLOR, ATTR_COLOR_TEMP)) - ) + service_data_brightness = service_data.copy() + service_data_brightness.pop(ATTR_RGB_COLOR, None) + service_data_brightness.pop(ATTR_COLOR_TEMP, None) + service_datas.append(service_data_brightness) return service_datas